From 4af0482a93824589024347f59319227f97987a22 Mon Sep 17 00:00:00 2001 From: Adrian Hopek Date: Fri, 8 Apr 2022 08:12:41 +0200 Subject: [PATCH] #112 - change content of emails (#114) * #112 - change content of emails * #112 - wip --- ...ionRequestWaitsForApprovalNotification.php | 46 +++++++++++++++---- app/Eloquent/Models/User.php | 1 + resources/lang/pl.json | 6 ++- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php b/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php index 4e9199c..3c88384 100644 --- a/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php +++ b/app/Domain/Notifications/VacationRequestWaitsForApprovalNotification.php @@ -8,6 +8,7 @@ use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; use InvalidArgumentException; +use Toby\Domain\States\VacationRequest\WaitingForTechnical; use Toby\Eloquent\Models\User; use Toby\Eloquent\Models\VacationRequest; @@ -43,8 +44,6 @@ class VacationRequestWaitsForApprovalNotification extends Notification protected function buildMailMessage(string $url): MailMessage { $user = $this->user->first_name; - $requester = $this->vacationRequest->user->fullName; - $title = $this->vacationRequest->name; $type = $this->vacationRequest->type->label(); $from = $this->vacationRequest->from->toDisplayString(); $to = $this->vacationRequest->to->toDisplayString(); @@ -54,13 +53,8 @@ class VacationRequestWaitsForApprovalNotification extends Notification ->greeting(__("Hi :user!", [ "user" => $user, ])) - ->subject(__("Vacation request :title is waiting for your approval", [ - "title" => $title, - ])) - ->line(__("The vacation request :title from user: :requester is waiting for your approval.", [ - "title" => $title, - "requester" => $requester, - ])) + ->subject($this->buildSubject()) + ->line($this->buildDescription()) ->line(__("Vacation type: :type", [ "type" => $type, ])) @@ -71,4 +65,38 @@ class VacationRequestWaitsForApprovalNotification extends Notification ])) ->action(__("Click here for details"), $url); } + + protected function buildSubject(): string + { + $title = $this->vacationRequest->name; + + if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) { + return __("Vacation request :title is waiting for your technical approval", [ + "title" => $title, + ]); + } + + return __("Vacation request :title is waiting for your administrative approval", [ + "title" => $title, + ]); + } + + protected function buildDescription(): string + { + $title = $this->vacationRequest->name; + $requester = $this->vacationRequest->user->fullName; + + if ($this->vacationRequest->state->equals(WaitingForTechnical::class)) { + return __("The vacation request :title from user :requester is waiting for your technical approval.", [ + "title" => $title, + "requester" => $requester, + ]); + } + + return __("The vacation request :title from user :requester is waiting for your administrative approval.", [ + "title" => $title, + "requester" => $requester, + ]); + } } + diff --git a/app/Eloquent/Models/User.php b/app/Eloquent/Models/User.php index 7aab139..1cab08a 100644 --- a/app/Eloquent/Models/User.php +++ b/app/Eloquent/Models/User.php @@ -23,6 +23,7 @@ use Toby\Eloquent\Helpers\ColorGenerator; * @property string $first_name * @property string $last_name * @property string $email + * @property string $password * @property string $avatar * @property string $position * @property Role $role diff --git a/resources/lang/pl.json b/resources/lang/pl.json index ccb2c3d..2c04418 100644 --- a/resources/lang/pl.json +++ b/resources/lang/pl.json @@ -59,8 +59,10 @@ "Vacation type: :type": "Rodzaj wniosku: :type", "From :from to :to (number of days: :days)": "Od :from do :to (liczba dni: :days)", "Click here for details": "Kliknij, aby zobaczyć szczegóły", - "Vacation request :title is waiting for your approval": "Wniosek urlopowy :title czeka na zaakceptowanie", - "The vacation request :title from user: :requester is waiting for your approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację.", + "Vacation request :title is waiting for your technical approval": "Wniosek urlopowy :title czeka na akceptacje techniczną", + "Vacation request :title is waiting for your administrative approval": "Wniosek urlopowy :title czeka na akceptacje administracyjną", + "The vacation request :title from user :requester is waiting for your technical approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację techniczną.", + "The vacation request :title from user :requester is waiting for your administrative approval.": "Wniosek urlopowy :title od użytkownika :requester czeka na Twoją akceptację administracyjną.", "Vacation request :title has been :status": "Wniosek urlopowy :title został :status", "The vacation request :title for user :requester has been :status.": "Wniosek urlopowy :title od użytkownika :requester został :status.", "Vacation request :title has been created on your behalf": "Wniosek urlopowy :title został utworzony w Twoim imieniu",