diff --git a/app/Listeners/Credit/CreditCreatedNotification.php b/app/Listeners/Credit/CreditCreatedNotification.php index 6a982dfe46ae..db9ccef8e958 100644 --- a/app/Listeners/Credit/CreditCreatedNotification.php +++ b/app/Listeners/Credit/CreditCreatedNotification.php @@ -49,6 +49,12 @@ 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'); @@ -60,7 +66,7 @@ class CreditCreatedNotification implements ShouldQueue unset($methods[$key]); $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($credit, 'credit'))->build()); + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($credit, 'credit', $use_react_link))->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 bd8a00452f12..cafbea8e3b4f 100644 --- a/app/Listeners/Invoice/InvoiceCreatedNotification.php +++ b/app/Listeners/Invoice/InvoiceCreatedNotification.php @@ -24,7 +24,7 @@ class InvoiceCreatedNotification implements ShouldQueue { use UserNotifies; - public $delay = 7; + public $delay = 3; public function __construct() { @@ -53,8 +53,8 @@ class InvoiceCreatedNotification implements ShouldQueue if (! $user) { continue; } - - 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; } diff --git a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php index 61a686de03b4..436ad651d3dd 100644 --- a/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php +++ b/app/Listeners/PurchaseOrder/PurchaseOrderCreatedListener.php @@ -55,6 +55,13 @@ 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'); @@ -66,7 +73,7 @@ class PurchaseOrderCreatedListener implements ShouldQueue unset($methods[$key]); $nmo = new NinjaMailerObject; - $nmo->mailable = new NinjaMailer((new EntityCreatedObject($purchase_order, 'purchase_order'))->build()); + $nmo->mailable = new NinjaMailer((new EntityCreatedObject($purchase_order, 'purchase_order', $use_react_link))->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 06b697e95930..2759ea9c2590 100644 --- a/app/Listeners/Quote/QuoteCreatedNotification.php +++ b/app/Listeners/Quote/QuoteCreatedNotification.php @@ -54,6 +54,12 @@ class QuoteCreatedNotification 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; + } + /* This is only here to handle the alternate message channels - ie Slack */ // $notification = new EntitySentNotification($event->invitation, 'quote'); diff --git a/app/Mail/Admin/EntityCreatedObject.php b/app/Mail/Admin/EntityCreatedObject.php index 06c1811a71a8..13a2a3003c2d 100644 --- a/app/Mail/Admin/EntityCreatedObject.php +++ b/app/Mail/Admin/EntityCreatedObject.php @@ -33,7 +33,7 @@ class EntityCreatedObject private $template_body; - private $use_react_link; + protected bool $use_react_link; public function __construct($entity, $entity_type, $use_react_link = false) { @@ -168,7 +168,7 @@ class EntityCreatedObject return [ 'title' => $this->getSubject(), 'message' => $this->getMessage(), - 'url' => $this->entity->invitations()->first()->getAdminLink(), + 'url' => $this->entity->invitations()->first()->getAdminLink($this->use_react_link), 'button' => ctrans("texts.view_{$this->entity_type}"), 'signature' => $settings->email_signature, 'logo' => $this->company->present()->logo(), diff --git a/app/Models/CompanyUser.php b/app/Models/CompanyUser.php index 5c5754c18f2b..dd117d660a47 100644 --- a/app/Models/CompanyUser.php +++ b/app/Models/CompanyUser.php @@ -35,7 +35,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property int|null $updated_at * @property int $permissions_updated_at * @property string $ninja_portal_url - * @property string|null $react_settings + * @property object|null $react_settings * @property-read \App\Models\Account $account * @property-read \App\Models\Company $company * @property-read \App\Models\CompanyUser $cu diff --git a/app/Models/CreditInvitation.php b/app/Models/CreditInvitation.php index 1c5709221688..1c29cd73b75a 100644 --- a/app/Models/CreditInvitation.php +++ b/app/Models/CreditInvitation.php @@ -112,7 +112,14 @@ class CreditInvitation extends BaseModel { return $this->belongsTo(Credit::class)->withTrashed(); } - + + /** + * @return mixed + */ + public function entity() + { + return $this->belongsTo(Credit::class)->withTrashed(); + } /** * @return mixed */ diff --git a/app/Models/InvoiceInvitation.php b/app/Models/InvoiceInvitation.php index c25403e56c69..20390c2a06fb 100644 --- a/app/Models/InvoiceInvitation.php +++ b/app/Models/InvoiceInvitation.php @@ -115,6 +115,14 @@ class InvoiceInvitation extends BaseModel return $this->belongsTo(Invoice::class)->withTrashed(); } + /** + * @return mixed + */ + public function entity() + { + return $this->belongsTo(Invoice::class)->withTrashed(); + } + /** * @return mixed */ diff --git a/app/Models/PurchaseOrderInvitation.php b/app/Models/PurchaseOrderInvitation.php index 8f22058d0712..eaba3a38f72b 100644 --- a/app/Models/PurchaseOrderInvitation.php +++ b/app/Models/PurchaseOrderInvitation.php @@ -110,6 +110,14 @@ class PurchaseOrderInvitation extends BaseModel return $this->belongsTo(PurchaseOrder::class)->withTrashed(); } + /** + * @return mixed + */ + public function entity() + { + return $this->belongsTo(PurchaseOrder::class)->withTrashed(); + } + /** * @return mixed */ diff --git a/app/Models/QuoteInvitation.php b/app/Models/QuoteInvitation.php index 6bfc589b76ae..f3b4199a9c3e 100644 --- a/app/Models/QuoteInvitation.php +++ b/app/Models/QuoteInvitation.php @@ -113,6 +113,14 @@ class QuoteInvitation extends BaseModel return $this->belongsTo(Quote::class)->withTrashed(); } + /** + * @return mixed + */ + public function entity() + { + return $this->belongsTo(Quote::class)->withTrashed(); + } + /** * @return mixed */ diff --git a/app/Models/RecurringInvoiceInvitation.php b/app/Models/RecurringInvoiceInvitation.php index 922b8ba6de74..01e2c088ce73 100644 --- a/app/Models/RecurringInvoiceInvitation.php +++ b/app/Models/RecurringInvoiceInvitation.php @@ -104,6 +104,14 @@ class RecurringInvoiceInvitation extends BaseModel return $this->belongsTo(RecurringInvoice::class)->withTrashed(); } + /** + * @return mixed + */ + public function entity() + { + return $this->belongsTo(RecurringInvoice::class)->withTrashed(); + } + /** * @return mixed */ diff --git a/app/Utils/Traits/Inviteable.php b/app/Utils/Traits/Inviteable.php index 5a841c3df800..b0a0aacd2134 100644 --- a/app/Utils/Traits/Inviteable.php +++ b/app/Utils/Traits/Inviteable.php @@ -141,11 +141,13 @@ trait Inviteable 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 { - return config('ninja.app_url')."/#/{$entity}/{$hash}/edit"; + $entity_type = Str::snake(class_basename($this->entityType())); + + return config('ninja.app_url')."/#/{$entity_type}/{$this->invoice->hashed_id}/edit"; } }