Phase 1, item 5: - New page /jobs/quick (Pikavastaanotto): customer (search or quick add), name, short description, service unit, responsible person and starting status (Alustava or Prospekti) in one column. The job is created with CreateCustomerJob, so numbering, reference checks and history are the same as on the full form. - After saving, the form clears for the next job (responsible person and status stay), and a status message with the job number and links to the job and its edit page takes focus. - The customer search of the job form moves to a PicksCustomer trait and an <x-jobs.customer-picker> component shared by both pages. - Menu link and a list button for users who may open jobs; nav items accept several route patterns. - PHPStan ignores unused-trait only for Livewire Concerns, which are used from excluded single-file components. - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
194 lines
7.3 KiB
PHP
194 lines
7.3 KiB
PHP
<?php
|
||
|
||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||
use App\Modules\Jobs\Application\DTOs\CustomerJobSummary;
|
||
use App\Modules\Jobs\Application\DTOs\JobListFilter;
|
||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||
use App\Modules\Users\Domain\Enums\Role;
|
||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||
use Livewire\Attributes\Computed;
|
||
use Livewire\Attributes\Url;
|
||
use Livewire\Component;
|
||
use Livewire\WithPagination;
|
||
|
||
/**
|
||
* The customer job list: search, filters and "my jobs" on by default.
|
||
*/
|
||
new class extends Component
|
||
{
|
||
use WithPagination;
|
||
|
||
#[Url(as: 'q', except: '')]
|
||
public string $search = '';
|
||
|
||
#[Url(except: '')]
|
||
public string $status = '';
|
||
|
||
#[Url(except: '')]
|
||
public string $priority = '';
|
||
|
||
#[Url(as: 'unit', except: '')]
|
||
public string $serviceUnit = '';
|
||
|
||
#[Url(except: true)]
|
||
public bool $mine = true;
|
||
|
||
#[Url(except: false)]
|
||
public bool $archived = false;
|
||
|
||
public function mount(): void
|
||
{
|
||
$this->authorize('jobs.view');
|
||
}
|
||
|
||
public function updated(string $property): void
|
||
{
|
||
if (in_array($property, ['search', 'status', 'priority', 'serviceUnit', 'mine', 'archived'], true)) {
|
||
$this->resetPage();
|
||
}
|
||
}
|
||
|
||
public function isSubcontractor(): bool
|
||
{
|
||
return auth()->user()?->role === Role::Subcontractor;
|
||
}
|
||
|
||
/**
|
||
* @return LengthAwarePaginator<int, CustomerJobSummary>
|
||
*/
|
||
#[Computed]
|
||
public function jobs(): LengthAwarePaginator
|
||
{
|
||
$userId = (int) auth()->id();
|
||
|
||
return app(CustomerJobQueries::class)->paginate(new JobListFilter(
|
||
search: $this->search,
|
||
status: JobStatus::tryFrom($this->status)?->value,
|
||
priority: Priority::tryFrom($this->priority)?->value,
|
||
serviceUnitId: $this->serviceUnit === '' ? null : (int) $this->serviceUnit,
|
||
mineForUserId: $this->mine && ! $this->isSubcontractor() ? $userId : null,
|
||
onlyMemberUserId: $this->isSubcontractor() ? $userId : null,
|
||
includeArchived: $this->archived,
|
||
));
|
||
}
|
||
|
||
/**
|
||
* @return list<array{index: string, label: string, sortable: bool}>
|
||
*/
|
||
public function headers(): array
|
||
{
|
||
return [
|
||
['index' => 'number', 'label' => __('jobs.fields.number'), 'sortable' => false],
|
||
['index' => 'name', 'label' => __('jobs.fields.name'), 'sortable' => false],
|
||
['index' => 'customerName', 'label' => __('jobs.fields.customer'), 'sortable' => false],
|
||
['index' => 'status', 'label' => __('jobs.fields.status'), 'sortable' => false],
|
||
['index' => 'priority', 'label' => __('jobs.fields.priority'), 'sortable' => false],
|
||
['index' => 'dueOn', 'label' => __('jobs.fields.due_on'), 'sortable' => false],
|
||
['index' => 'responsibleName', 'label' => __('jobs.fields.responsible_user'), 'sortable' => false],
|
||
];
|
||
}
|
||
|
||
public function render(): mixed
|
||
{
|
||
return $this->view()->title(__('jobs.title'));
|
||
}
|
||
};
|
||
?>
|
||
|
||
<div class="mx-auto max-w-7xl space-y-6 p-4 sm:p-6">
|
||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||
<h1 class="text-2xl font-semibold">{{ __('jobs.title') }}</h1>
|
||
|
||
@can('jobs.manage')
|
||
<div class="flex flex-wrap gap-2">
|
||
<x-button :href="route('jobs.quick')" wire:navigate subtle color="black" icon="bolt" :text="__('jobs.quick.link')" />
|
||
<x-button :href="route('jobs.create')" wire:navigate icon="plus" :text="__('jobs.new')" />
|
||
</div>
|
||
@endcan
|
||
</div>
|
||
|
||
@if (session('status'))
|
||
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
|
||
@endif
|
||
|
||
@if ($this->isSubcontractor())
|
||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.list.subcontractor_note') }}</p>
|
||
@endif
|
||
|
||
<div class="grid gap-4 md:grid-cols-2 xl:grid-cols-4">
|
||
<div class="md:col-span-2 xl:col-span-4">
|
||
<x-input
|
||
wire:model.live.debounce.300ms="search"
|
||
type="search"
|
||
icon="magnifying-glass"
|
||
:label="__('jobs.list.search')"
|
||
:hint="__('jobs.list.search_description')"
|
||
/>
|
||
</div>
|
||
|
||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||
<x-select.native wire:model.live="status" :label="__('jobs.fields.status')" :aria-label="__('jobs.fields.status')">
|
||
<option value="">{{ __('jobs.list.all_statuses') }}</option>
|
||
@foreach (JobStatus::cases() as $option)
|
||
<option value="{{ $option->value }}">{{ __('jobs.statuses.'.$option->value) }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
|
||
<x-select.native wire:model.live="priority" :label="__('jobs.fields.priority')" :aria-label="__('jobs.fields.priority')">
|
||
<option value="">{{ __('jobs.list.all_priorities') }}</option>
|
||
@foreach (Priority::cases() as $option)
|
||
<option value="{{ $option->value }}">{{ __('jobs.priorities.'.$option->value) }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
|
||
<x-select.native wire:model.live="serviceUnit" :label="__('jobs.fields.service_units')" :aria-label="__('jobs.fields.service_units')">
|
||
<option value="">{{ __('jobs.list.all_service_units') }}</option>
|
||
@foreach (app(CatalogQueries::class)->activeServiceUnits() as $unit)
|
||
<option value="{{ $unit->id }}">{{ $unit->name }}</option>
|
||
@endforeach
|
||
</x-select.native>
|
||
|
||
<div class="space-y-2">
|
||
@unless ($this->isSubcontractor())
|
||
<x-checkbox id="only-mine" wire:model.live="mine" :label="__('jobs.list.only_mine')" />
|
||
@endunless
|
||
<x-checkbox id="include-archived" wire:model.live="archived" :label="__('jobs.list.include_archived')" />
|
||
</div>
|
||
</div>
|
||
|
||
<p role="status" aria-live="polite" aria-atomic="true" class="text-sm text-zinc-600 dark:text-zinc-300">
|
||
{{ trans_choice('jobs.list.result_count', $this->jobs->total(), ['count' => $this->jobs->total()]) }}
|
||
@if ($mine && ! $this->isSubcontractor())
|
||
– {{ __('jobs.list.only_mine_description') }}
|
||
@endif
|
||
</p>
|
||
|
||
@if ($this->jobs->total() === 0)
|
||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.list.empty') }}</p>
|
||
@else
|
||
<x-table :headers="$this->headers()" :rows="$this->jobs" paginate>
|
||
@interact('column_number', $job)
|
||
<span class="whitespace-nowrap">{{ $job->number }}</span>
|
||
@endinteract
|
||
|
||
@interact('column_name', $job)
|
||
<x-link :href="route('jobs.show', $job->id)" navigate class="font-medium">{{ $job->name }}</x-link>
|
||
@endinteract
|
||
|
||
@interact('column_status', $job)
|
||
{{ __('jobs.statuses.'.$job->status->value) }}
|
||
@endinteract
|
||
|
||
@interact('column_priority', $job)
|
||
<x-jobs.priority :priority="$job->priority" />
|
||
@endinteract
|
||
|
||
@interact('column_dueOn', $job)
|
||
<x-jobs.due-date :date="$job->dueOn" :status="$job->status" />
|
||
@endinteract
|
||
</x-table>
|
||
@endif
|
||
</div>
|