feat(Membership): add notification for user and admin during registration
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m30s
All checks were successful
Deploy Roxane to Preprod / deploy (push) Successful in 1m30s
This commit is contained in:
@@ -4,8 +4,12 @@ namespace App\Filament\Resources\Memberships\Pages;
|
||||
|
||||
use App\Filament\Resources\Memberships\MembershipResource;
|
||||
use App\Models\Membership;
|
||||
use App\Notifications\MembershipValidatedNotification;
|
||||
use Filament\Actions\Action;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Illuminate\Contracts\Support\Htmlable;
|
||||
|
||||
class EditMembership extends EditRecord
|
||||
@@ -15,17 +19,40 @@ class EditMembership extends EditRecord
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
Action::make('validate')
|
||||
->label(__('memberships.actions.validate'))
|
||||
->icon(Heroicon::OutlinedCheckCircle)
|
||||
->color('success')
|
||||
->visible(fn (Membership $record) => $record->status === 'pending')
|
||||
->form([
|
||||
DatePicker::make('start_date')
|
||||
->label(Membership::getAttributeLabel('start_date'))
|
||||
->required(),
|
||||
DatePicker::make('end_date')
|
||||
->label(Membership::getAttributeLabel('end_date'))
|
||||
->required(),
|
||||
])
|
||||
->fillForm(fn (Membership $record): array => [
|
||||
'start_date' => $record->start_date,
|
||||
'end_date' => $record->end_date,
|
||||
])
|
||||
->action(function (Membership $record, array $data): void {
|
||||
$record->update([
|
||||
'status' => 'active',
|
||||
'start_date' => $data['start_date'],
|
||||
'end_date' => $data['end_date'],
|
||||
]);
|
||||
$record->member->notify(new MembershipValidatedNotification($record->fresh(['member', 'package'])));
|
||||
}),
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @property Membership $record
|
||||
* @return string|Htmlable
|
||||
*
|
||||
*/
|
||||
public function getTitle(): string | Htmlable
|
||||
public function getTitle(): string|Htmlable
|
||||
{
|
||||
return Membership::getAttributeLabel('membership') . ' #' . $this->record->id;
|
||||
return Membership::getAttributeLabel('membership').' #'.$this->record->id;
|
||||
}
|
||||
}
|
||||
|
||||
54
app/Notifications/MemberNewRequestMemberNotification.php
Normal file
54
app/Notifications/MemberNewRequestMemberNotification.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Member;
|
||||
use App\Models\NotificationTemplate;
|
||||
use App\Models\Package;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class MemberNewRequestMemberNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
public readonly Member $member,
|
||||
public readonly Package $package,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$template = NotificationTemplate::findByIdentifier('member_new_request_member');
|
||||
|
||||
$vars = [
|
||||
'member_name' => $this->member->full_name,
|
||||
'package_name' => $this->package->name,
|
||||
'app_name' => 'Le Retzien Libre',
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($template->renderSubject($vars))
|
||||
->view('notifications.mail-template', [
|
||||
'body' => $template->renderBody($vars),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
52
app/Notifications/MembershipValidatedNotification.php
Normal file
52
app/Notifications/MembershipValidatedNotification.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Notifications;
|
||||
|
||||
use App\Models\Membership;
|
||||
use App\Models\NotificationTemplate;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Notifications\Messages\MailMessage;
|
||||
use Illuminate\Notifications\Notification;
|
||||
|
||||
class MembershipValidatedNotification extends Notification implements ShouldQueue
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(public readonly Membership $membership) {}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public function via(object $notifiable): array
|
||||
{
|
||||
return ['mail'];
|
||||
}
|
||||
|
||||
public function toMail(object $notifiable): MailMessage
|
||||
{
|
||||
$template = NotificationTemplate::findByIdentifier('membership_validated');
|
||||
|
||||
$vars = [
|
||||
'member_name' => $this->membership->member->full_name,
|
||||
'package_name' => $this->membership->package->name,
|
||||
'start_date' => $this->membership->start_date?->format('d/m/Y') ?? '',
|
||||
'end_date' => $this->membership->end_date?->format('d/m/Y') ?? '',
|
||||
'app_name' => config('app.name'),
|
||||
];
|
||||
|
||||
return (new MailMessage)
|
||||
->subject($template->renderSubject($vars))
|
||||
->view('notifications.mail-template', [
|
||||
'body' => $template->renderBody($vars),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(object $notifiable): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@ use App\Models\Package;
|
||||
use App\Notifications\MemberDeactivatedAdminNotification;
|
||||
use App\Notifications\MemberDeactivatedMemberNotification;
|
||||
use App\Notifications\MemberNewRequestAdminNotification;
|
||||
use App\Notifications\MemberNewRequestMemberNotification;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
class MemberService
|
||||
@@ -55,6 +56,8 @@ class MemberService
|
||||
Notification::route('mail', config('app.admin_email'))
|
||||
->notify(new MemberNewRequestAdminNotification($member, $package, (float) $data['amount']));
|
||||
|
||||
$member->notify(new MemberNewRequestMemberNotification($member, $package));
|
||||
|
||||
event(new MemberRegistered($member));
|
||||
|
||||
return $member;
|
||||
|
||||
Reference in New Issue
Block a user