Add tasks to customer jobs
Phase 1, item 7, in the Jobs module (tasks are part of a job, and my jobs needs their assignees): - Tasks with name, work type, assignees, status (waiting, in progress, in review, done), due date, estimated hours and description. - Tasks can be added once the job is a quote request or later, not to an archived job. The work type must belong to the job's service units or the shared ones and be in use; assignees must be active. What a task already has stays allowed after being taken out of use. - Job page: a Tehtävät section with a status select per task (announced, focus kept), edit links and delete with a confirmation dialog. Task form with work types grouped by unit and service. - Access: adding, changing and removing for everyone but subcontractors; subcontractors may change task statuses on jobs they are attached to. - Task assignees now count in my jobs (list, Kanban, job access). - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -4,9 +4,16 @@ use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
||||
use App\Modules\Jobs\Application\Contracts\TaskQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\JobChangeEntry;
|
||||
use App\Modules\Jobs\Application\DTOs\TaskSummary;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeTaskStatus;
|
||||
use App\Modules\Jobs\Application\UseCases\RemoveTask;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
@@ -19,6 +26,17 @@ new class extends Component
|
||||
#[Locked]
|
||||
public int $jobId;
|
||||
|
||||
/**
|
||||
* The task the remove dialog asks about.
|
||||
*/
|
||||
#[Locked]
|
||||
public ?int $removalTaskId = null;
|
||||
|
||||
#[Locked]
|
||||
public string $removalTaskTitle = '';
|
||||
|
||||
public string $taskStatusMessage = '';
|
||||
|
||||
public function mount(CustomerJobQueries $jobQueries, int $job): void
|
||||
{
|
||||
$this->authorize('jobs.view');
|
||||
@@ -45,6 +63,82 @@ new class extends Component
|
||||
return app(CustomerJobQueries::class)->changes($this->jobId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<TaskSummary>
|
||||
*/
|
||||
#[Computed]
|
||||
public function tasks(): array
|
||||
{
|
||||
return app(TaskQueries::class)->tasksOf($this->jobId);
|
||||
}
|
||||
|
||||
public function changeTaskStatus(int $taskId, string $status, ChangeTaskStatus $changeStatus): void
|
||||
{
|
||||
$this->authorize('jobs.update-task-status', $this->jobId);
|
||||
|
||||
$newStatus = TaskStatus::tryFrom($status);
|
||||
$task = app(TaskQueries::class)->findTask($this->jobId, $taskId);
|
||||
|
||||
if ($newStatus === null || $task === null) {
|
||||
$this->taskStatusMessage = __('jobs.tasks.not_found');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$changeStatus->execute($this->jobId, $taskId, $newStatus);
|
||||
} catch (TaskNotFound) {
|
||||
$this->taskStatusMessage = __('jobs.tasks.not_found');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->tasks);
|
||||
$this->taskStatusMessage = __('jobs.tasks.status_changed', ['title' => $task->title, 'status' => __('jobs.tasks.statuses.'.$newStatus->value)]);
|
||||
|
||||
// The list is re-ordered (done tasks last): keep focus on the same select.
|
||||
$this->js("document.getElementById('task-status-{$taskId}')?.focus()");
|
||||
}
|
||||
|
||||
public function confirmTaskRemoval(int $taskId): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||
|
||||
$task = app(TaskQueries::class)->findTask($this->jobId, $taskId);
|
||||
|
||||
if ($task === null) {
|
||||
$this->taskStatusMessage = __('jobs.tasks.not_found');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->removalTaskId = $task->id;
|
||||
$this->removalTaskTitle = $task->title;
|
||||
|
||||
$this->js("document.getElementById('remove-task-dialog').showModal()");
|
||||
}
|
||||
|
||||
public function removeTask(RemoveTask $removeTask): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||
|
||||
if ($this->removalTaskId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$removeTask->execute($this->jobId, $this->removalTaskId);
|
||||
$this->taskStatusMessage = __('jobs.tasks.removed', ['title' => $this->removalTaskTitle]);
|
||||
} catch (TaskNotFound) {
|
||||
$this->taskStatusMessage = __('jobs.tasks.not_found');
|
||||
}
|
||||
|
||||
unset($this->tasks);
|
||||
$this->reset('removalTaskId', 'removalTaskTitle');
|
||||
|
||||
$this->js("document.getElementById('remove-task-dialog').close(); document.getElementById('tasks-heading').focus()");
|
||||
}
|
||||
|
||||
public function formatDate(?string $date): string
|
||||
{
|
||||
return $date === null ? __('jobs.not_set') : CarbonImmutable::parse($date)->format('j.n.Y');
|
||||
@@ -188,6 +282,113 @@ new class extends Component
|
||||
</dl>
|
||||
</section>
|
||||
|
||||
<section id="tasks" aria-labelledby="tasks-heading" class="space-y-4">
|
||||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||||
<h2 id="tasks-heading" tabindex="-1" class="text-xl font-semibold focus:outline-none">{{ __('jobs.tasks.title') }}</h2>
|
||||
|
||||
@can('jobs.manage-tasks', $job->id)
|
||||
@if ($job->status->allowsTasks())
|
||||
<x-button :href="route('jobs.tasks.create', $job->id)" wire:navigate icon="plus" :text="__('jobs.tasks.new')" />
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
@can('jobs.manage-tasks', $job->id)
|
||||
@unless ($job->status->allowsTasks())
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.not_allowed_yet') }}</p>
|
||||
@endunless
|
||||
@endcan
|
||||
|
||||
<p role="status" aria-live="polite" class="text-sm">{{ $taskStatusMessage }}</p>
|
||||
|
||||
@if ($this->tasks === [])
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.empty') }}</p>
|
||||
@else
|
||||
@php($canChangeStatus = Gate::allows('jobs.update-task-status', $job->id))
|
||||
@php($canManageTasks = Gate::allows('jobs.manage-tasks', $job->id))
|
||||
|
||||
<ul class="space-y-3">
|
||||
@foreach ($this->tasks as $task)
|
||||
<li wire:key="task-{{ $task->id }}">
|
||||
<article aria-labelledby="task-{{ $task->id }}-title" class="space-y-3 rounded-lg border border-zinc-200 p-4 text-sm dark:border-zinc-700">
|
||||
<div class="flex flex-wrap items-start justify-between gap-3">
|
||||
<h3 id="task-{{ $task->id }}-title" class="text-base font-medium break-words">{{ $task->title }}</h3>
|
||||
<span>{{ __('jobs.tasks.statuses.'.$task->status->value) }}</span>
|
||||
</div>
|
||||
|
||||
<dl class="grid gap-x-6 gap-y-1 sm:grid-cols-[max-content_1fr]">
|
||||
<dt class="font-medium">{{ __('jobs.tasks.fields.work_type') }}</dt>
|
||||
<dd>{{ $task->workType->name }}</dd>
|
||||
<dt class="font-medium">{{ __('jobs.tasks.fields.assignees') }}</dt>
|
||||
<dd>{{ $task->assignees === [] ? __('jobs.not_set') : collect($task->assignees)->pluck('name')->join(', ') }}</dd>
|
||||
<dt class="font-medium">{{ __('jobs.tasks.fields.due_on') }}</dt>
|
||||
<dd><x-jobs.due-date :date="$task->dueOn" :status="$task->status" /></dd>
|
||||
<dt class="font-medium">{{ __('jobs.tasks.fields.estimated_hours') }}</dt>
|
||||
<dd>{{ $task->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $task->estimatedHours).' h' }}</dd>
|
||||
</dl>
|
||||
|
||||
@if ($task->description !== null)
|
||||
<p class="whitespace-pre-line">{{ $task->description }}</p>
|
||||
@endif
|
||||
|
||||
<div class="flex flex-wrap items-end gap-3">
|
||||
@if ($canChangeStatus)
|
||||
<div class="w-full sm:w-56">
|
||||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||||
<x-select.native
|
||||
id="task-status-{{ $task->id }}"
|
||||
wire:change="changeTaskStatus({{ $task->id }}, $event.target.value)"
|
||||
:label="__('jobs.tasks.fields.status')"
|
||||
:aria-label="__('jobs.tasks.status_of', ['title' => $task->title])"
|
||||
>
|
||||
@foreach (TaskStatus::cases() as $status)
|
||||
<option value="{{ $status->value }}" @selected($status === $task->status)>{{ __('jobs.tasks.statuses.'.$status->value) }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($canManageTasks)
|
||||
<x-button
|
||||
:href="route('jobs.tasks.edit', [$job->id, $task->id])"
|
||||
wire:navigate
|
||||
subtle
|
||||
color="black"
|
||||
sm
|
||||
icon="pencil"
|
||||
:text="__('jobs.edit')"
|
||||
:aria-label="__('jobs.tasks.edit_named', ['title' => $task->title])"
|
||||
/>
|
||||
<x-button
|
||||
wire:click="confirmTaskRemoval({{ $task->id }})"
|
||||
subtle
|
||||
color="black"
|
||||
sm
|
||||
icon="trash"
|
||||
:text="__('customers.remove')"
|
||||
:aria-label="__('jobs.tasks.remove_named', ['title' => $task->title])"
|
||||
/>
|
||||
@endif
|
||||
</div>
|
||||
</article>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
|
||||
<x-confirm-dialog id="remove-task-dialog" :title="__('customers.removal.title')">
|
||||
<p>
|
||||
@if ($removalTaskId !== null)
|
||||
{{ __('jobs.tasks.remove_question', ['title' => $removalTaskTitle]) }}
|
||||
@endif
|
||||
</p>
|
||||
|
||||
<x-slot:actions>
|
||||
<x-button wire:click="removeTask" color="red" icon="trash" :text="__('customers.remove')" />
|
||||
</x-slot:actions>
|
||||
</x-confirm-dialog>
|
||||
</section>
|
||||
|
||||
<section aria-labelledby="links-heading" class="space-y-3">
|
||||
<h2 id="links-heading" class="text-xl font-semibold">{{ __('jobs.sections.links') }}</h2>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user