Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
35 changes: 34 additions & 1 deletion app/Filament/Admin/Resources/PermResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ public static function form(Form $form): Form
->placeholder('Adresse mail du responsable de la permanence')
->label('Adresse mail du responsable')
->default(auth()->user()?->email)
->email()
->columnSpan([
'sm' => 6,
'md' => 4,
Expand All @@ -214,6 +215,7 @@ public static function form(Form $form): Form
->required()
->placeholder('Adresse mail du sous-responsable')
->label('Adresse mail du sous-responsable')
->email()
->columnSpan([
'sm' => 6,
'md' => 4,
Expand All @@ -237,6 +239,7 @@ public static function form(Form $form): Form
->required(fn(Forms\Get $get) => $get('asso'))
->placeholder('Adresse mail de l\'association')
->label('Adresse mail de l\'association')
->email()
->columnSpan([
'sm' => 6,
'md' => 6,
Expand Down Expand Up @@ -484,12 +487,33 @@ public static function sendMail($record)
return;
}

// Vérification : l'email du responsable est-il valide?
if (!filter_var($record->mail_resp, FILTER_VALIDATE_EMAIL)) {
\Filament\Notifications\Notification::make()
->title('Erreur : Email invalide')
->body('Impossible d\'envoyer le mail car l\'email du responsable est invalide.')
->danger()
->send();
return;
}

DB::beginTransaction();

try {
$mailResp1 = $record->mail_resp;
$mailResp2 = $record->mail_resp_2;
$mailAsso = $record->mail_asso;
$incorrectEmails = [];

// Vérification : les emails sont-ils valides ?
if($mailResp2 && !filter_var($mailResp2, FILTER_VALIDATE_EMAIL)) {
$incorrectEmails[] = $mailResp2;
$mailResp2 = null;
}
if($mailAsso && !filter_var($mailAsso, FILTER_VALIDATE_EMAIL)) {
$incorrectEmails[] = $mailAsso;
$mailAsso = null;
}

$email = Mail::to($mailResp1);
if ($mailResp2 && $mailAsso) {
Expand All @@ -516,10 +540,19 @@ public static function sendMail($record)

DB::commit();

\Filament\Notifications\Notification::make()
if(!empty($incorrectEmails)) {
\Filament\Notifications\Notification::make()
->title('Mail envoyé avec succès')
->body('Sauf pour les adresses suivantes : ' . implode(', ', $incorrectEmails))
->success()
->send();
} else {
\Filament\Notifications\Notification::make()
->title('Mail envoyé avec succès')
->success()
->send();
}

} catch (Exception $e) {
DB::rollBack();
\Filament\Notifications\Notification::make()
Expand Down
3 changes: 3 additions & 0 deletions app/Filament/Public/Resources/RequestedPermsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public static function form(Form $form): Form
->placeholder('Adresse mail du responsable de la permanence')
->label('Adresse mail du responsable')
->default(auth()->user()?->email)
->email()
->columnSpan([
'sm' => 6,
'md' => 4,
Expand All @@ -209,6 +210,7 @@ public static function form(Form $form): Form
->required()
->placeholder('Adresse mail du sous-responsable')
->label('Adresse mail du sous-responsable')
->email()
->columnSpan([
'sm' => 6,
'md' => 4,
Expand All @@ -232,6 +234,7 @@ public static function form(Form $form): Form
->required(fn (Forms\Get $get) => $get('asso'))
->placeholder('Adresse mail de l\'association')
->label('Adresse mail de l\'association')
->email()
->columnSpan([
'sm' => 6,
'md' => 6,
Expand Down
Loading