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:
2026-11-23 19:07:25 +02:00
co-authored by Claude Opus 5.5
parent 70e107f6e2
commit b3d8e66477
16 changed files with 627 additions and 151 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ Accessibility is a contractual acceptance criterion. It covers the whole UI: nav
- `<tallstackui:script />`: root-relative asset URLs that 404 in a subfolder (local XAMPP). The layout includes `resources/views/partials/tallstackui-script.blade.php` instead. - `<tallstackui:script />`: root-relative asset URLs that 404 in a subfolder (local XAMPP). The layout includes `resources/views/partials/tallstackui-script.blade.php` instead.
- `<x-select.native>`: the label is not tied to the control, so also pass `:aria-label` with the same text. - `<x-select.native>`: the label is not tied to the control, so also pass `:aria-label` with the same text.
- `<x-modal>`: `aria-labelledby` points at an id its title lacks, the close button has no name, and focus neither moves in nor returns. Use `<x-confirm-dialog>` (`resources/views/components/confirm-dialog.blade.php`, native `<dialog>` + `showModal()`), opened from Livewire with `$this->js("document.getElementById('<id>').showModal()")`; see `customers::show`. - `<x-modal>`: `aria-labelledby` points at an id its title lacks, the close button has no name, and focus neither moves in nor returns. Use `<x-confirm-dialog>` (`resources/views/components/confirm-dialog.blade.php`, native `<dialog>` + `showModal()`), opened from Livewire with `$this->js("document.getElementById('<id>').showModal()")`; see `customers::show`.
- Groups of checkboxes for an array property: `<x-checkbox-group>` (`resources/views/components/checkbox-group.blade.php`, fieldset + legend + native inputs). Searchable choices (customer on the job form) are a search input with result buttons and a `role="status"` count, not `<x-select.styled>`. - Groups of checkboxes for an array property: `<x-checkbox-group>` (`resources/views/components/checkbox-group.blade.php`, fieldset + legend + native inputs). Searchable choices are a search input with result buttons and a `role="status"` count, not `<x-select.styled>`: for customers use the `PicksCustomer` trait (`app/Modules/Jobs/Presentation/Livewire/Concerns`) with `<x-jobs.customer-picker>`.
- Solid `color="red"` buttons: white on red-500 is 3.5:1, so the solid red is red-700 in the published `NormalButtonColors`. - Solid `color="red"` buttons: white on red-500 is 3.5:1, so the solid red is red-700 in the published `NormalButtonColors`.
- `<x-input>` without `wire:model` (e.g. a read-only value): pass an explicit `id`, or the label is not tied to it. `<x-clipboard>` has an unlabelled input and a button whose name changes; build copy fields from `<x-input readonly>` + `<x-button>` + a `role="status"` message instead (see `users::form`). - `<x-input>` without `wire:model` (e.g. a read-only value): pass an explicit `id`, or the label is not tied to it. `<x-clipboard>` has an unlabelled input and a button whose name changes; build copy fields from `<x-input readonly>` + `<x-button>` + a `role="status"` message instead (see `users::form`).
- Contrast: the primary palette is one step darker (`resources/css/app.css`); error text, label error and asterisk, and input/select error colours are changed by soft customization in `App\Providers\AppServiceProvider`; light alert and link text colours are in published colour classes `app/View/Components/TallStackUi/Colors/`. `flat` and `outline` buttons have no dark-mode text colour: use `subtle color="black"` for neutral buttons. - Contrast: the primary palette is one step darker (`resources/css/app.css`); error text, label error and asterisk, and input/select error colours are changed by soft customization in `App\Providers\AppServiceProvider`; light alert and link text colours are in published colour classes `app/View/Components/TallStackUi/Colors/`. `flat` and `outline` buttons have no dark-mode text colour: use `subtle color="black"` for neutral buttons.
@@ -0,0 +1,102 @@
<?php
namespace App\Modules\Jobs\Presentation\Livewire\Concerns;
use App\Modules\Customers\Application\Contracts\CustomerQueries;
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\Shared\Domain\Exceptions\DomainException;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
/**
* Customer choice for job pages, rendered with <x-jobs.customer-picker>:
* a search field whose results are buttons, and a quick add by name. The
* page has a form object with a `customer_id` string and may override
* customerChosen() to clear fields that depend on the customer.
*
* @property-read list<CustomerSummary> $customerResults
*/
trait PicksCustomer
{
public string $customerSearch = '';
#[Locked]
public string $customerName = '';
public string $statusMessage = '';
/**
* @return list<CustomerSummary>
*/
#[Computed]
public function customerResults(): array
{
$term = trim($this->customerSearch);
return mb_strlen($term) < 2 ? [] : app(CustomerQueries::class)->search($term, 8);
}
public function selectCustomer(int $customerId): void
{
$this->authorize('jobs.manage');
$customer = app(CustomerQueries::class)->findSummary($customerId);
if ($customer !== null) {
$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->customerName = '';
$this->statusMessage = '';
$this->customerChosen(null);
$this->js("document.getElementById('customer-search')?.focus()");
}
/**
* Called when the customer changes; null when it was cleared.
*/
protected function customerChosen(?int $customerId): void {}
private function useCustomer(int $customerId, string $name): void
{
$changed = (string) $customerId !== $this->form->customer_id;
$this->form->customer_id = (string) $customerId;
$this->customerName = $name;
$this->customerSearch = '';
$this->resetErrorBag(['customerSearch', 'form.customer_id']);
if ($changed) {
$this->customerChosen($customerId);
}
$this->js("document.getElementById('change-customer')?.focus()");
}
}
@@ -0,0 +1,105 @@
<?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'),
];
}
}
@@ -4,10 +4,6 @@ use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Customers\Application\Contracts\CustomerQueries; use App\Modules\Customers\Application\Contracts\CustomerQueries;
use App\Modules\Customers\Application\DTOs\BillingUnitSummary; use App\Modules\Customers\Application\DTOs\BillingUnitSummary;
use App\Modules\Customers\Application\DTOs\ContactSummary; 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\Contracts\CustomerJobQueries;
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails; use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
use App\Modules\Jobs\Application\UseCases\CreateCustomerJob; 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\PaymentBasis;
use App\Modules\Jobs\Domain\Enums\Priority; use App\Modules\Jobs\Domain\Enums\Priority;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound; 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\Jobs\Presentation\Livewire\Forms\JobForm;
use App\Modules\Shared\Domain\Exceptions\DomainException; use App\Modules\Shared\Domain\Exceptions\DomainException;
use App\Modules\Users\Application\Contracts\UserAccountQueries; use App\Modules\Users\Application\Contracts\UserAccountQueries;
@@ -32,15 +29,14 @@ use Livewire\Component;
*/ */
new class extends Component new class extends Component
{ {
use PicksCustomer;
#[Locked] #[Locked]
public ?int $jobId = null; public ?int $jobId = null;
#[Locked] #[Locked]
public string $jobNumber = ''; public string $jobNumber = '';
#[Locked]
public string $customerName = '';
/** /**
* The status stored before this edit: always offered, even when the * The status stored before this edit: always offered, even when the
* user could not set it themselves. * user could not set it themselves.
@@ -50,12 +46,8 @@ new class extends Component
public JobForm $form; public JobForm $form;
public string $customerSearch = '';
public string $newTag = ''; public string $newTag = '';
public string $statusMessage = '';
public function mount(CustomerJobQueries $jobQueries, ?int $job = null): void public function mount(CustomerJobQueries $jobQueries, ?int $job = null): void
{ {
$this->authorize('jobs.manage'); $this->authorize('jobs.manage');
@@ -77,17 +69,6 @@ new class extends Component
$this->form->fillFromDetails($details); $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}> * @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)); 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 public function addTag(): void
{ {
$tag = trim(preg_replace('/\s+/u', ' ', $this->newTag) ?? ''); $tag = trim(preg_replace('/\s+/u', ' ', $this->newTag) ?? '');
@@ -317,19 +255,13 @@ new class extends Component
return true; 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->customer_contact_id = ''; $this->form->billing_unit_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()");
} }
}; };
?> ?>
@@ -354,74 +286,12 @@ new class extends Component
<x-input wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required /> <x-input wire:model="form.name" :label="__('jobs.fields.name')" autocomplete="off" required />
{{-- Customer: search field and results as buttons, or the chosen customer. --}} <x-jobs.customer-picker
<div class="space-y-2"> :customer-id="$form->customer_id"
@if ($form->customer_id !== '') :customer-name="$customerName"
<p class="text-sm font-semibold text-gray-700 dark:text-dark-300">{{ __('jobs.fields.customer') }}</p> :search="$customerSearch"
<div class="flex flex-wrap items-center gap-3"> :results="$this->customerResults"
<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-textarea wire:model="form.description" :label="__('jobs.fields.description')" resize-auto /> <x-textarea wire:model="form.description" :label="__('jobs.fields.description')" resize-auto />
@@ -102,7 +102,10 @@ new class extends Component
<h1 class="text-2xl font-semibold">{{ __('jobs.title') }}</h1> <h1 class="text-2xl font-semibold">{{ __('jobs.title') }}</h1>
@can('jobs.manage') @can('jobs.manage')
<x-button :href="route('jobs.create')" wire:navigate icon="plus" :text="__('jobs.new')" /> <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 @endcan
</div> </div>
@@ -0,0 +1,165 @@
<?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>
@@ -8,6 +8,7 @@ Route::middleware(['web', 'auth', 'can:jobs.view'])
->group(function () { ->group(function () {
Route::livewire('/', 'jobs::index')->name('index'); Route::livewire('/', 'jobs::index')->name('index');
Route::livewire('/create', 'jobs::form')->middleware('can:jobs.manage')->name('create'); Route::livewire('/create', 'jobs::form')->middleware('can:jobs.manage')->name('create');
Route::livewire('/quick', 'jobs::quick')->middleware('can:jobs.manage')->name('quick');
Route::livewire('/{job}', 'jobs::show')->whereNumber('job')->name('show'); Route::livewire('/{job}', 'jobs::show')->whereNumber('job')->name('show');
Route::livewire('/{job}/edit', 'jobs::form')->whereNumber('job')->middleware('can:jobs.manage')->name('edit'); Route::livewire('/{job}/edit', 'jobs::form')->whereNumber('job')->middleware('can:jobs.manage')->name('edit');
}); });
+4 -2
View File
@@ -204,7 +204,9 @@ Asiakastyön kenttien muutokset tallennetaan: kuka, milloin, mikä kenttä, vanh
- Toimii puhelimella ja tietokoneella; puhelimella yksi kapea lomake. - Toimii puhelimella ja tietokoneella; puhelimella yksi kapea lomake.
- Pakolliset: asiakas (haku tai pikalisäys), nimi, lyhyt kuvaus, palveluyksikkö, vastuuhenkilö. Muut kentät täydennetään myöhemmin. - Pakolliset: asiakas (haku tai pikalisäys), nimi, lyhyt kuvaus, palveluyksikkö, vastuuhenkilö. Muut kentät täydennetään myöhemmin.
- Uusi työ alkaa tilasta *Prospekti* tai *Alustava* (valittavissa, oletus Alustava). - Uusi työ alkaa tilasta *Prospekti* tai *Alustava* (valittavissa, oletus Alustava). Laji on Kertaluonteinen ja prioriteetti Normaali; vastuuhenkilönä on oletuksena kirjaaja.
- Tallennuksen jälkeen sivu jää auki seuraavaa työtä varten: lomake tyhjenee (vastuuhenkilö ja tila säilyvät), ja ilmoituksessa on työn numero sekä linkit "Avaa työ" ja "Täydennä tietoja".
- Pikavastaanotto löytyy valikosta ja asiakastyölistalta (`/jobs/quick`).
- Ei automaattista luontia sähköpostista tai verkkolomakkeesta toistaiseksi. - Ei automaattista luontia sähköpostista tai verkkolomakkeesta toistaiseksi.
## 7. Pikamyynti *(K19)* ## 7. Pikamyynti *(K19)*
@@ -411,7 +413,7 @@ Jokainen sivu täyttää saavutettavuusvaatimukset ja saa selaintestin (vaalea/t
- Muutoshistoria näkyy työn sivulla. - Muutoshistoria näkyy työn sivulla.
### 16.5 Pikavastaanotto ### 16.5 Pikavastaanotto
- Puhelimella (320 px) yksi lomake: asiakas, nimi, lyhyt kuvaus, palveluyksikkö, vastuuhenkilö. Tallennuksen jälkeen ilmoitus työn numerosta ja linkki työhön. - *(valmis)* Puhelimella (320 px) yksi lomake: asiakas, nimi, lyhyt kuvaus, palveluyksikkö, vastuuhenkilö ja alkutila. Tallennuksen jälkeen ilmoitus työn numerosta ja linkit työhön; fokus siirtyy ilmoitukseen.
### 16.6 Kanban ### 16.6 Kanban
- Sarakkeet tiloittain, arkistoitu pois. Kortin tila vaihdetaan vetämällä tai kortin valikosta (näppäimistö). Muutos ilmoitetaan `aria-live`-alueella. - Sarakkeet tiloittain, arkistoitu pois. Kortin tila vaihdetaan vetämällä tai kortin valikosta (näppäimistö). Muutos ilmoitetaan `aria-live`-alueella.
+12
View File
@@ -14,6 +14,18 @@ return [
'late' => 'Myöhässä', 'late' => 'Myöhässä',
'opens_in_new_tab' => 'avautuu uuteen välilehteen', 'opens_in_new_tab' => 'avautuu uuteen välilehteen',
'quick' => [
'title' => 'Pikavastaanotto',
'intro' => 'Kirjaa uusi työ nopeasti. Muut tiedot voi täydentää myöhemmin työn sivulla.',
'description' => 'Lyhyt kuvaus',
'service_unit' => 'Palveluyksikkö',
'service_unit_required' => 'Valitse palveluyksikkö.',
'save' => 'Tallenna työ',
'open' => 'Avaa työ :number',
'complete' => 'Täydennä tietoja',
'link' => 'Pikavastaanotto',
],
'list' => [ 'list' => [
'search' => 'Hae asiakastyötä', 'search' => 'Hae asiakastyötä',
'search_description' => 'Hae numerolla, nimellä tai asiakkaan nimellä.', 'search_description' => 'Hae numerolla, nimellä tai asiakkaan nimellä.',
+1
View File
@@ -5,6 +5,7 @@ return [
'main_menu' => 'Päävalikko', 'main_menu' => 'Päävalikko',
'home' => 'Etusivu', 'home' => 'Etusivu',
'jobs' => 'Asiakastyöt', 'jobs' => 'Asiakastyöt',
'quick_intake' => 'Pikavastaanotto',
'customers' => 'Asiakkaat', 'customers' => 'Asiakkaat',
'users' => 'Käyttäjät', 'users' => 'Käyttäjät',
'catalog' => 'Pohjatiedot', 'catalog' => 'Pohjatiedot',
+5
View File
@@ -8,3 +8,8 @@ parameters:
excludePaths: excludePaths:
# Livewire single-file components mix PHP and Blade, so PHPStan cannot analyse them. # Livewire single-file components mix PHP and Blade, so PHPStan cannot analyse them.
- app/**/*.blade.php - app/**/*.blade.php
ignoreErrors:
# Traits for Livewire single-file components are used only by the excluded .blade.php files.
-
identifier: trait.unused
path: app/Modules/*/Presentation/Livewire/Concerns/*
@@ -0,0 +1,81 @@
{{--
Customer choice of a job page using the PicksCustomer trait: a search
field whose results are buttons, the number of matches announced, and
"Lisää uusi asiakas" for a name not found. Once chosen, the customer is
shown as text with a "Vaihda asiakas" button.
--}}
@props([
'customerId',
'customerName',
'search',
'results',
'errorKey' => 'form.customer_id',
])
<div {{ $attributes->class('space-y-2') }}>
@if ($customerId !== '')
<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 break-words">{{ $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($errorKey)
<p class="text-sm text-red-700 dark:text-red-400">{{ $message }}</p>
@enderror
@if (mb_strlen(trim($search)) >= 2)
<p role="status" aria-live="polite" class="text-sm text-zinc-600 dark:text-zinc-300">
{{ trans_choice('jobs.customer_picker.results', count($results), ['count' => count($results)]) }}
</p>
<ul class="space-y-1">
@foreach ($results 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($search)])"
/>
@endcan
@endif
@endif
</div>
+5 -1
View File
@@ -55,7 +55,11 @@
</a> </a>
<nav aria-label="{{ __('layout.main_menu') }}" class="flex flex-1 flex-wrap items-center gap-1"> <nav aria-label="{{ __('layout.main_menu') }}" class="flex flex-1 flex-wrap items-center gap-1">
@include('partials.nav-item', ['route' => 'jobs.index', 'pattern' => 'jobs.*', 'label' => __('layout.jobs')]) @include('partials.nav-item', ['route' => 'jobs.index', 'pattern' => ['jobs.index', 'jobs.show', 'jobs.create', 'jobs.edit'], 'label' => __('layout.jobs')])
@can('jobs.manage')
@include('partials.nav-item', ['route' => 'jobs.quick', 'pattern' => 'jobs.quick', 'label' => __('layout.quick_intake')])
@endcan
@can('customers.use') @can('customers.use')
@include('partials.nav-item', ['route' => 'customers.index', 'pattern' => 'customers.*', 'label' => __('layout.customers')]) @include('partials.nav-item', ['route' => 'customers.index', 'pattern' => 'customers.*', 'label' => __('layout.customers')])
+1 -1
View File
@@ -1,5 +1,5 @@
{{-- Main menu link. The current page is marked with aria-current and an underline, not colour alone. --}} {{-- Main menu link. The current page is marked with aria-current and an underline, not colour alone. --}}
@php($current = request()->routeIs($pattern)) @php($current = request()->routeIs(...(array) $pattern))
<a <a
href="{{ route($route) }}" href="{{ route($route) }}"
+35
View File
@@ -1,6 +1,7 @@
<?php <?php
use App\Models\User; use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel; use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel; use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -69,3 +70,37 @@ it('finds and picks a customer, and adds and removes a tag, with the keyboard',
->assertScript('document.activeElement.id', 'new-tag') ->assertScript('document.activeElement.id', 'new-tag')
->assertNoAccessibilityIssues(level: 2); ->assertNoAccessibilityIssues(level: 2);
}); });
it('has no accessibility issues on the quick intake, also with errors', function (string $device, string $colorScheme) {
$visit = visit(route('jobs.quick'));
$visit = $device === 'mobile' ? $visit->on()->mobile() : $visit->on()->desktop();
$visit = $colorScheme === 'dark' ? $visit->inDarkMode() : $visit->inLightMode();
$visit->assertNoJavaScriptErrors()
->assertNoAccessibilityIssues(level: 2)
->press('Tallenna työ')
->assertSee('Valitse palveluyksikkö.')
->assertNoAccessibilityIssues(level: 2);
})->with([
'desktop, light' => ['desktop', 'light'],
'desktop, dark' => ['desktop', 'dark'],
'mobile, light' => ['mobile', 'light'],
'mobile, dark' => ['mobile', 'dark'],
]);
it('takes in a job on a phone with the keyboard alone', function () {
$unit = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
visit(route('jobs.quick'))
->on()->mobile()
->type('#customer-search', 'Mainos')
->assertSee('1 osuma.')
->keys('[aria-label="Valitse Mainos Oy"]', 'Enter')
->assertScript('document.activeElement.id', 'change-customer')
->type('[wire\:model="form.name"]', 'Kevätkampanja')
->select('[wire\:model="form.service_unit_id"]', (string) $unit->id)
->keys('[wire\:model="form.name"]', 'Enter')
->assertSee('Kevätkampanja luotu.')
->assertScript('document.activeElement.id', 'quick-created')
->assertNoAccessibilityIssues(level: 2);
});
@@ -0,0 +1,90 @@
<?php
use App\Models\User;
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\DB;
use Livewire\Livewire;
uses(RefreshDatabase::class);
beforeEach(function () {
$this->employee = User::factory()->create(['name' => 'Eero Työntekijä']);
$this->actingAs($this->employee);
$this->customer = CustomerModel::factory()->create(['name' => 'Mainos Oy']);
$this->unit = ServiceUnitModel::query()->where('name', 'Markkinointi')->sole();
});
it('opens a job with the required fields and the defaults, then clears the form', function () {
$this->get(route('jobs.quick'))->assertOk()->assertSee('Pikavastaanotto');
Livewire::test('jobs::quick')
->assertSet('form.responsible_user_id', (string) $this->employee->id)
->call('selectCustomer', $this->customer->id)
->set('form.name', 'Kevätkampanja')
->set('form.description', 'Some-mainokset huhtikuulle.')
->set('form.service_unit_id', (string) $this->unit->id)
->set('form.status', 'prospect')
->call('save')
->assertHasNoErrors()
->assertSee('Asiakastyö '.now()->year.'-0001 Kevätkampanja luotu.')
->assertSee('Avaa työ '.now()->year.'-0001')
->assertSee('Täydennä tietoja')
->assertSet('form.name', '')
->assertSet('form.customer_id', '')
->assertSet('form.status', 'prospect')
->assertSet('form.responsible_user_id', (string) $this->employee->id);
$job = CustomerJobModel::query()->sole();
expect($job->status->value)->toBe('prospect')
->and($job->priority->value)->toBe('normal')
->and($job->kind->value)->toBe('one_off')
->and($job->customer_id)->toBe($this->customer->id)
->and(DB::table('customer_job_service_unit')->where('customer_job_id', $job->id)->pluck('service_unit_id')->all())->toBe([$this->unit->id])
->and(DB::table('customer_job_changes')->where('customer_job_id', $job->id)->value('field'))->toBe('created');
});
it('adds a new customer during intake', function () {
Livewire::test('jobs::quick')
->set('customerSearch', 'Kahvila Kulma')
->call('createCustomer')
->assertSee('Asiakas Kahvila Kulma lisätty ja valittu.')
->set('form.name', 'Ruokalistan kuvaus')
->set('form.service_unit_id', (string) $this->unit->id)
->call('save')
->assertHasNoErrors();
expect(CustomerJobModel::query()->sole()->customer_id)
->toBe(CustomerModel::query()->where('name', 'Kahvila Kulma')->sole()->id);
});
it('shows Finnish errors for missing fields and does not accept other statuses', function () {
Livewire::test('jobs::quick')
->set('form.responsible_user_id', '')
->call('save')
->assertHasErrors(['form.customer_id', 'form.name', 'form.service_unit_id', 'form.responsible_user_id'])
->assertSee('Valitse asiakas tai lisää uusi.')
->assertSee('Valitse palveluyksikkö.');
Livewire::test('jobs::quick')
->call('selectCustomer', $this->customer->id)
->set('form.name', 'Työ')
->set('form.service_unit_id', (string) $this->unit->id)
->set('form.status', 'billed')
->call('save')
->assertHasErrors(['form.status']);
expect(CustomerJobModel::query()->count())->toBe(0);
});
it('keeps subcontractors out and shows the menu link only to those who may open jobs', function () {
$this->get(route('jobs.index'))->assertSee('Pikavastaanotto');
$this->actingAs(User::factory()->subcontractor()->create());
$this->get(route('jobs.quick'))->assertForbidden();
$this->get(route('jobs.index'))->assertDontSee('Pikavastaanotto');
});