-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Orders): Switch to using Laravel notifcations to display mes…
…sages to assigned approver for order accounts pending approval
- Loading branch information
Patrick Mulligan
committed
Apr 11, 2024
1 parent
1189cbe
commit 415500c
Showing
7 changed files
with
133 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace App\Modules\Orders\Events; | ||
|
||
use App\Modules\Orders\Models\Account; | ||
|
||
class NotifyApprover | ||
{ | ||
/** | ||
* @var Account | ||
*/ | ||
public $account; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param Account $account | ||
* @return void | ||
*/ | ||
public function __construct(Account $account) | ||
{ | ||
$this->account = $account; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Modules\Orders\Listeners; | ||
|
||
use Illuminate\Events\Dispatcher; | ||
use App\Modules\Orders\Events\NotifyApprover; | ||
use App\Modules\Orders\Models\Account; | ||
use App\Modules\Orders\Notifications\AccountApprovalNeeded; | ||
|
||
/** | ||
* Account listener | ||
*/ | ||
class NotifyAccountApprover | ||
{ | ||
/** | ||
* Register the listeners for the subscriber. | ||
* | ||
* @param Dispatcher $events | ||
* @return void | ||
*/ | ||
public function subscribe(Dispatcher $events): void | ||
{ | ||
$events->listen(NotifyApprover::class, self::class . '@handleAccountCreated'); | ||
} | ||
|
||
/** | ||
* Plugin that loads module positions within content | ||
* | ||
* @param GroupReading $event | ||
* @return void | ||
*/ | ||
public function handleAccountCreated(NotifyApprover $event): void | ||
{ | ||
$account = $event->account; | ||
$account->approver->notify(new AccountApprovalNeeded($event->account)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/Modules/Orders/Notifications/AccountApprovalNeeded.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace App\Modules\Orders\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Contracts\Queue\ShouldQueue; | ||
use Illuminate\Notifications\Notification; | ||
use App\Modules\Orders\Models\Account; | ||
|
||
class AccountApprovalNeeded extends Notification | ||
{ | ||
use Queueable; | ||
|
||
/** | ||
* The user request | ||
* | ||
* @var Account $account | ||
*/ | ||
private $account; | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param UserRequest $userrequest | ||
* @return void | ||
*/ | ||
public function __construct(Account $account) | ||
{ | ||
$this->account = $account; | ||
} | ||
|
||
/** | ||
* What methods can this notificaiton be sent | ||
* | ||
* @param object $notifiable | ||
* @return array<int,string> | ||
*/ | ||
public function via($notifiable) | ||
{ | ||
return ['database']; | ||
} | ||
|
||
/** | ||
* Generate a message formatted for database | ||
* | ||
* @param object $notifiable | ||
* @return array<string,string> | ||
*/ | ||
public function toArray($notifiable) | ||
{ | ||
$title = trans('orders::orders.orders'); | ||
|
||
$account = $this->account->purchasewbse; | ||
$account = $account ?: $this->account->purchaseio; | ||
|
||
$content = '<a href="' . route('site.orders.read', ['id' => $this->account->orderid]) . '">'; | ||
$content .= trans('orders::orders.purchase account waiting approval', ['order' => $this->account->orderid, 'account' => $account]); | ||
$content .= '</a>'; | ||
|
||
return [ | ||
'title' => $title, | ||
'data' => $content | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters