Files
petriandClaude Opus 5.5 51b40b24fe Give the UI an indigo look with cards, status badges and empty states
- Dark indigo header and tinted page background; the mobile main menu gets
  its own row, in the same order as the keyboard reaches it.
- Page titles with an icon chip (x-page-title, x-page, x-page-header) and
  card sections (x-panel, the card utility); x-table styled as a card with
  an indigo header row in AppServiceProvider::styleTables().
- Job and task statuses, late work, unapproved hours and stock states as
  badges with icon and text (x-status-badge, x-jobs.status,
  x-jobs.task-status), never colour alone.
- Empty lists as x-empty-state; dashboard quick link tiles, week hour bars
  and trend arrows; Kanban columns and task cards edged by status; calendar
  today column and bar accents; quick sale, reports and machine console
  restyled; signed-out pages show the app name.
- Focus rings use the primary colour in both themes (white in the header).
- Document the components in CLAUDE.md; test the status badges.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-29 10:53:10 +02:00

199 lines
8.4 KiB
PHP

<?php
use App\Modules\Notifications\Application\Contracts\NotificationQueries;
use App\Modules\Notifications\Application\DTOs\NotificationSummary;
use App\Modules\Notifications\Application\UseCases\MarkNotificationsSeen;
use App\Modules\Notifications\Application\UseCases\NotifyTasksStartingSoon;
use App\Modules\Notifications\Domain\Enums\NotificationType;
use Carbon\CarbonImmutable;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* The signed-in user's notifications in the header: a bell with the number
* of unseen ones and a panel with those of the last 7 days. Opening the
* panel marks them seen; those that were new are marked "Uusi" until the
* page is left.
*/
new class extends Component
{
/**
* Notifications that were unseen when the panel was opened.
*
* @var list<int>
*/
#[Locked]
public array $newIds = [];
/**
* @return list<NotificationSummary>
*/
#[Computed]
public function notifications(): array
{
return app(NotificationQueries::class)->recentFor((int) auth()->id(), $this->since());
}
#[Computed]
public function unseenCount(): int
{
return app(NotificationQueries::class)->unseenCount((int) auth()->id(), $this->since());
}
public function open(MarkNotificationsSeen $markSeen): void
{
$unseen = array_values(array_map(
fn (NotificationSummary $notification): int => $notification->id,
array_filter($this->notifications, fn (NotificationSummary $notification): bool => ! $notification->seen),
));
if ($unseen === []) {
return;
}
$this->newIds = array_values(array_unique([...$this->newIds, ...$unseen]));
$markSeen->execute((int) auth()->id());
unset($this->notifications, $this->unseenCount);
}
public function text(NotificationSummary $notification): string
{
return match ($notification->type) {
NotificationType::TaskStartsSoon => __('notifications.types.task_starts_soon', [
'task' => (string) $notification->params['task_title'],
'number' => (string) $notification->params['job_number'],
'job' => (string) $notification->params['job_name'],
'date' => $this->formatDay((string) $notification->params['starts_on']),
]),
NotificationType::TaskAssigned => __('notifications.types.task_assigned.'.$notification->params['role'], [
'task' => (string) $notification->params['task_title'],
'number' => (string) $notification->params['job_number'],
'job' => (string) $notification->params['job_name'],
]),
NotificationType::JobAssigned => __('notifications.types.job_assigned', [
'number' => (string) $notification->params['job_number'],
'job' => (string) $notification->params['job_name'],
'roles' => $this->roleList((string) $notification->params['roles']),
]),
NotificationType::MaintenanceDue => __('notifications.types.maintenance_due.'.$notification->params['level'], [
'machine' => (string) $notification->params['machine'],
'item' => (string) $notification->params['item'],
]),
};
}
public function url(NotificationSummary $notification): string
{
return match ($notification->type) {
NotificationType::TaskStartsSoon, NotificationType::TaskAssigned => route('jobs.show', (int) $notification->params['job_id']).'#task-'.$notification->params['task_id'],
NotificationType::JobAssigned => route('jobs.show', (int) $notification->params['job_id']),
NotificationType::MaintenanceDue => route('machines.show', (int) $notification->params['machine_id']).'#maintenance-heading',
};
}
/**
* "vastuuhenkilöksi ja jäseneksi" from "responsible,member".
*/
private function roleList(string $roles): string
{
$names = array_map(fn (string $role): string => __('notifications.job_roles.'.$role), array_filter(explode(',', $roles)));
$last = array_pop($names);
return $names === [] ? (string) $last : implode(', ', $names).' '.__('notifications.and').' '.$last;
}
/**
* "25.11.2026 klo 14.05" from "2026-11-25 14:05".
*/
public function formatTime(string $moment): string
{
$time = CarbonImmutable::createFromFormat('Y-m-d H:i', $moment);
return __('notifications.at', ['date' => $time->format('j.n.Y'), 'time' => $time->format('H.i')]);
}
/**
* "ma 30.11.2026" from "2026-11-30".
*/
private function formatDay(string $date): string
{
$day = CarbonImmutable::createFromFormat('Y-m-d', $date);
return __('holidays.weekdays.'.$day->dayOfWeekIso).' '.$day->format('j.n.Y');
}
private function since(): DateTimeImmutable
{
return CarbonImmutable::now()->subDays(NotifyTasksStartingSoon::KEEP_DAYS)->toDateTimeImmutable();
}
};
?>
{{--
A disclosure like the profile menu (not role="menu"): the bell's name stays "Ilmoitukset", and the number of
unseen notifications is visible text that the button refers to with aria-describedby. Opening the panel marks
them seen. Escape, a click outside and moving focus out close it.
--}}
<div
class="relative"
x-data="{ open: false }"
x-on:keydown.escape="if (open) { open = false; $refs.trigger.focus() }"
x-on:click.outside="open = false"
x-on:focusout="if (open && $event.relatedTarget && ! $el.contains($event.relatedTarget)) open = false"
wire:poll.300s.visible
>
@php($count = $this->unseenCount)
<button
type="button"
x-ref="trigger"
x-on:click="open = ! open; if (open) $wire.open()"
x-bind:aria-expanded="open.toString()"
aria-expanded="false"
aria-controls="notifications-panel"
aria-describedby="notifications-count"
data-notifications-bell
class="relative flex min-h-9 items-center gap-1 rounded-md px-3 py-2 text-sm font-medium text-zinc-200 hover:bg-white/10 hover:text-white focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
>
<x-icon name="bell" class="size-5" aria-hidden="true" />
<span class="sr-only">{{ __('notifications.title') }}</span>
@if ($count > 0)
<span aria-hidden="true" class="min-w-5 rounded-full bg-red-700 px-1.5 text-center text-xs font-bold leading-5 text-white">{{ $count > 99 ? '99+' : $count }}</span>
@endif
</button>
<span id="notifications-count" class="sr-only">{{ trans_choice('notifications.unseen', $count, ['count' => $count]) }}</span>
<div
id="notifications-panel"
x-show="open"
x-cloak
class="z-40 mt-1 w-96 max-w-[calc(100vw-2rem)] rounded-md border border-white/15 bg-primary-950 p-4 text-sm text-zinc-100 shadow-lg sm:absolute sm:end-0"
>
{{-- Not a heading: the header comes before the page's h1. --}}
<p id="notifications-panel-title" class="mb-2 font-semibold">{{ __('notifications.recent') }}</p>
@if ($this->notifications === [])
<p class="text-zinc-300">{{ __('notifications.empty') }}</p>
@else
<ul aria-labelledby="notifications-panel-title" class="max-h-[60vh] space-y-1 overflow-y-auto">
@foreach ($this->notifications as $notification)
<li wire:key="notification-{{ $notification->id }}">
<a
href="{{ $this->url($notification) }}"
wire:navigate
class="block rounded-md px-2 py-2 hover:bg-white/10 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-white"
>
@if (in_array($notification->id, $newIds, true))
<span class="me-1 rounded bg-zinc-100 px-1.5 py-0.5 text-xs font-semibold text-zinc-900">{{ __('notifications.new') }}</span>
@endif
<span class="break-words">{{ $this->text($notification) }}</span>
<span class="mt-0.5 block text-xs text-zinc-300">{{ $this->formatTime($notification->createdAt) }}</span>
</a>
</li>
@endforeach
</ul>
@endif
</div>
</div>