Add quick job intake for phones
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]>
This commit is contained in:
@@ -4,10 +4,6 @@ use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Customers\Application\DTOs\BillingUnitSummary;
|
||||
use App\Modules\Customers\Application\DTOs\ContactSummary;
|
||||
use App\Modules\Customers\Application\DTOs\CustomerDetailsData;
|
||||
use App\Modules\Customers\Application\DTOs\CustomerSummary;
|
||||
use App\Modules\Customers\Application\UseCases\RegisterCustomer;
|
||||
use App\Modules\Customers\Domain\Enums\CustomerType;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
||||
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob;
|
||||
@@ -17,6 +13,7 @@ use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\PaymentBasis;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Jobs\Presentation\Livewire\Concerns\PicksCustomer;
|
||||
use App\Modules\Jobs\Presentation\Livewire\Forms\JobForm;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
@@ -32,15 +29,14 @@ use Livewire\Component;
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use PicksCustomer;
|
||||
|
||||
#[Locked]
|
||||
public ?int $jobId = null;
|
||||
|
||||
#[Locked]
|
||||
public string $jobNumber = '';
|
||||
|
||||
#[Locked]
|
||||
public string $customerName = '';
|
||||
|
||||
/**
|
||||
* The status stored before this edit: always offered, even when the
|
||||
* user could not set it themselves.
|
||||
@@ -50,12 +46,8 @@ new class extends Component
|
||||
|
||||
public JobForm $form;
|
||||
|
||||
public string $customerSearch = '';
|
||||
|
||||
public string $newTag = '';
|
||||
|
||||
public string $statusMessage = '';
|
||||
|
||||
public function mount(CustomerJobQueries $jobQueries, ?int $job = null): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
@@ -77,17 +69,6 @@ new class extends Component
|
||||
$this->form->fillFromDetails($details);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<CustomerSummary>
|
||||
*/
|
||||
#[Computed]
|
||||
public function customerResults(): array
|
||||
{
|
||||
$term = trim($this->customerSearch);
|
||||
|
||||
return mb_strlen($term) < 2 ? [] : app(CustomerQueries::class)->search($term, 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{value: int, label: string}>
|
||||
*/
|
||||
@@ -162,49 +143,6 @@ new class extends Component
|
||||
return array_values(array_diff(app(CustomerJobQueries::class)->tagSuggestions($this->newTag), $this->form->tags));
|
||||
}
|
||||
|
||||
public function selectCustomer(int $customerId): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$customer = app(CustomerQueries::class)->findSummary($customerId);
|
||||
|
||||
if ($customer === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->useCustomer($customer->id, $customer->name);
|
||||
}
|
||||
|
||||
public function createCustomer(RegisterCustomer $registerCustomer): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
$this->authorize('customers.use');
|
||||
|
||||
$name = trim($this->customerSearch);
|
||||
|
||||
try {
|
||||
$customerId = $registerCustomer->execute(new CustomerDetailsData($name, CustomerType::Company));
|
||||
} catch (DomainException) {
|
||||
$this->addError('customerSearch', __('customers.errors.invalid_name'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->useCustomer($customerId, $name);
|
||||
$this->statusMessage = __('jobs.customer_picker.created', ['name' => $name]);
|
||||
}
|
||||
|
||||
public function clearCustomer(): void
|
||||
{
|
||||
$this->form->customer_id = '';
|
||||
$this->form->customer_contact_id = '';
|
||||
$this->form->billing_unit_id = '';
|
||||
$this->customerName = '';
|
||||
$this->statusMessage = '';
|
||||
|
||||
$this->js("document.getElementById('customer-search')?.focus()");
|
||||
}
|
||||
|
||||
public function addTag(): void
|
||||
{
|
||||
$tag = trim(preg_replace('/\s+/u', ' ', $this->newTag) ?? '');
|
||||
@@ -317,19 +255,13 @@ new class extends Component
|
||||
return true;
|
||||
}
|
||||
|
||||
private function useCustomer(int $customerId, string $name): void
|
||||
/**
|
||||
* A contact or billing unit of another customer no longer fits.
|
||||
*/
|
||||
protected function customerChosen(?int $customerId): void
|
||||
{
|
||||
if ((string) $customerId !== $this->form->customer_id) {
|
||||
$this->form->customer_contact_id = '';
|
||||
$this->form->billing_unit_id = '';
|
||||
}
|
||||
|
||||
$this->form->customer_id = (string) $customerId;
|
||||
$this->customerName = $name;
|
||||
$this->customerSearch = '';
|
||||
$this->resetErrorBag(['customerSearch', 'form.customer_id']);
|
||||
|
||||
$this->js("document.getElementById('change-customer')?.focus()");
|
||||
$this->form->customer_contact_id = '';
|
||||
$this->form->billing_unit_id = '';
|
||||
}
|
||||
};
|
||||
?>
|
||||
@@ -354,74 +286,12 @@ new class extends Component
|
||||
|
||||
<x-input wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required />
|
||||
|
||||
{{-- Customer: search field and results as buttons, or the chosen customer. --}}
|
||||
<div class="space-y-2">
|
||||
@if ($form->customer_id !== '')
|
||||
<p class="text-sm font-semibold text-gray-700 dark:text-dark-300">{{ __('jobs.fields.customer') }}</p>
|
||||
<div class="flex flex-wrap items-center gap-3">
|
||||
<span class="font-medium">{{ $customerName }}</span>
|
||||
<x-button
|
||||
id="change-customer"
|
||||
wire:click="clearCustomer"
|
||||
subtle
|
||||
color="black"
|
||||
sm
|
||||
:text="__('jobs.customer_picker.change')"
|
||||
:aria-label="__('jobs.customer_picker.change').': '.$customerName"
|
||||
/>
|
||||
</div>
|
||||
@else
|
||||
<x-input
|
||||
id="customer-search"
|
||||
wire:model.live.debounce.300ms="customerSearch"
|
||||
type="search"
|
||||
icon="magnifying-glass"
|
||||
:label="__('jobs.customer_picker.search')"
|
||||
:hint="__('jobs.customer_picker.search_description')"
|
||||
autocomplete="off"
|
||||
required
|
||||
/>
|
||||
|
||||
@error('form.customer_id')
|
||||
<p class="text-sm text-red-700 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
@if (mb_strlen(trim($customerSearch)) >= 2)
|
||||
<p role="status" aria-live="polite" class="text-sm text-zinc-600 dark:text-zinc-300">
|
||||
{{ trans_choice('jobs.customer_picker.results', count($this->customerResults), ['count' => count($this->customerResults)]) }}
|
||||
</p>
|
||||
|
||||
<ul class="space-y-1">
|
||||
@foreach ($this->customerResults as $customer)
|
||||
<li wire:key="customer-result-{{ $customer->id }}">
|
||||
<button
|
||||
type="button"
|
||||
wire:click="selectCustomer({{ $customer->id }})"
|
||||
class="w-full rounded-md px-3 py-2 text-left text-sm hover:bg-zinc-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:hover:bg-zinc-700"
|
||||
aria-label="{{ __('jobs.customer_picker.choose', ['name' => $customer->name]) }}"
|
||||
>
|
||||
<span class="font-medium">{{ $customer->name }}</span>
|
||||
@if ($customer->businessId !== null)
|
||||
<span class="text-zinc-600 dark:text-zinc-300">{{ $customer->businessId }}</span>
|
||||
@endif
|
||||
</button>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
|
||||
@can('customers.use')
|
||||
<x-button
|
||||
wire:click="createCustomer"
|
||||
subtle
|
||||
color="black"
|
||||
sm
|
||||
icon="plus"
|
||||
:text="__('jobs.customer_picker.create', ['name' => trim($customerSearch)])"
|
||||
/>
|
||||
@endcan
|
||||
@endif
|
||||
@endif
|
||||
</div>
|
||||
<x-jobs.customer-picker
|
||||
:customer-id="$form->customer_id"
|
||||
:customer-name="$customerName"
|
||||
:search="$customerSearch"
|
||||
:results="$this->customerResults"
|
||||
/>
|
||||
|
||||
<x-textarea wire:model="form.description" :label="__('jobs.fields.description')" resize-auto />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user