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]>
106 lines
3.6 KiB
PHP
106 lines
3.6 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Jobs\Presentation\Livewire\Forms;
|
|
|
|
use App\Modules\Jobs\Application\DTOs\CustomerJobData;
|
|
use App\Modules\Jobs\Domain\Enums\JobKind;
|
|
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
|
use App\Modules\Jobs\Domain\Enums\Priority;
|
|
use App\Modules\Jobs\Domain\Exceptions\InvalidJobName;
|
|
use App\Modules\Jobs\Domain\Exceptions\InvalidJobReference;
|
|
use App\Modules\Jobs\Domain\Exceptions\ServiceUnitRequired;
|
|
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
|
use Illuminate\Validation\Rule;
|
|
use Livewire\Form;
|
|
|
|
/**
|
|
* Quick job intake on a phone: only what is needed to open a job (spec 6).
|
|
* Everything else gets the defaults and is filled in later.
|
|
*/
|
|
class QuickJobForm extends Form
|
|
{
|
|
public string $customer_id = '';
|
|
|
|
public string $name = '';
|
|
|
|
public string $description = '';
|
|
|
|
public string $service_unit_id = '';
|
|
|
|
public string $responsible_user_id = '';
|
|
|
|
public string $status = JobStatus::Tentative->value;
|
|
|
|
public function toData(): CustomerJobData
|
|
{
|
|
$this->validate();
|
|
|
|
return new CustomerJobData(
|
|
name: $this->name,
|
|
customerId: (int) $this->customer_id,
|
|
serviceUnitIds: [(int) $this->service_unit_id],
|
|
responsibleUserId: (int) $this->responsible_user_id,
|
|
kind: JobKind::OneOff->value,
|
|
status: $this->status,
|
|
priority: Priority::Normal->value,
|
|
description: trim($this->description) === '' ? null : $this->description,
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Empties the form for the next job; responsible person and status stay.
|
|
*/
|
|
public function clearForNextJob(): void
|
|
{
|
|
$this->reset('customer_id', 'name', 'description', 'service_unit_id');
|
|
$this->resetErrorBag();
|
|
}
|
|
|
|
public function showDomainError(DomainException $exception): void
|
|
{
|
|
[$field, $key] = match (true) {
|
|
$exception instanceof InvalidJobName => ['name', 'jobs.errors.invalid_name'],
|
|
$exception instanceof ServiceUnitRequired => ['service_unit_id', 'jobs.errors.service_units_required'],
|
|
$exception instanceof InvalidJobReference => [match ($exception->field) {
|
|
'customer' => 'customer_id',
|
|
'service_units' => 'service_unit_id',
|
|
default => 'responsible_user_id',
|
|
}, 'jobs.errors.invalid_reference'],
|
|
default => throw $exception,
|
|
};
|
|
|
|
$this->addError($field, __($key));
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, mixed>>
|
|
*/
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'customer_id' => ['required', 'integer'],
|
|
'name' => ['required', 'string', 'max:255'],
|
|
'description' => ['nullable', 'string', 'max:2000'],
|
|
'service_unit_id' => ['required', 'integer'],
|
|
'responsible_user_id' => ['required', 'integer'],
|
|
'status' => ['required', Rule::in([JobStatus::Tentative->value, JobStatus::Prospect->value])],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function messages(): array
|
|
{
|
|
return [
|
|
'customer_id.required' => __('jobs.errors.customer_required'),
|
|
'name.required' => __('jobs.errors.name_required'),
|
|
'name.max' => __('jobs.errors.invalid_name'),
|
|
'description.max' => __('jobs.errors.too_long', ['max' => 2000]),
|
|
'service_unit_id.required' => __('jobs.quick.service_unit_required'),
|
|
'responsible_user_id.required' => __('jobs.errors.responsible_required'),
|
|
'status.in' => __('jobs.errors.status_not_allowed'),
|
|
];
|
|
}
|
|
}
|