Refactor for admin links

This commit is contained in:
David Bomba 2023-06-07 13:53:38 +10:00
parent 23a88f5a99
commit c3189183a5
12 changed files with 71 additions and 11 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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;

View File

@ -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');

View File

@ -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(),

View File

@ -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

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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
*/

View File

@ -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";
}
}