From 6046b65d3c363fa9baf75ae5aec4e786daffd932 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sat, 7 Sep 2024 08:13:00 +0300 Subject: [PATCH 1/2] fix event types --- .../EventResource/Pages/ListEvents.php | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/Resources/EventResource/Pages/ListEvents.php b/src/Resources/EventResource/Pages/ListEvents.php index 358a438..329b40f 100644 --- a/src/Resources/EventResource/Pages/ListEvents.php +++ b/src/Resources/EventResource/Pages/ListEvents.php @@ -6,7 +6,7 @@ use Filament\Resources\Pages\ListRecords; use Illuminate\Database\Eloquent\Builder; use Vormkracht10\FilamentMails\Resources\EventResource; -use Vormkracht10\Mails\Enums\WebhookEventType; +use Vormkracht10\Mails\Enums\EventType; use Vormkracht10\Mails\Models\MailEvent; class ListEvents extends ListRecords @@ -34,32 +34,38 @@ public function getTabs(): array 'delivery' => Tab::make() ->label(__('Delivery')) ->icon('heroicon-o-check-circle') - ->badge(MailEvent::where('type', WebhookEventType::DELIVERY)->count()) - ->modifyQueryUsing(fn (Builder $query) => $query->where('type', WebhookEventType::DELIVERY)), + ->badge(MailEvent::where('type', EventType::DELIVERED)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('type', EventType::DELIVERED)), 'click' => Tab::make() ->label(__('Click')) ->icon('heroicon-o-cursor-arrow-rays') - ->badge(MailEvent::where('type', WebhookEventType::CLICK)->count()) - ->modifyQueryUsing(fn (Builder $query) => $query->where('type', WebhookEventType::CLICK)), + ->badge(MailEvent::where('type', EventType::CLICKED)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('type', EventType::CLICKED)), 'open' => Tab::make() ->label(__('Open')) ->icon('heroicon-o-envelope-open') - ->badge(MailEvent::where('type', WebhookEventType::OPEN)->count()) - ->modifyQueryUsing(fn (Builder $query) => $query->where('type', WebhookEventType::OPEN)), + ->badge(MailEvent::where('type', EventType::OPENED)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('type', EventType::OPENED)), - 'bounce' => Tab::make() - ->label(__('Bounce')) + 'soft_bounce' => Tab::make() + ->label(__('Soft Bounce')) ->icon('heroicon-o-x-circle') - ->badge(MailEvent::where('type', WebhookEventType::BOUNCE)->count()) - ->modifyQueryUsing(fn (Builder $query) => $query->where('type', WebhookEventType::BOUNCE)), + ->badge(MailEvent::where('type', EventType::SOFT_BOUNCED)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('type', EventType::SOFT_BOUNCED)), + + 'hard_bounce' => Tab::make() + ->label(__('Hard Bounce')) + ->icon('heroicon-o-x-circle') + ->badge(MailEvent::where('type', EventType::HARD_BOUNCED)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('type', EventType::HARD_BOUNCED)), 'complaint' => Tab::make() ->label(__('Complaint')) ->icon('heroicon-o-exclamation-circle') - ->badge(MailEvent::where('type', WebhookEventType::COMPLAINT)->count()) - ->modifyQueryUsing(fn (Builder $query) => $query->where('type', WebhookEventType::COMPLAINT)), + ->badge(MailEvent::where('type', EventType::COMPLAINED)->count()) + ->modifyQueryUsing(fn (Builder $query) => $query->where('type', EventType::COMPLAINED)), ]; } } From 85db29725ca9babed3ec77a2ec53057481e9dc56 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Sat, 7 Sep 2024 08:31:44 +0300 Subject: [PATCH 2/2] fix WebhookEventType --- src/Resources/EventResource.php | 32 +++++++++++++++++--------------- src/Resources/MailResource.php | 17 +++++++++-------- 2 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/Resources/EventResource.php b/src/Resources/EventResource.php index 93c1b07..0069a7f 100644 --- a/src/Resources/EventResource.php +++ b/src/Resources/EventResource.php @@ -11,7 +11,7 @@ use Filament\Tables\Table; use Vormkracht10\FilamentMails\Resources\EventResource\Pages\ListEvents; use Vormkracht10\FilamentMails\Resources\EventResource\Pages\Pages\ViewEvent; -use Vormkracht10\Mails\Enums\WebhookEventType; +use Vormkracht10\Mails\Enums\EventType; use Vormkracht10\Mails\Models\MailEvent; class EventResource extends Resource @@ -74,14 +74,15 @@ public static function infolist(Infolist $infolist): Infolist TextEntry::make('type') ->label(__('Type')) ->badge() - ->color(fn (WebhookEventType $state): string => match ($state) { - WebhookEventType::DELIVERY => 'success', - WebhookEventType::CLICK => 'clicked', - WebhookEventType::OPEN => 'success', - WebhookEventType::BOUNCE => 'danger', - WebhookEventType::COMPLAINT => 'danger', + ->color(fn (EventType $state): string => match ($state) { + EventType::DELIVERED => 'success', + EventType::CLICKED => 'clicked', + EventType::OPENED => 'success', + EventType::SOFT_BOUNCED => 'danger', + EventType::HARD_BOUNCED => 'danger', + EventType::COMPLAINED => 'danger', }) - ->formatStateUsing(function (WebhookEventType $state) { + ->formatStateUsing(function (EventType $state) { return ucfirst($state->value); }), TextEntry::make('mail.subject') @@ -193,14 +194,15 @@ public static function table(Table $table): Table ->label(__('Type')) ->sortable() ->badge() - ->color(fn (WebhookEventType $state): string => match ($state) { - WebhookEventType::DELIVERY => 'success', - WebhookEventType::CLICK => 'clicked', - WebhookEventType::OPEN => 'success', - WebhookEventType::BOUNCE => 'danger', - WebhookEventType::COMPLAINT => 'danger', + ->color(fn (EventType $state): string => match ($state) { + EventType::DELIVERED => 'success', + EventType::CLICKED => 'clicked', + EventType::OPENED => 'success', + EventType::SOFT_BOUNCED => 'danger', + EventType::HARD_BOUNCED => 'danger', + EventType::COMPLAINED => 'danger', }) - ->formatStateUsing(function (WebhookEventType $state) { + ->formatStateUsing(function (EventType $state) { return ucfirst($state->value); }) ->searchable(), diff --git a/src/Resources/MailResource.php b/src/Resources/MailResource.php index 0a23d52..e87795a 100644 --- a/src/Resources/MailResource.php +++ b/src/Resources/MailResource.php @@ -22,7 +22,7 @@ use Vormkracht10\FilamentMails\Resources\MailResource\Pages\ListMails; use Vormkracht10\FilamentMails\Resources\MailResource\Pages\ViewMail; use Vormkracht10\Mails\Actions\ResendMail; -use Vormkracht10\Mails\Enums\WebhookEventType; +use Vormkracht10\Mails\Enums\EventType; use Vormkracht10\Mails\Models\MailEvent; class MailResource extends Resource @@ -153,14 +153,15 @@ public static function infolist(Infolist $infolist): Infolist 'record' => $record, 'tenant' => filament()->getTenant()?->id, ])) - ->color(fn (WebhookEventType $state): string => match ($state) { - WebhookEventType::DELIVERY => 'success', - WebhookEventType::CLICK => 'clicked', - WebhookEventType::OPEN => 'success', - WebhookEventType::BOUNCE => 'danger', - WebhookEventType::COMPLAINT => 'danger', + ->color(fn (EventType $state): string => match ($state) { + EventType::DELIVERED => 'success', + EventType::CLICKED => 'clicked', + EventType::OPENED => 'success', + EventType::SOFT_BOUNCED => 'danger', + EventType::HARD_BOUNCED => 'danger', + EventType::COMPLAINED => 'danger', }) - ->formatStateUsing(function (WebhookEventType $state) { + ->formatStateUsing(function (EventType $state) { return ucfirst($state->value); }), TextEntry::make('occurred_at')