From 5756fa06d7df935dc9502eb780f765daa3f4668b Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Tue, 22 Oct 2024 17:39:42 -0500 Subject: [PATCH] feat:invitation email for shared portfolios --- .../InvitedToPortfolioNotification.php | 62 +++++++++++++++++++ .../views/components/ib-toolbar.blade.php | 2 +- .../livewire/share-portfolio-form.blade.php | 11 +++- .../vendor/notifications/email.blade.php | 2 +- 4 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 app/Notifications/InvitedToPortfolioNotification.php diff --git a/app/Notifications/InvitedToPortfolioNotification.php b/app/Notifications/InvitedToPortfolioNotification.php new file mode 100644 index 0000000..7d2d4db --- /dev/null +++ b/app/Notifications/InvitedToPortfolioNotification.php @@ -0,0 +1,62 @@ + + */ + public function via(object $notifiable): array + { + return ['mail']; + } + + /** + * Get the mail representation of the notification. + */ + public function toMail(object $notifiable): MailMessage + { + + return (new MailMessage) + ->replyTo($this->sender->email, $this->sender->name) + ->greeting('Hey there! 👋') + ->subject("{$this->sender->name} invited you to {$this->portfolio->title} on Investbrain!") + ->line("{$this->sender->name} has invited you to **{$this->portfolio->title}** on Investbrain, Smart open-source investment tracker that consolidates and monitors market performance across your different brokerages.") + ->line('Once you\'re in, you\'ll be able to see holdings, dividends, market performance and more!') + ->action("Get Started", route('portfolio.show', ['portfolio' => $this->portfolio->id])) + ->line("If you have any questions, you can reply to this email.") + ->salutation("See you there,\n". e($this->sender->name)); + } + + /** + * Get the array representation of the notification. + * + * @return array + */ + public function toArray(object $notifiable): array + { + return [ + // + ]; + } +} diff --git a/resources/views/components/ib-toolbar.blade.php b/resources/views/components/ib-toolbar.blade.php index 575dc1c..215df13 100644 --- a/resources/views/components/ib-toolbar.blade.php +++ b/resources/views/components/ib-toolbar.blade.php @@ -1,7 +1,7 @@ @props(['title' => ''])
merge(['class' => 'flex items-center mb-6']) }} class=""> -

{{ $title }}

+

{{ $title }}

{{ $slot }}
\ No newline at end of file diff --git a/resources/views/livewire/share-portfolio-form.blade.php b/resources/views/livewire/share-portfolio-form.blade.php index 2124040..12a0e56 100644 --- a/resources/views/livewire/share-portfolio-form.blade.php +++ b/resources/views/livewire/share-portfolio-form.blade.php @@ -6,6 +6,7 @@ use Livewire\Attributes\Rule; use Livewire\Volt\Component; use Illuminate\Support\Collection; use Mary\Traits\Toast; +use App\Notifications\InvitedToPortfolioNotification; new class extends Component { @@ -99,7 +100,14 @@ new class extends Component { 'full_access' => $this->fullAccess ]; - $this->portfolio->users()->sync($this->permissions); + $sync = $this->portfolio->users()->sync($this->permissions); + + if (!empty($sync['attached'])) { + + foreach($sync['attached'] as $newUserId) { + User::find($newUserId)->notify(new InvitedToPortfolioNotification($this->portfolio, auth()->user())); + }; + } $this->success(__('Shared portfolio with user')); $this->portfolio->refresh(); @@ -233,6 +241,5 @@ new class extends Component { {{ __('Add People') }} - \ No newline at end of file diff --git a/resources/views/vendor/notifications/email.blade.php b/resources/views/vendor/notifications/email.blade.php index 79c2408..739e761 100644 --- a/resources/views/vendor/notifications/email.blade.php +++ b/resources/views/vendor/notifications/email.blade.php @@ -37,7 +37,7 @@ {{-- Salutation --}} @if (! empty($salutation)) -{{ $salutation }} +{!! nl2br($salutation) !!} @else @lang('Regards,')
{{ config('app.name') }}