Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] event types #2

Merged
merged 3 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions src/Resources/EventResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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(),
Expand Down
32 changes: 19 additions & 13 deletions src/Resources/EventResource/Pages/ListEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)),
];
}
}
17 changes: 9 additions & 8 deletions src/Resources/MailResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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')
Expand Down