Files
Toiminnanohjaus/app/Modules/Jobs/Presentation/Livewire/⚡task-form.blade.php
T
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

246 lines
9.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
use App\Modules\Jobs\Application\Contracts\TaskQueries;
use App\Modules\Jobs\Application\DTOs\NamedId;
use App\Modules\Jobs\Application\UseCases\AddTask;
use App\Modules\Jobs\Application\UseCases\UpdateTask;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Jobs\Presentation\Livewire\Forms\TaskForm;
use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\Users\Application\Contracts\UserAccountQueries;
use App\Modules\Users\Domain\Enums\Role;
use Carbon\CarbonImmutable;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Component;
/**
* Add page (no {task}) and edit page (with {task}) of a job's task.
*/
new class extends Component
{
#[Locked]
public int $jobId;
#[Locked]
public ?int $taskId = null;
#[Locked]
public string $jobTitle = '';
/** @var list<int> */
#[Locked]
public array $serviceUnitIds = [];
/**
* The task's work type when editing, offered even if taken out of use.
*/
#[Locked]
public ?int $storedWorkTypeId = null;
public TaskForm $form;
public function mount(CustomerJobQueries $jobQueries, TaskQueries $taskQueries, int $job, ?int $task = null): void
{
$details = $jobQueries->findDetails($job);
abort_if($details === null, 404);
$this->authorize('jobs.manage-tasks', $details->id);
$this->jobId = $details->id;
$this->jobTitle = $details->number.' '.$details->name;
$this->serviceUnitIds = array_map(fn (NamedId $unit): int => $unit->id, $details->serviceUnits);
if ($task === null) {
abort_unless($details->status->allowsTasks(), 404);
$this->form->assignee_user_id = (string) auth()->id();
return;
}
$summary = $taskQueries->findTask($details->id, $task);
abort_if($summary === null, 404);
$this->taskId = $summary->id;
$this->storedWorkTypeId = $summary->workType->id;
$this->form->fillFromSummary($summary);
}
/**
* Work types of the job's service units and the shared ones, grouped
* as "Unit – Service" for <optgroup>.
*
* @return array<string, list<array{id: int, name: string}>>
*/
#[Computed]
public function workTypeGroups(): array
{
$catalog = app(CatalogQueries::class);
$groups = [];
$seen = [];
foreach ($catalog->activeWorkTypesFor($this->serviceUnitIds) as $node) {
if ($node->workTypes !== []) {
$groups[$node->serviceUnit->name] = array_map(fn ($workType): array => ['id' => $workType->id, 'name' => $workType->name], $node->workTypes);
}
foreach ($node->services as $serviceNode) {
if ($serviceNode->workTypes !== []) {
$groups[$node->serviceUnit->name.' – '.$serviceNode->service->name] = array_map(fn ($workType): array => ['id' => $workType->id, 'name' => $workType->name], $serviceNode->workTypes);
}
}
}
foreach ($groups as $group) {
foreach ($group as $workType) {
$seen[$workType['id']] = true;
}
}
if ($this->storedWorkTypeId !== null && ! isset($seen[$this->storedWorkTypeId]) && ($stored = $catalog->findWorkType($this->storedWorkTypeId)) !== null) {
$groups[__('catalog.inactive')] = [['id' => $stored->id, 'name' => $stored->name]];
}
return $groups;
}
/**
* @return list<array{value: int, label: string, note: ?string}>
*/
#[Computed]
public function userOptions(): array
{
return array_map(fn ($user): array => [
'value' => $user->id,
'label' => $user->name,
'note' => $user->role === Role::Subcontractor ? __('users.roles.subcontractor') : null,
], app(UserAccountQueries::class)->activeUserOptions());
}
public function save(AddTask $addTask, UpdateTask $updateTask): void
{
$this->authorize('jobs.manage-tasks', $this->jobId);
$data = $this->form->toData();
try {
if ($this->taskId === null) {
$taskId = $addTask->execute($this->jobId, $data, (int) auth()->id());
$message = __('jobs.tasks.created', ['title' => trim($data->title)]);
} else {
$taskId = $this->taskId;
$updateTask->execute($this->jobId, $taskId, $data, (int) auth()->id());
$message = __('jobs.tasks.updated', ['title' => trim($data->title)]);
}
} catch (CustomerJobNotFound|TaskNotFound) {
abort(404);
} catch (DomainException $exception) {
$this->form->showDomainError($exception);
return;
}
$plannedTo = app(TaskQueries::class)->findTask($this->jobId, $taskId)?->plannedTo;
if ($data->plannedFrom !== null && $plannedTo !== null && $plannedTo !== ($data->plannedTo ?? $data->plannedFrom)) {
$message .= ' '.__('jobs.tasks.extended', ['to' => CarbonImmutable::parse($plannedTo)->format('j.n.Y')]);
}
session()->flash('status', $message);
$this->redirect(route('jobs.show', $this->jobId).'#tasks', navigate: true);
}
public function heading(): string
{
return __($this->taskId === null ? 'jobs.tasks.create_title' : 'jobs.tasks.edit_title');
}
public function render(): mixed
{
return $this->view()->title($this->heading().' – '.$this->jobTitle);
}
};
?>
<div class="mx-auto max-w-2xl space-y-6 p-4 sm:p-6">
<div class="space-y-1">
<x-page-title icon="clipboard-document-list">{{ $this->heading() }}</x-page-title>
<p class="text-sm text-zinc-600 dark:text-zinc-300">
{{ __('jobs.tasks.job_label') }}:
<x-link :href="route('jobs.show', $jobId)" navigate>{{ $jobTitle }}</x-link>
</p>
</div>
<form wire:submit="save" class="card space-y-6" novalidate>
<x-input wire:model="form.title" :label="__('jobs.tasks.fields.title')" autocomplete="off" required />
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
<x-select.native wire:model="form.work_type_id" :label="__('jobs.tasks.fields.work_type')" :aria-label="__('jobs.tasks.fields.work_type')" :hint="__('jobs.tasks.fields.work_type_description')" required>
<option value="">{{ __('jobs.fields.none_selected') }}</option>
@foreach ($this->workTypeGroups as $group => $workTypes)
<optgroup label="{{ $group }}">
@foreach ($workTypes as $workType)
<option value="{{ $workType['id'] }}">{{ $workType['name'] }}</option>
@endforeach
</optgroup>
@endforeach
</x-select.native>
<x-select.native wire:model="form.assignee_user_id" :label="__('jobs.tasks.fields.assignee')" :aria-label="__('jobs.tasks.fields.assignee')" :hint="__('jobs.tasks.fields.assignee_hint')">
<option value="">{{ __('jobs.calendar.no_assignee') }}</option>
@foreach ($this->userOptions as $user)
<option value="{{ $user['value'] }}">{{ $user['note'] === null ? $user['label'] : $user['label'].' ('.$user['note'].')' }}</option>
@endforeach
</x-select.native>
<x-checkbox-group
:legend="__('jobs.tasks.fields.members')"
model="form.member_user_ids"
:options="$this->userOptions"
:hint="__('jobs.tasks.fields.members_hint')"
/>
<div class="grid gap-6 sm:grid-cols-3">
<x-select.native wire:model="form.status" :label="__('jobs.tasks.fields.status')" :aria-label="__('jobs.tasks.fields.status')">
@foreach (TaskStatus::cases() as $status)
<option value="{{ $status->value }}">{{ __('jobs.tasks.statuses.'.$status->value) }}</option>
@endforeach
</x-select.native>
<x-input wire:model="form.due_on" type="date" :label="__('jobs.tasks.fields.due_on')" />
<x-input
wire:model="form.estimated_hours"
type="number"
step="0.25"
min="0"
inputmode="decimal"
:label="__('jobs.tasks.fields.estimated_hours')"
/>
</div>
<fieldset class="space-y-2">
<legend class="text-sm font-semibold">{{ __('jobs.tasks.schedule') }}</legend>
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.fields.planned_hint') }}</p>
<div class="grid gap-6 sm:grid-cols-2">
<x-input wire:model="form.planned_from" type="date" :label="__('jobs.tasks.fields.planned_from')" />
<x-input wire:model="form.planned_to" type="date" :label="__('jobs.tasks.fields.planned_to')" />
</div>
</fieldset>
<x-textarea wire:model="form.description" :label="__('jobs.tasks.fields.description')" resize-auto />
<div class="flex flex-wrap gap-3">
<x-button submit :text="__('jobs.save')" />
<x-button :href="route('jobs.show', $jobId).'#tasks'" wire:navigate subtle color="black" :text="__('jobs.cancel')" />
</div>
</form>
</div>