@@ -413,7 +413,7 @@ public static function table(Table $table): Table
413413 ->icon ('heroicon-o-arrow-uturn-right ' )
414414 ->requiresConfirmation ()
415415 ->modalDescription (__ ('Are you sure you want to resend the selected mails? ' ))
416- ->form (self ::getResendForm ( ))
416+ ->form (fn ( $ records ) => self ::getBulkResendForm ( $ records ))
417417 ->action (function (Collection $ records , array $ data ) {
418418 foreach ($ records as $ record ) {
419419 (new ResendMail )->handle ($ record , $ data ['to ' ], $ data ['cc ' ] ?? [], $ data ['bcc ' ] ?? []);
@@ -448,6 +448,43 @@ private static function getResendForm(): array
448448 ];
449449 }
450450
451+ private static function getBulkResendForm ($ records ): array
452+ {
453+ $ extractEmails = function ($ records , $ field ) {
454+ return collect ($ records )
455+ ->map (fn ($ record ) => array_keys ($ record ->{$ field } ?? []))
456+ ->flatten ()
457+ ->unique ()
458+ ->toArray ();
459+ };
460+
461+
462+ $ toEmails = $ extractEmails ($ records , 'to ' );
463+ $ ccEmails = $ extractEmails ($ records , 'cc ' );
464+ $ bccEmails = $ extractEmails ($ records , 'bcc ' );
465+
466+ return [
467+ TagsInput::make ('to ' )
468+ ->placeholder (__ ('Recipient(s) ' ))
469+ ->label (__ ('Recipient(s) ' ))
470+ ->default ($ toEmails )
471+ ->required ()
472+ ->nestedRecursiveRules (['email:rfc,dns ' ]),
473+
474+ TagsInput::make ('cc ' )
475+ ->placeholder (__ ('CC ' ))
476+ ->label (__ ('CC ' ))
477+ ->default ($ ccEmails )
478+ ->nestedRecursiveRules (['nullable ' , 'email:rfc,dns ' ]),
479+
480+ TagsInput::make ('bcc ' )
481+ ->placeholder (__ ('BCC ' ))
482+ ->label (__ ('BCC ' ))
483+ ->default ($ bccEmails )
484+ ->nestedRecursiveRules (['nullable ' , 'email:rfc,dns ' ]),
485+ ];
486+ }
487+
451488 public static function getPages (): array
452489 {
453490 return [
0 commit comments