From f9eb48c9b82185e775a1fb7374c39f9f307723a5 Mon Sep 17 00:00:00 2001 From: Alex Popa Date: Mon, 2 Dec 2024 13:11:35 +0200 Subject: [PATCH] Fix email --- .../UserResource/Pages/CreateUser.php | 3 +- app/Models/User.php | 6 ++ .../WelcomeNotificationInAnotherTenant.php | 57 +++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 app/Notifications/Organizations/WelcomeNotificationInAnotherTenant.php diff --git a/app/Filament/Organizations/Resources/UserResource/Pages/CreateUser.php b/app/Filament/Organizations/Resources/UserResource/Pages/CreateUser.php index f713095e..5d0e5588 100644 --- a/app/Filament/Organizations/Resources/UserResource/Pages/CreateUser.php +++ b/app/Filament/Organizations/Resources/UserResource/Pages/CreateUser.php @@ -34,7 +34,8 @@ protected function handleRecordCreation(array $data): Model { if ($user = User::query()->where('email', $data['email'])->first()) { $this->associateRecordWithTenant($user, Filament::getTenant()); - $user->sendWelcomeNotification(); + $user->initializeStatus(); + $user->sendWelcomeNotificationInAnotherTenant(); return $user; } diff --git a/app/Models/User.php b/app/Models/User.php index 6c5fef0c..08d940b2 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -7,6 +7,7 @@ use App\Concerns\HasPermissions; use App\Concerns\HasUlid; use App\Concerns\MustSetInitialPassword; +use App\Notifications\Organizations\WelcomeNotificationInAnotherTenant; use Filament\Facades\Filament; use Filament\Models\Contracts\FilamentUser; use Filament\Models\Contracts\HasAvatar; @@ -281,4 +282,9 @@ public function initializeStatus(): void 'organization_id' => Filament::getTenant()->id, ]); } + + public function sendWelcomeNotificationInAnotherTenant(): void + { + $this->notify(new WelcomeNotificationInAnotherTenant); + } } diff --git a/app/Notifications/Organizations/WelcomeNotificationInAnotherTenant.php b/app/Notifications/Organizations/WelcomeNotificationInAnotherTenant.php new file mode 100644 index 00000000..3bdba9be --- /dev/null +++ b/app/Notifications/Organizations/WelcomeNotificationInAnotherTenant.php @@ -0,0 +1,57 @@ + + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + // TODO: change line msg + return (new MailMessage) + ->subject(__('email.organization.welcome.subject')) + ->line('![Logo](' . Vite::asset('resources/svg/logo.svg') . ')') + ->greeting(__('email.organization.welcome.greeting', ['name' => $notifiable->first_name])) + ->line( + __('email.organization.welcome.intro_line_1', [ + 'institution_name' => Filament::getTenant()?->institution->name ?? '', + 'center_name' => Filament::getTenant()?->name ?? '', + ]) + ) + ->line(__('email.organization.welcome.intro_line_2')) + ->line(__('email.organization.welcome.intro_line_3')) + ->action( + __('email.organization.welcome.accept_invitation'), + URL::signedRoute($this->route, ['tenant' => Filament::getTenant()]) + ) + ->line(__('email.organization.welcome.intro_line_4')) + ->line(new HtmlString(__('email.organization.welcome.intro_line_5'))) + ->salutation(__('email.salutation')); + } +}