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]>
166 lines
6.0 KiB
PHP
166 lines
6.0 KiB
PHP
<?php
|
|
|
|
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
|
use App\Modules\Catalog\Application\DTOs\ServiceUnitSummary;
|
|
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
|
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Presentation\Livewire\Concerns\PicksCustomer;
|
|
use App\Modules\Jobs\Presentation\Livewire\Forms\QuickJobForm;
|
|
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
|
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
|
use App\Modules\Users\Application\DTOs\UserOption;
|
|
use App\Modules\Users\Domain\Enums\Role;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* Quick job intake (pikavastaanotto), made for phones: customer, name,
|
|
* short description, service unit and responsible person. The page stays
|
|
* open for the next job and links to the one just created.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
use PicksCustomer;
|
|
|
|
public QuickJobForm $form;
|
|
|
|
/**
|
|
* The job created last on this page, shown with links to it.
|
|
*/
|
|
#[Locked]
|
|
public ?int $createdJobId = null;
|
|
|
|
#[Locked]
|
|
public string $createdMessage = '';
|
|
|
|
#[Locked]
|
|
public string $createdNumber = '';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->authorize('jobs.manage');
|
|
|
|
$this->form->responsible_user_id = (string) auth()->id();
|
|
}
|
|
|
|
/**
|
|
* @return list<ServiceUnitSummary>
|
|
*/
|
|
#[Computed]
|
|
public function serviceUnits(): array
|
|
{
|
|
return app(CatalogQueries::class)->activeServiceUnits();
|
|
}
|
|
|
|
/**
|
|
* Users who can be responsible for a job (not subcontractors).
|
|
*
|
|
* @return list<UserOption>
|
|
*/
|
|
#[Computed]
|
|
public function staff(): array
|
|
{
|
|
return array_values(array_filter(
|
|
app(UserAccountQueries::class)->activeUserOptions(),
|
|
fn (UserOption $user): bool => $user->role !== Role::Subcontractor,
|
|
));
|
|
}
|
|
|
|
public function save(CreateCustomerJob $createJob, CustomerJobQueries $jobQueries): void
|
|
{
|
|
$this->authorize('jobs.manage');
|
|
|
|
$data = $this->form->toData();
|
|
|
|
try {
|
|
$jobId = $createJob->execute($data, (int) auth()->id());
|
|
} catch (DomainException $exception) {
|
|
$this->form->showDomainError($exception);
|
|
|
|
return;
|
|
}
|
|
|
|
$this->createdJobId = $jobId;
|
|
$this->createdNumber = $jobQueries->findDetails($jobId)->number ?? '';
|
|
$this->createdMessage = __('jobs.created', ['number' => $this->createdNumber, 'name' => trim($data->name)]);
|
|
|
|
$this->form->clearForNextJob();
|
|
$this->customerName = '';
|
|
$this->customerSearch = '';
|
|
$this->statusMessage = '';
|
|
|
|
$this->js("document.getElementById('quick-created')?.focus()");
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('jobs.quick.title'));
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-lg space-y-6 p-4 sm:p-6">
|
|
<div class="space-y-1">
|
|
<h1 class="text-2xl font-semibold">{{ __('jobs.quick.title') }}</h1>
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.quick.intro') }}</p>
|
|
</div>
|
|
|
|
<div id="quick-created" tabindex="-1" role="status" aria-live="polite" class="focus:outline-none">
|
|
@if ($createdJobId !== null)
|
|
<div class="space-y-2 rounded-lg border border-green-700 bg-green-50 p-4 text-sm text-green-900 dark:border-green-500 dark:bg-green-950 dark:text-green-100">
|
|
<p class="flex items-start gap-2 font-medium">
|
|
<x-icon name="check-circle" class="size-5 shrink-0" aria-hidden="true" />
|
|
{{ $createdMessage }}
|
|
</p>
|
|
<p class="flex flex-wrap gap-x-4 gap-y-1">
|
|
<x-link :href="route('jobs.show', $createdJobId)" navigate>{{ __('jobs.quick.open', ['number' => $createdNumber]) }}</x-link>
|
|
<x-link :href="route('jobs.edit', $createdJobId)" navigate>{{ __('jobs.quick.complete') }}</x-link>
|
|
</p>
|
|
</div>
|
|
@endif
|
|
</div>
|
|
|
|
<p role="status" aria-live="polite" class="text-sm">{{ $statusMessage }}</p>
|
|
|
|
<form wire:submit="save" class="space-y-6" novalidate>
|
|
<x-jobs.customer-picker
|
|
:customer-id="$form->customer_id"
|
|
:customer-name="$customerName"
|
|
:search="$customerSearch"
|
|
:results="$this->customerResults"
|
|
/>
|
|
|
|
<x-input wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required />
|
|
|
|
<x-textarea wire:model="form.description" :label="__('jobs.quick.description')" rows="3" />
|
|
|
|
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
|
<x-select.native wire:model="form.service_unit_id" :label="__('jobs.quick.service_unit')" :aria-label="__('jobs.quick.service_unit')" required>
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($this->serviceUnits as $unit)
|
|
<option value="{{ $unit->id }}">{{ $unit->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-select.native wire:model="form.responsible_user_id" :label="__('jobs.fields.responsible_user')" :aria-label="__('jobs.fields.responsible_user')" required>
|
|
<option value="">{{ __('jobs.fields.none_selected') }}</option>
|
|
@foreach ($this->staff as $user)
|
|
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
|
|
<x-radio.group
|
|
wire:model="form.status"
|
|
:label="__('jobs.fields.status')"
|
|
:options="[
|
|
['label' => __('jobs.statuses.'.JobStatus::Tentative->value), 'value' => JobStatus::Tentative->value],
|
|
['label' => __('jobs.statuses.'.JobStatus::Prospect->value), 'value' => JobStatus::Prospect->value],
|
|
]"
|
|
/>
|
|
|
|
<x-button submit lg class="w-full" :text="__('jobs.quick.save')" />
|
|
</form>
|
|
</div>
|