From f3623df3404542267696f5eebf722540f2b0098f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Janczak?= Date: Tue, 2 Jun 2026 20:54:33 +0200 Subject: [PATCH] feat: show share modal after creating a new short URL --- .../ShortUrlResource/Pages/ListShortUrls.php | 111 +++++++++++++++++- 1 file changed, 110 insertions(+), 1 deletion(-) diff --git a/src/Filament/Resources/ShortUrlResource/Pages/ListShortUrls.php b/src/Filament/Resources/ShortUrlResource/Pages/ListShortUrls.php index 37f4137..4f59a78 100644 --- a/src/Filament/Resources/ShortUrlResource/Pages/ListShortUrls.php +++ b/src/Filament/Resources/ShortUrlResource/Pages/ListShortUrls.php @@ -4,10 +4,13 @@ namespace Bjanczak\FilamentShortUrl\Filament\Resources\ShortUrlResource\Pages; use Bjanczak\FilamentShortUrl\Filament\Resources\ShortUrlResource; use Bjanczak\FilamentShortUrl\Filament\Resources\ShortUrlResource\Widgets\ShortUrlGlobalOverview; +use Bjanczak\FilamentShortUrl\Models\ShortUrl; use Bjanczak\FilamentShortUrl\Services\ShortUrlService; use Filament\Actions\Action; use Filament\Actions\CreateAction; +use Filament\Forms; use Filament\Resources\Pages\ManageRecords; +use Illuminate\Support\HtmlString; class ListShortUrls extends ManageRecords { @@ -30,12 +33,118 @@ class ListShortUrls extends ManageRecords ->color('primary') ->modalWidth('4xl') ->mutateFormDataUsing(function (array $data): array { - // Auto-generate key if not provided if (empty($data['url_key'])) { $data['url_key'] = app(ShortUrlService::class)->generateKey(); } return $data; + }) + ->after(function (ShortUrl $record): void { + $this->mountAction('shareAfterCreate', [ + 'shortUrl' => $record->getShortUrl(), + 'urlKey' => $record->url_key, + 'destHost' => parse_url($record->destination_url, PHP_URL_HOST) ?? '', + ]); + }), + + // Hidden action — opened programmatically after create + Action::make('shareAfterCreate') + ->label('') + ->hidden() + ->modalHeading('') + ->modalWidth('lg') + ->modalSubmitAction(false) + ->modalCancelAction(false) + ->form(function (array $arguments): array { + $shortUrl = $arguments['shortUrl'] ?? ''; + $destHost = $arguments['destHost'] ?? ''; + $encoded = urlencode($shortUrl); + $eid = 'fsu_'.substr(md5($shortUrl), 0, 8); + + $html = << + +
+

Time to get some clicks 🎉

+

Your link & QR code are ready!

+

Copy and share manually or choose a platform.

+
+ + +
+
+ +
+ {$shortUrl} +
+ + + + +
+
+ + +
+ + + + + + + + + + + + + + + + + + +
+ + +
+ + +
+ + +HTML; + + return [ + Forms\Components\Placeholder::make('share_modal_content') + ->label('') + ->content(new HtmlString($html)), + ]; }), ]; }