2
2
3
3
namespace Vormkracht10 \FilamentMails \Resources ;
4
4
5
- use Filament \Tables ;
6
- use Illuminate \View \View ;
7
- use Filament \Tables \Table ;
8
- use Illuminate \Support \Carbon ;
9
- use Filament \Infolists \Infolist ;
10
- use Filament \Resources \Resource ;
11
- use Illuminate \Support \Collection ;
12
- use Filament \Tables \Actions \Action ;
13
- use Vormkracht10 \Mails \Models \Mail ;
14
- use Filament \Infolists \Components \Grid ;
15
- use Filament \Infolists \Components \Tabs ;
16
- use Vormkracht10 \Mails \Enums \EventType ;
17
5
use Filament \Forms \Components \TextInput ;
18
- use Filament \Notifications \ Notification ;
19
- use Vormkracht10 \ Mails \ Models \ MailEvent ;
6
+ use Filament \Infolists \ Components \ Grid ;
7
+ use Filament \ Infolists \ Components \ RepeatableEntry ;
20
8
use Filament \Infolists \Components \Section ;
21
- use Vormkracht10 \ Mails \ Actions \ ResendMail ;
9
+ use Filament \ Infolists \ Components \ Tabs ;
22
10
use Filament \Infolists \Components \Tabs \Tab ;
23
11
use Filament \Infolists \Components \TextEntry ;
24
12
use Filament \Infolists \Components \ViewEntry ;
25
- use Filament \Infolists \Components \RepeatableEntry ;
26
- use Vormkracht10 \FilamentMails \Resources \MailResource \Pages \ViewMail ;
13
+ use Filament \Infolists \Infolist ;
14
+ use Filament \Notifications \Notification ;
15
+ use Filament \Resources \Resource ;
16
+ use Filament \Tables ;
17
+ use Filament \Tables \Actions \Action ;
18
+ use Filament \Tables \Table ;
19
+ use Illuminate \Support \Carbon ;
20
+ use Illuminate \Support \Collection ;
21
+ use Illuminate \View \View ;
27
22
use Vormkracht10 \FilamentMails \Resources \MailResource \Pages \ListMails ;
23
+ use Vormkracht10 \FilamentMails \Resources \MailResource \Pages \ViewMail ;
28
24
use Vormkracht10 \FilamentMails \Resources \MailResource \Widgets \MailStatsWidget ;
25
+ use Vormkracht10 \Mails \Actions \ResendMail ;
26
+ use Vormkracht10 \Mails \Enums \EventType ;
27
+ use Vormkracht10 \Mails \Models \Mail ;
28
+ use Vormkracht10 \Mails \Models \MailEvent ;
29
29
30
30
class MailResource extends Resource
31
31
{
@@ -84,22 +84,22 @@ public static function infolist(Infolist $infolist): Infolist
84
84
->label (__ ('Subject ' )),
85
85
TextEntry::make ('from ' )
86
86
->label (__ ('From ' ))
87
- ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->from )),
87
+ ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->from )),
88
88
TextEntry::make ('to ' )
89
89
->label (__ ('Recipient ' ))
90
- ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->to )),
90
+ ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->to )),
91
91
TextEntry::make ('cc ' )
92
92
->label (__ ('CC ' ))
93
93
->default ('- ' )
94
- ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->cc ?? [])),
94
+ ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->cc ?? [])),
95
95
TextEntry::make ('bcc ' )
96
96
->label (__ ('BCC ' ))
97
97
->default ('- ' )
98
- ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->bcc ?? [])),
98
+ ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->bcc ?? [])),
99
99
TextEntry::make ('reply_to ' )
100
100
->default ('- ' )
101
101
->label (__ ('Reply To ' ))
102
- ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->reply_to ?? [])),
102
+ ->getStateUsing (fn (Mail $ record ) => self ::formatMailState ($ record ->reply_to ?? [])),
103
103
]),
104
104
]),
105
105
Tab::make (__ ('Statistics ' ))
@@ -171,11 +171,11 @@ public static function infolist(Infolist $infolist): Infolist
171
171
TextEntry::make ('type ' )
172
172
->label (__ ('Type ' ))
173
173
->badge ()
174
- ->url (fn (MailEvent $ record ) => route ('filament. ' . filament ()->getCurrentPanel ()?->getId() . '.resources.mails.events.view ' , [
174
+ ->url (fn (MailEvent $ record ) => route ('filament. ' . filament ()->getCurrentPanel ()?->getId() . '.resources.mails.events.view ' , [
175
175
'record ' => $ record ,
176
176
'tenant ' => filament ()->getTenant ()?->id,
177
177
]))
178
- ->color (fn (EventType $ state ): string => match ($ state ) {
178
+ ->color (fn (EventType $ state ): string => match ($ state ) {
179
179
EventType::DELIVERED => 'success ' ,
180
180
EventType::CLICKED => 'clicked ' ,
181
181
EventType::OPENED => 'info ' ,
@@ -189,7 +189,7 @@ public static function infolist(Infolist $infolist): Infolist
189
189
return ucfirst ($ state ->value );
190
190
}),
191
191
TextEntry::make ('occurred_at ' )
192
- ->url (fn (MailEvent $ record ) => route ('filament. ' . filament ()->getCurrentPanel ()?->getId() . '.resources.mails.events.view ' , [
192
+ ->url (fn (MailEvent $ record ) => route ('filament. ' . filament ()->getCurrentPanel ()?->getId() . '.resources.mails.events.view ' , [
193
193
'record ' => $ record ,
194
194
'tenant ' => filament ()->getTenant ()?->id,
195
195
]))
@@ -219,7 +219,7 @@ public static function infolist(Infolist $infolist): Infolist
219
219
->hiddenLabel ()
220
220
->label (__ ('HTML Content ' ))
221
221
->extraAttributes (['class ' => 'overflow-x-auto ' ])
222
- ->formatStateUsing (fn (string $ state , Mail $ record ): View => view (
222
+ ->formatStateUsing (fn (string $ state , Mail $ record ): View => view (
223
223
'filament-mails::mails.preview ' ,
224
224
['html ' => $ state , 'mail ' => $ record ],
225
225
)),
@@ -229,7 +229,7 @@ public static function infolist(Infolist $infolist): Infolist
229
229
TextEntry::make ('html ' )
230
230
->hiddenLabel ()
231
231
->extraAttributes (['class ' => 'overflow-x-auto ' ])
232
- ->formatStateUsing (fn (string $ state , Mail $ record ): View => view (
232
+ ->formatStateUsing (fn (string $ state , Mail $ record ): View => view (
233
233
'filament-mails::mails.html ' ,
234
234
['html ' => $ state , 'mail ' => $ record ],
235
235
))
@@ -260,12 +260,12 @@ public static function infolist(Infolist $infolist): Infolist
260
260
TextEntry::make ('attachments ' )
261
261
->hiddenLabel ()
262
262
->label (__ ('Attachments ' ))
263
- ->visible (fn (Mail $ record ) => $ record ->attachments ->count () == 0 )
263
+ ->visible (fn (Mail $ record ) => $ record ->attachments ->count () == 0 )
264
264
->default (__ ('Email has no attachments ' )),
265
265
RepeatableEntry::make ('attachments ' )
266
266
->hiddenLabel ()
267
267
->label (__ ('Attachments ' ))
268
- ->visible (fn (Mail $ record ) => $ record ->attachments ->count () > 0 )
268
+ ->visible (fn (Mail $ record ) => $ record ->attachments ->count () > 0 )
269
269
->schema ([
270
270
Grid::make (3 )
271
271
->schema ([
@@ -277,7 +277,7 @@ public static function infolist(Infolist $infolist): Infolist
277
277
->label (__ ('Mime Type ' )),
278
278
ViewEntry::make ('uuid ' )
279
279
->label (__ ('Download ' ))
280
- ->getStateUsing (fn ($ record ) => $ record )
280
+ ->getStateUsing (fn ($ record ) => $ record )
281
281
->view ('filament-mails::mails.download ' ),
282
282
]),
283
283
]),
@@ -297,7 +297,7 @@ public static function table(Table $table): Table
297
297
->label (__ ('Status ' ))
298
298
->sortable ()
299
299
->badge ()
300
- ->color (fn (string $ state ): string => match ($ state ) {
300
+ ->color (fn (string $ state ): string => match ($ state ) {
301
301
__ ('Soft Bounced ' ) => 'warning ' ,
302
302
__ ('Hard Bounced ' ) => 'danger ' ,
303
303
__ ('Complained ' ) => 'danger ' ,
@@ -317,27 +317,27 @@ public static function table(Table $table): Table
317
317
Tables \Columns \IconColumn::make ('attachments ' )
318
318
->label ('' )
319
319
->alignLeft ()
320
- ->getStateUsing (fn (Mail $ record ) => $ record ->attachments ->count () > 0 )
321
- ->icon (fn (string $ state ): string => $ state ? 'heroicon-o-paper-clip ' : '' ),
320
+ ->getStateUsing (fn (Mail $ record ) => $ record ->attachments ->count () > 0 )
321
+ ->icon (fn (string $ state ): string => $ state ? 'heroicon-o-paper-clip ' : '' ),
322
322
Tables \Columns \TextColumn::make ('to ' )
323
323
->label (__ ('Recipient ' ))
324
324
->limit (50 )
325
- ->getStateUsing (fn (Mail $ record ) => self ::formatMailState (emails: $ record ->to , mailOnly: true ))
325
+ ->getStateUsing (fn (Mail $ record ) => self ::formatMailState (emails: $ record ->to , mailOnly: true ))
326
326
->sortable ()
327
327
->searchable (),
328
328
Tables \Columns \TextColumn::make ('opens ' )
329
329
->label (__ ('Opens ' ))
330
- ->tooltip (fn (Mail $ record ) => __ ('Last opened at :date ' , ['date ' => $ record ->last_opened_at ?->format('d-m-Y H:i ' )]))
330
+ ->tooltip (fn (Mail $ record ) => __ ('Last opened at :date ' , ['date ' => $ record ->last_opened_at ?->format('d-m-Y H:i ' )]))
331
331
->sortable (),
332
332
Tables \Columns \TextColumn::make ('clicks ' )
333
333
->label (__ ('Clicks ' ))
334
- ->tooltip (fn (Mail $ record ) => __ ('Last clicked at :date ' , ['date ' => $ record ->last_clicked_at ?->format('d-m-Y H:i ' )]))
334
+ ->tooltip (fn (Mail $ record ) => __ ('Last clicked at :date ' , ['date ' => $ record ->last_clicked_at ?->format('d-m-Y H:i ' )]))
335
335
->sortable (),
336
336
Tables \Columns \TextColumn::make ('sent_at ' )
337
337
->label (__ ('Sent At ' ))
338
338
->dateTime ('d-m-Y H:i ' )
339
339
->since ()
340
- ->tooltip (fn (Mail $ record ) => $ record ->sent_at ?->format('d-m-Y H:i ' ))
340
+ ->tooltip (fn (Mail $ record ) => $ record ->sent_at ?->format('d-m-Y H:i ' ))
341
341
->sortable ()
342
342
->searchable (),
343
343
])
@@ -430,8 +430,8 @@ public static function getPages(): array
430
430
private static function formatMailState (array $ emails , bool $ mailOnly = false ): string
431
431
{
432
432
return collect ($ emails )
433
- ->mapWithKeys (fn ($ value , $ key ) => [$ key => $ value ?? $ key ])
434
- ->map (fn ($ value , $ key ) => $ mailOnly ? $ key : ($ value === null ? $ key : "$ value < $ key> " ))
433
+ ->mapWithKeys (fn ($ value , $ key ) => [$ key => $ value ?? $ key ])
434
+ ->map (fn ($ value , $ key ) => $ mailOnly ? $ key : ($ value === null ? $ key : "$ value < $ key> " ))
435
435
->implode (', ' );
436
436
}
437
437
@@ -441,4 +441,4 @@ public static function getWidgets(): array
441
441
MailStatsWidget::class,
442
442
];
443
443
}
444
- }
444
+ }
0 commit comments