Files
Toiminnanohjaus/app/Modules/Jobs/Presentation/Livewire/Forms/QuickJobForm.php
T
petriandClaude Opus 5.5 6332ff0fa9 Rebuild the Kanban board after the prototype, with the job editor and quick intake dialog
- Toolbar: whose board (own, a person, a service line, all), pipeline
  views (daily, sales, full), urgent and late filters with a live count,
  normal and compact density, and the quick intake button.
- Columns side by side with horizontal scrolling on desktop, stacked on
  phones; each user's own column colours and order, the urgent column's
  threshold menu, and the continuing jobs column.
- Cards in customer colours: job cards with their tasks checked off inside
  the card (the status select is gone), continuing job cards with the next
  period, PIN and quick add, and pinned task cards. Dragging moves and
  orders cards; the keyboard opens the job editor from the card title.
- Job editor dialog: every job detail, tasks with checklists and
  templates, quick hours (TimeTracking) and expenses (Expenses), history.
- The quick intake form also adds a contact person, initial status and
  priority, and opens as a dialog on the board.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-30 06:33:28 +02:00

137 lines
5.0 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 and in the board's dialog: only what is
* needed to open a job (docs/ui-kanban-board.md 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 string $priority = Priority::Normal->value;
public string $customer_contact_id = '';
/** The intake has a new contact person of the customer to add. */
public bool $adding_contact = false;
public string $new_contact_name = '';
public string $new_contact_phone = '';
/**
* The statuses a job can start in at intake.
*
* @return list<JobStatus>
*/
public static function startStatuses(): array
{
return [JobStatus::Prospect, JobStatus::Tentative, JobStatus::QuoteRequest, JobStatus::Order, JobStatus::InProduction];
}
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: $this->priority,
description: trim($this->description) === '' ? null : $this->description,
customerContactId: $this->customer_contact_id === '' ? null : (int) $this->customer_contact_id,
);
}
/**
* 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', 'priority', 'customer_contact_id', 'adding_contact', 'new_contact_name', 'new_contact_phone');
$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(array_map(fn (JobStatus $status): string => $status->value, self::startStatuses()))],
'priority' => ['required', Rule::enum(Priority::class)],
'customer_contact_id' => ['nullable', 'integer'],
'new_contact_name' => [$this->adding_contact ? 'required' : 'nullable', 'string', 'max:255'],
'new_contact_phone' => ['nullable', 'string', 'max:50'],
];
}
/**
* @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'),
'priority.*' => __('jobs.errors.status_not_allowed'),
'new_contact_name.required' => __('jobs.quick.contact_name_required'),
'new_contact_name.max' => __('jobs.errors.too_long', ['max' => 255]),
'new_contact_phone.max' => __('jobs.errors.too_long', ['max' => 50]),
];
}
}