diff --git a/app/Listeners/Credit/CreditCreatedNotification.php b/app/Listeners/Credit/CreditCreatedNotification.php index db9ccef8e958..4cd093fdc824 100644 --- a/app/Listeners/Credit/CreditCreatedNotification.php +++ b/app/Listeners/Credit/CreditCreatedNotification.php @@ -40,8 +40,6 @@ class CreditCreatedNotification implements ShouldQueue { MultiDB::setDb($event->company->db); - // $first_notification_sent = true; - $credit = $event->credit; /* We loop through each user and determine whether they need to be notified */ @@ -49,12 +47,6 @@ class CreditCreatedNotification implements ShouldQueue /* The User */ $user = $company_user->user; - $use_react_link = false; - - if($company_user->react_settings && property_exists($company_user->react_settings, 'react_notification_link') && $company_user->react_settings->react_notification_link) { - $use_react_link = true; - } - /* This is only here to handle the alternate message channels - ie Slack */ // $notification = new EntitySentNotification($event->invitation, 'credit'); @@ -66,7 +58,7 @@ class CreditCreatedNotification implements ShouldQueue unset($methods[$key]); $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($credit, 'credit', $use_react_link))->build()); + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($credit, 'credit', $company_user->portalType()))->build()); $nmo->company = $credit->company; $nmo->settings = $credit->company->settings; $nmo->to_user = $user; diff --git a/app/Listeners/Invoice/InvoiceCreatedNotification.php b/app/Listeners/Invoice/InvoiceCreatedNotification.php index cafbea8e3b4f..867c1e9161dc 100644 --- a/app/Listeners/Invoice/InvoiceCreatedNotification.php +++ b/app/Listeners/Invoice/InvoiceCreatedNotification.php @@ -48,16 +48,11 @@ class InvoiceCreatedNotification implements ShouldQueue foreach ($event->company->company_users as $company_user) { /* The User */ $user = $company_user->user; - $use_react_link = false; - + if (! $user) { continue; } - if(isset($company_user->react_settings->react_notification_link) && $company_user->react_settings->react_notification_link) { - $use_react_link = true; - } - /* This is only here to handle the alternate message channels - ie Slack */ // $notification = new EntitySentNotification($event->invitation, 'invoice'); @@ -69,7 +64,7 @@ class InvoiceCreatedNotification implements ShouldQueue unset($methods[$key]); $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($invoice, 'invoice', $use_react_link))->build()); + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($invoice, 'invoice', $company_user->portalType()))->build()); $nmo->company = $invoice->company; $nmo->settings = $invoice->company->settings; $nmo->to_user = $user; diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php index 436ad651d3dd..998cbd4e1167 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php @@ -45,7 +45,6 @@ class PurchaseOrderCreatedListener implements ShouldQueue $purchase_order = $event->purchase_order; - /* We loop through each user and determine whether they need to be notified */ foreach ($event->company->company_users as $company_user) { /* The User */ @@ -55,13 +54,6 @@ class PurchaseOrderCreatedListener implements ShouldQueue continue; } - $use_react_link = false; - - if($company_user->react_settings && property_exists($company_user->react_settings, 'react_notification_link') && $company_user->react_settings->react_notification_link) { - $use_react_link = true; - nlog("inside"); - } - /* This is only here to handle the alternate message channels - ie Slack */ // $notification = new EntitySentNotification($event->invitation, 'purchase_order'); @@ -73,7 +65,7 @@ class PurchaseOrderCreatedListener implements ShouldQueue unset($methods[$key]); $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($purchase_order, 'purchase_order', $use_react_link))->build()); + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($purchase_order, 'purchase_order', $company_user->portalType()))->build()); $nmo->company = $purchase_order->company; $nmo->settings = $purchase_order->company->settings; diff --git a/app/Listeners/Quote/QuoteCreatedNotification.php b/app/Listeners/Quote/QuoteCreatedNotification.php index 2759ea9c2590..81daa301151b 100644 --- a/app/Listeners/Quote/QuoteCreatedNotification.php +++ b/app/Listeners/Quote/QuoteCreatedNotification.php @@ -56,7 +56,7 @@ class QuoteCreatedNotification implements ShouldQueue $use_react_link = false; - if($company_user->react_settings && property_exists($company_user->react_settings, 'react_notification_link') && $company_user->react_settings->react_notification_link) { + if(isset($company_user->react_settings->react_notification_link) && $company_user->react_settings->react_notification_link) { $use_react_link = true; } @@ -71,7 +71,7 @@ class QuoteCreatedNotification implements ShouldQueue unset($methods[$key]); $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($quote, 'quote'))->build()); + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($quote, 'quote', $company_user->portalType()))->build()); $nmo->company = $quote->company; $nmo->settings = $quote->company->settings; diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index dd117d660a47..1cc42e1a7769 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -196,8 +196,22 @@ class CompanyUser extends Pivot public function scopeAuthCompany($query) { - $query->where('company_id', auth()->user()->companyId()); + /** @var \App\Models\User $user */ + $user = auth()->user(); + + $query->where('company_id', $user->companyId()); return $query; } -} + + /** + * Determines if the notifications should be React of Flutter links + * + * @return bool + */ + public function portalType():bool + { + return isset($this->react_settings->react_notification_link) && $this->react_settings->react_notification_link; + } + +} \ No newline at end of file diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index 20390c2a06fb..e3e0a19f7a0f 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -118,7 +118,7 @@ class InvoiceInvitation extends BaseModel /** * @return mixed */ - public function entity() + public function getEntity() { return $this->belongsTo(Invoice::class)->withTrashed(); } diff --git a/app/Models/PurchaseOrderInvitation.php b/app/Models/PurchaseOrderInvitation.php index eaba3a38f72b..86122fd794c0 100644 --- a/app/Models/PurchaseOrderInvitation.php +++ b/app/Models/PurchaseOrderInvitation.php @@ -194,8 +194,16 @@ class PurchaseOrderInvitation extends BaseModel } } - public function getAdminLink() :string + public function getAdminLink($use_react_link = false) :string { - return $this->getLink().'?silent=true'; + return $use_react_link ? $this->getReactLink() : $this->getLink().'?silent=true'; } + + private function getReactLink(): string + { + $entity_type = Str::snake(class_basename($this->entityType())); + + return config('ninja.app_url')."/#/{$entity_type}/{$this->{$entity_type}->hashed_id}/edit"; + } + } diff --git a/app/Utils/Traits/Inviteable.php b/app/Utils/Traits/Inviteable.php index b0a0aacd2134..305fc5881fac 100644 --- a/app/Utils/Traits/Inviteable.php +++ b/app/Utils/Traits/Inviteable.php @@ -148,6 +148,6 @@ trait Inviteable { $entity_type = Str::snake(class_basename($this->entityType())); - return config('ninja.app_url')."/#/{$entity_type}/{$this->invoice->hashed_id}/edit"; + return config('ninja.react_url')."/{$entity_type}s/{$this->{$entity_type}->hashed_id}/edit"; } } diff --git a/config/ninja.php b/config/ninja.php index 4d86a860d804..b87fb6c6b296 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -5,7 +5,7 @@ return [ 'web_url' => 'https://www.invoiceninja.com', 'admin_token' => env('NINJA_ADMIN_TOKEN', ''), 'license_url' => 'https://app.invoiceninja.com', - 'react_url' => 'https://app.invoicing.co', + 'react_url' => env('REACT_URL', 'https://app.invoicing.co'), 'production' => env('NINJA_PROD', false), 'license' => env('NINJA_LICENSE', ''), 'version_url' => 'https://pdf.invoicing.co/api/version',