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,82 @@
<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Domain\Events;
use App\Modules\Jobs\Domain\Entities\CustomerJob;
use App\Modules\Jobs\Domain\ValueObjects\JobDetails;
/**
* Someone got a role on a customer job: responsible person, contact
* person, biller or member. Published after the change is saved, for
* notifying them (not the one who made it).
*/
final readonly class PeopleAddedToJob
{
public const string RESPONSIBLE = 'responsible';
public const string CONTACT = 'contact';
public const string BILLER = 'biller';
public const string MEMBER = 'member';
/**
* @param array<int, list<string>> $newRoles The new roles by user id.
*/
public function __construct(
public int $jobId,
public string $jobNumber,
public string $jobName,
public array $newRoles,
public int $actorUserId,
) {}
/**
* The roles the saved job gives that the details before did not (a new
* job has none before); null when nobody got a new role.
*/
public static function between(?JobDetails $before, CustomerJob $after, int $actorUserId): ?self
{
$old = $before === null ? [] : self::rolesOf($before);
$newRoles = [];
foreach (self::rolesOf($after->details()) as $userId => $roles) {
$added = array_values(array_diff($roles, $old[$userId] ?? []));
if ($added !== []) {
$newRoles[$userId] = $added;
}
}
if ($newRoles === []) {
return null;
}
return new self((int) $after->id(), $after->number()->format(), $after->details()->name->value, $newRoles, $actorUserId);
}
/**
* @return array<int, list<string>>
*/
private static function rolesOf(JobDetails $details): array
{
$roles = [];
$roles[$details->responsibleUserId][] = self::RESPONSIBLE;
if ($details->contactUserId !== null) {
$roles[$details->contactUserId][] = self::CONTACT;
}
if ($details->billerUserId !== null) {
$roles[$details->billerUserId][] = self::BILLER;
}
foreach ($details->memberUserIds as $memberId) {
$roles[$memberId][] = self::MEMBER;
}
return $roles;
}
}
@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace App\Modules\Jobs\Domain\Events;
use App\Modules\Jobs\Domain\Entities\CustomerJob;
use App\Modules\Jobs\Domain\Entities\Task;
/**
* Someone became a task's assignee or one of its members. Published after
* the change is saved, for notifying them (not the one who made it).
*/
final readonly class PeopleAddedToTask
{
/**
* @param list<int> $newMemberIds
*/
public function __construct(
public int $taskId,
public string $taskTitle,
public int $jobId,
public string $jobNumber,
public string $jobName,
public ?int $newAssigneeId,
public array $newMemberIds,
public int $actorUserId,
) {}
/**
* The people the saved task has that it did not have before (a new task
* has none before); null when nobody was added.
*
* @param array{assignee: ?int, members: list<int>}|null $before
*/
public static function between(?array $before, Task $after, CustomerJob $job, int $actorUserId): ?self
{
$assignee = $after->assigneeUserId();
$newAssignee = $assignee !== null && $assignee !== ($before['assignee'] ?? null) ? $assignee : null;
$newMembers = array_values(array_diff($after->memberUserIds(), $before['members'] ?? [], $newAssignee === null ? [] : [$newAssignee]));
if ($newAssignee === null && $newMembers === []) {
return null;
}
return new self(
(int) $after->id(),
$after->title()->value,
$job->id() ?? $after->jobId(),
$job->number()->format(),
$job->details()->name->value,
$newAssignee,
$newMembers,
$actorUserId,
);
}
/**
* Who the task has now, to compare with after a change.
*
* @return array{assignee: ?int, members: list<int>}
*/
public static function peopleOf(Task $task): array
{
return ['assignee' => $task->assigneeUserId(), 'members' => $task->memberUserIds()];
}
}