Add notifications: header bell, task start run and assignment notices

A new Notifications module shows a bell beside the profile menu with the
number of unseen notifications and a panel of the last 7 days; opening
it marks them seen, and each notification links to its job or task.

- A daily run at 14.00 (notifications:task-starts) tells the assignee
  and members of tasks that start by the next working day, skipping
  holidays and days off, done tasks and archived jobs.
- Jobs publishes PeopleAddedToTask and PeopleAddedToJob when someone
  else makes a user a task's assignee or member or gives them a role on
  a job; those users are notified at once. UpdateTask and ScheduleTask
  now take the acting user.
- A notification link to #task-<id> opens that task card on the job page.

Also: simplifying job fields per service unit (K31) moves to the end of
phase 4, and the workflow template browser test waits for Livewire's
progress bar before its last accessibility check.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
2026-11-25 08:28:01 +02:00
co-authored by Claude Sonnet 5.5
parent ae8172898d
commit f906f9a43f
48 changed files with 1665 additions and 31 deletions
@@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
namespace App\Modules\Notifications\Domain\Contracts;
use App\Modules\Notifications\Domain\ValueObjects\NewNotification;
use DateTimeImmutable;
interface NotificationRepository
{
/**
* Adds the notification unless one with the same dedupe key exists.
*
* @return bool Whether it was added.
*/
public function addIfNew(NewNotification $notification): bool;
/**
* Marks the user's unseen notifications seen.
*/
public function markSeen(int $userId, DateTimeImmutable $at): void;
public function deleteOlderThan(DateTimeImmutable $moment): void;
}
@@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace App\Modules\Notifications\Domain\Enums;
/**
* What a notification tells about; its text is
* `notifications.types.<value>` with the notification's parameters.
*/
enum NotificationType: string
{
/**
* A task the user does or is a member of starts on the next working day.
*/
case TaskStartsSoon = 'task_starts_soon';
/**
* Someone else made the user a task's assignee or member.
*/
case TaskAssigned = 'task_assigned';
/**
* Someone else gave the user a role on a customer job.
*/
case JobAssigned = 'job_assigned';
}
@@ -0,0 +1,44 @@
<?php
declare(strict_types=1);
namespace App\Modules\Notifications\Domain\ValueObjects;
use App\Modules\Notifications\Domain\Enums\NotificationType;
use DateTimeImmutable;
/**
* A notification to add for a user, once per dedupe key.
*/
final readonly class NewNotification
{
/**
* @param array<string, int|string> $params
*/
public function __construct(
public int $userId,
public NotificationType $type,
public array $params,
public string $dedupeKey,
public DateTimeImmutable $createdAt,
) {}
/**
* @param array<string, int|string> $params
*/
public static function taskStartsSoon(int $userId, int $taskId, string $startsOn, array $params, DateTimeImmutable $at): self
{
return new self($userId, NotificationType::TaskStartsSoon, $params, "task_starts:{$taskId}:{$startsOn}:{$userId}", $at);
}
/**
* Each assignment is its own notification: one removed and added again
* is told again.
*
* @param array<string, int|string> $params
*/
public static function assigned(NotificationType $type, int $userId, int $subjectId, array $params, DateTimeImmutable $at): self
{
return new self($userId, $type, $params, "{$type->value}:{$subjectId}:{$userId}:".$at->format('U.u').':'.bin2hex(random_bytes(4)), $at);
}
}