- actions and notifications refactor (#88)

* wip

* fix

* fix

* fix

* add test

* fix

* wip

* fix

* fix translations

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
Adrian Hopek
2022-03-21 15:29:20 +01:00
committed by GitHub
parent d8ac2bd61f
commit 95f5ed44d6
47 changed files with 537 additions and 1014 deletions

View File

@@ -40,24 +40,17 @@ class VacationRequestCreatedNotification extends Notification
protected function buildMailMessage(string $url): MailMessage
{
$user = $this->vacationRequest->user->first_name;
$title = $this->vacationRequest->name;
$type = $this->vacationRequest->type->label();
$from = $this->vacationRequest->from->toDisplayString();
$to = $this->vacationRequest->to->toDisplayString();
$days = $this->vacationRequest->vacations()->count();
$appName = config("app.name");
return (new MailMessage())
->greeting(__("Hi :user!", [
"user" => $user,
]))
->subject(__("Vacation request :title has been created", [
"title" => $title,
]))
->line(__("The vacation request :title has been created correctly in the :appName.", [
"title" => $title,
"appName" => $appName,
]))
->subject($this->buildSubject())
->line($this->buildDescription())
->line(__("Vacation type: :type", [
"type" => $type,
]))
@@ -68,4 +61,38 @@ class VacationRequestCreatedNotification extends Notification
]))
->action(__("Click here for details"), $url);
}
protected function buildSubject(): string
{
$name = $this->vacationRequest->name;
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
return __("Vacation request :title has been created", [
"title" => $name,
]);
}
return __("Vacation request :title has been created on your behalf", [
"title" => $name,
]);
}
protected function buildDescription(): string
{
$name = $this->vacationRequest->name;
$appName = config("app.name");
if ($this->vacationRequest->creator()->is($this->vacationRequest->user)) {
return __("The vacation request :title has been created correctly in the :appName.", [
"title" => $name,
"appName" => $appName,
]);
}
return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
"title" => $this->vacationRequest->name,
"appName" => $appName,
"creator" => $this->vacationRequest->creator->fullName,
]);
}
}