Add ticket create notification event support
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Actions\Notifications;
|
||||
|
||||
use App\Enums\NotificationEventType;
|
||||
use App\Models\Project;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\TicketStatus;
|
||||
use App\Models\User;
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
class BuildTicketCreatedPayload
|
||||
{
|
||||
public function handle(
|
||||
Project $project,
|
||||
Ticket $ticket,
|
||||
TicketStatus $ticketStatus,
|
||||
?User $actor,
|
||||
CarbonImmutable $occurredAt,
|
||||
): TicketStatusChangedPayload {
|
||||
return new TicketStatusChangedPayload(
|
||||
eventType: NotificationEventType::TicketCreate,
|
||||
projectId: $project->id,
|
||||
projectKey: $project->key,
|
||||
projectName: $project->name,
|
||||
ticketId: $ticket->id,
|
||||
ticketKey: $ticket->ticket_key,
|
||||
ticketTitle: $ticket->title,
|
||||
ticketUrl: route('projects.tickets.show', [$project, $ticket]),
|
||||
actorId: $actor?->id,
|
||||
actorName: $actor?->name,
|
||||
fromStatusId: null,
|
||||
fromStatusLabel: null,
|
||||
toStatusId: $ticketStatus->id,
|
||||
toStatusLabel: $this->statusLabel($ticketStatus),
|
||||
occurredAt: $occurredAt,
|
||||
);
|
||||
}
|
||||
|
||||
private function statusLabel(TicketStatus $ticketStatus): string
|
||||
{
|
||||
$ticketStatus->loadMissing('boardColumn');
|
||||
|
||||
if ($ticketStatus->boardColumn === null || $ticketStatus->boardColumn->name === $ticketStatus->name) {
|
||||
return $ticketStatus->name;
|
||||
}
|
||||
|
||||
return "{$ticketStatus->boardColumn->name} / {$ticketStatus->name}";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user