-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #323 - threadable emails * - csf * - cleaning up
- Loading branch information
1 parent
912ad27
commit 171d1f3
Showing
13 changed files
with
125 additions
and
266 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
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,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Domain\Notifications; | ||
|
||
class VacationRequestEmailTitle | ||
{ | ||
public static function get(string $title): string | ||
{ | ||
return __("Request :title in :application", [ | ||
"title" => $title, | ||
"application" => config("app.name"), | ||
]); | ||
} | ||
} |
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,94 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Toby\Domain\Notifications; | ||
|
||
use Illuminate\Bus\Queueable; | ||
use Illuminate\Notifications\Messages\MailMessage; | ||
use InvalidArgumentException; | ||
use Toby\Eloquent\Models\User; | ||
use Toby\Eloquent\Models\VacationRequest; | ||
use Toby\Infrastructure\Slack\Elements\SlackMessage; | ||
|
||
abstract class VacationRequestNotification extends QueuedNotification | ||
{ | ||
use Queueable; | ||
|
||
public function __construct( | ||
protected VacationRequest $vacationRequest, | ||
protected User $user, | ||
) { | ||
parent::__construct(); | ||
} | ||
|
||
public function via(): array | ||
{ | ||
return [Channels::MAIL, Channels::SLACK]; | ||
} | ||
|
||
public function toSlack(): SlackMessage | ||
{ | ||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]); | ||
$seeDetails = __("See details"); | ||
|
||
return (new SlackMessage()) | ||
->text("{$this->buildDescription()}\n <{$url}|{$seeDetails}>"); | ||
} | ||
|
||
/** | ||
* @throws InvalidArgumentException | ||
*/ | ||
public function toMail(): MailMessage | ||
{ | ||
$url = route( | ||
"vacation.requests.show", | ||
[ | ||
"vacationRequest" => $this->vacationRequest, | ||
], | ||
); | ||
|
||
return $this->buildMailMessage($url); | ||
} | ||
|
||
protected function buildMailMessage(string $url): MailMessage | ||
{ | ||
$user = $this->user->profile->first_name; | ||
$type = $this->vacationRequest->type->label(); | ||
$from = $this->vacationRequest->from; | ||
$to = $this->vacationRequest->to; | ||
$days = $this->vacationRequest->vacations()->count(); | ||
|
||
$date = $from->equalTo($to) | ||
? "{$from->toDisplayString()}" | ||
: "{$from->toDisplayString()} - {$to->toDisplayString()}"; | ||
|
||
return (new MailMessage()) | ||
->greeting( | ||
__("Hi :user!", [ | ||
"user" => $user, | ||
]), | ||
) | ||
->subject($this->buildSubject()) | ||
->line($this->buildDescription()) | ||
->line( | ||
__("Request type: :type", [ | ||
"type" => $type, | ||
]), | ||
) | ||
->line( | ||
__("Date: :date (number of days: :days)", [ | ||
"date" => $date, | ||
"days" => $days, | ||
]), | ||
) | ||
->action(__("Click here for details"), $url); | ||
} | ||
|
||
protected function buildSubject(): string | ||
{ | ||
return VacationRequestEmailTitle::get($this->vacationRequest->name); | ||
} | ||
|
||
abstract protected function buildDescription(): string; | ||
} |
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
Oops, something went wrong.