* wip * wip * wip * wip * fix * wip * wip * fix * fix * cs fix * #116 - fix * #116 - changed home-office icon * Apply suggestions from code review Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> * #116 - cr fix * #116 - cs fix * #116 - cs fix * Apply suggestions from code review Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com> * #5 - bump codestyle Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl> Co-authored-by: Krzysztof Rewak <krzysztof.rewak@gmail.com> Co-authored-by: Ewelina Lasowy <56546832+EwelinaLasowy@users.noreply.github.com>
This commit is contained in:
11
app/Domain/Notifications/Channels.php
Normal file
11
app/Domain/Notifications/Channels.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
class Channels
|
||||
{
|
||||
public const MAIL = "mail";
|
||||
public const SLACK = "slack";
|
||||
}
|
42
app/Domain/Notifications/KeyHasBeenGivenNotification.php
Normal file
42
app/Domain/Notifications/KeyHasBeenGivenNotification.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class KeyHasBeenGivenNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected User $sender,
|
||||
protected User $recipient,
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return [Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(Notifiable $notifiable): string
|
||||
{
|
||||
return __(":sender gives key no :key to :recipient", [
|
||||
"sender" => $this->getName($this->sender),
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
"key" => $notifiable->id,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getName(User $user): string
|
||||
{
|
||||
if ($user->profile->slack_id !== null) {
|
||||
return "<@{$user->profile->slack_id}>";
|
||||
}
|
||||
|
||||
return $user->profile->full_name;
|
||||
}
|
||||
}
|
42
app/Domain/Notifications/KeyHasBeenTakenNotification.php
Normal file
42
app/Domain/Notifications/KeyHasBeenTakenNotification.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Notifications\Notification;
|
||||
use Toby\Eloquent\Models\User;
|
||||
|
||||
class KeyHasBeenTakenNotification extends Notification
|
||||
{
|
||||
use Queueable;
|
||||
|
||||
public function __construct(
|
||||
protected User $recipient,
|
||||
protected User $sender,
|
||||
) {}
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return [Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(Notifiable $notifiable): string
|
||||
{
|
||||
return __(":recipient takes key no :key from :sender", [
|
||||
"recipient" => $this->getName($this->recipient),
|
||||
"sender" => $this->getName($this->sender),
|
||||
"key" => $notifiable->id,
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getName(User $user): string
|
||||
{
|
||||
if ($user->profile->slack_id !== null) {
|
||||
return "<@{$user->profile->slack_id}>";
|
||||
}
|
||||
|
||||
return $user->profile->full_name;
|
||||
}
|
||||
}
|
10
app/Domain/Notifications/Notifiable.php
Normal file
10
app/Domain/Notifications/Notifiable.php
Normal file
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Toby\Domain\Notifications;
|
||||
|
||||
interface Notifiable
|
||||
{
|
||||
public function notify($instance);
|
||||
}
|
@@ -20,7 +20,17 @@ class VacationRequestCreatedNotification extends Notification
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): string
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return implode("\n", [
|
||||
$this->buildDescription(),
|
||||
"<${url}|Zobacz szczegóły>",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -80,18 +90,16 @@ class VacationRequestCreatedNotification extends Notification
|
||||
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.", [
|
||||
return __("The vacation request :title from user :user has been created successfully.", [
|
||||
"user" => $this->vacationRequest->user->profile->full_name,
|
||||
"title" => $name,
|
||||
"appName" => $appName,
|
||||
]);
|
||||
}
|
||||
|
||||
return __("The vacation request :title has been created correctly by user :creator on your behalf in the :appName.", [
|
||||
return __("The vacation request :title has been created successfully by user :creator on your behalf.", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"appName" => $appName,
|
||||
"creator" => $this->vacationRequest->creator->profile->full_name,
|
||||
]);
|
||||
}
|
||||
|
@@ -22,7 +22,17 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): string
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return implode("\n", [
|
||||
$this->buildDescription(),
|
||||
"<${url}|Zobacz szczegóły>",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -43,27 +53,17 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
protected function buildMailMessage(string $url): MailMessage
|
||||
{
|
||||
$user = $this->user->profile->first_name;
|
||||
$title = $this->vacationRequest->name;
|
||||
$type = $this->vacationRequest->type->label();
|
||||
$status = $this->vacationRequest->state->label();
|
||||
$from = $this->vacationRequest->from->toDisplayString();
|
||||
$to = $this->vacationRequest->to->toDisplayString();
|
||||
$days = $this->vacationRequest->vacations()->count();
|
||||
$requester = $this->vacationRequest->user->profile->full_name;
|
||||
|
||||
return (new MailMessage())
|
||||
->greeting(__("Hi :user!", [
|
||||
"user" => $user,
|
||||
]))
|
||||
->subject(__("Vacation request :title has been :status", [
|
||||
"title" => $title,
|
||||
"status" => $status,
|
||||
]))
|
||||
->line(__("The vacation request :title from user :requester has been :status.", [
|
||||
"title" => $title,
|
||||
"requester" => $requester,
|
||||
"status" => $status,
|
||||
]))
|
||||
->subject($this->buildSubject())
|
||||
->line($this->buildDescription())
|
||||
->line(__("Vacation type: :type", [
|
||||
"type" => $type,
|
||||
]))
|
||||
@@ -74,4 +74,21 @@ class VacationRequestStatusChangedNotification extends Notification
|
||||
]))
|
||||
->action(__("Click here for details"), $url);
|
||||
}
|
||||
|
||||
protected function buildSubject(): string
|
||||
{
|
||||
return __("Vacation request :title has been :status", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"status" => $this->vacationRequest->state->label(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function buildDescription(): string
|
||||
{
|
||||
return __("The vacation request :title from user :requester has been :status.", [
|
||||
"title" => $this->vacationRequest->name,
|
||||
"requester" => $this->vacationRequest->user->profile->full_name,
|
||||
"status" => $this->vacationRequest->state->label(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@@ -23,7 +23,17 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
|
||||
public function via(): array
|
||||
{
|
||||
return ["mail"];
|
||||
return [Channels::MAIL, Channels::SLACK];
|
||||
}
|
||||
|
||||
public function toSlack(): string
|
||||
{
|
||||
$url = route("vacation.requests.show", ["vacationRequest" => $this->vacationRequest->id]);
|
||||
|
||||
return implode("\n", [
|
||||
$this->buildDescription(),
|
||||
"<${url}|Zobacz szczegóły>",
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,4 +109,3 @@ class VacationRequestWaitsForApprovalNotification extends Notification
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user