diff --git a/CLAUDE.md b/CLAUDE.md index c41b549..9f30302 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -39,7 +39,7 @@ Accessibility is a contractual acceptance criterion. It covers the whole UI: nav - ``: root-relative asset URLs that 404 in a subfolder (local XAMPP). The layout includes `resources/views/partials/tallstackui-script.blade.php` instead. - ``: the label is not tied to the control, so also pass `:aria-label` with the same text. - ``: `aria-labelledby` points at an id its title lacks, the close button has no name, and focus neither moves in nor returns. Use `` (`resources/views/components/confirm-dialog.blade.php`, native `` + `showModal()`), opened from Livewire with `$this->js("document.getElementById('').showModal()")`; see `customers::show`. - - Groups of checkboxes for an array property: `` (`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 ``. + - Groups of checkboxes for an array property: `` (`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 ``: for customers use the `PicksCustomer` trait (`app/Modules/Jobs/Presentation/Livewire/Concerns`) with ``. - Solid `color="red"` buttons: white on red-500 is 3.5:1, so the solid red is red-700 in the published `NormalButtonColors`. - `` without `wire:model` (e.g. a read-only value): pass an explicit `id`, or the label is not tied to it. `` has an unlabelled input and a button whose name changes; build copy fields from `` + `` + 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. diff --git a/app/Modules/Jobs/Presentation/Livewire/Concerns/PicksCustomer.php b/app/Modules/Jobs/Presentation/Livewire/Concerns/PicksCustomer.php new file mode 100644 index 0000000..d157f79 --- /dev/null +++ b/app/Modules/Jobs/Presentation/Livewire/Concerns/PicksCustomer.php @@ -0,0 +1,102 @@ +: + * 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 $customerResults + */ +trait PicksCustomer +{ + public string $customerSearch = ''; + + #[Locked] + public string $customerName = ''; + + public string $statusMessage = ''; + + /** + * @return list + */ + #[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()"); + } +} diff --git a/app/Modules/Jobs/Presentation/Livewire/Forms/QuickJobForm.php b/app/Modules/Jobs/Presentation/Livewire/Forms/QuickJobForm.php new file mode 100644 index 0000000..0302beb --- /dev/null +++ b/app/Modules/Jobs/Presentation/Livewire/Forms/QuickJobForm.php @@ -0,0 +1,105 @@ +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> + */ + 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 + */ + 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'), + ]; + } +} diff --git a/app/Modules/Jobs/Presentation/Livewire/⚡form.blade.php b/app/Modules/Jobs/Presentation/Livewire/⚡form.blade.php index f9d32fe..c9c6000 100644 --- a/app/Modules/Jobs/Presentation/Livewire/⚡form.blade.php +++ b/app/Modules/Jobs/Presentation/Livewire/⚡form.blade.php @@ -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 - */ - #[Computed] - public function customerResults(): array - { - $term = trim($this->customerSearch); - - return mb_strlen($term) < 2 ? [] : app(CustomerQueries::class)->search($term, 8); - } - /** * @return list */ @@ -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 - {{-- Customer: search field and results as buttons, or the chosen customer. --}} -
- @if ($form->customer_id !== '') -

{{ __('jobs.fields.customer') }}

-
- {{ $customerName }} - -
- @else - - - @error('form.customer_id') -

{{ $message }}

- @enderror - - @if (mb_strlen(trim($customerSearch)) >= 2) -

- {{ trans_choice('jobs.customer_picker.results', count($this->customerResults), ['count' => count($this->customerResults)]) }} -

- -
    - @foreach ($this->customerResults as $customer) -
  • - -
  • - @endforeach -
- - @can('customers.use') - - @endcan - @endif - @endif -
+ diff --git a/app/Modules/Jobs/Presentation/Livewire/⚡index.blade.php b/app/Modules/Jobs/Presentation/Livewire/⚡index.blade.php index f7de9f5..4daa297 100644 --- a/app/Modules/Jobs/Presentation/Livewire/⚡index.blade.php +++ b/app/Modules/Jobs/Presentation/Livewire/⚡index.blade.php @@ -102,7 +102,10 @@ new class extends Component

{{ __('jobs.title') }}

@can('jobs.manage') - +
+ + +
@endcan diff --git a/app/Modules/Jobs/Presentation/Livewire/⚡quick.blade.php b/app/Modules/Jobs/Presentation/Livewire/⚡quick.blade.php new file mode 100644 index 0000000..e8cb145 --- /dev/null +++ b/app/Modules/Jobs/Presentation/Livewire/⚡quick.blade.php @@ -0,0 +1,165 @@ +authorize('jobs.manage'); + + $this->form->responsible_user_id = (string) auth()->id(); + } + + /** + * @return list + */ + #[Computed] + public function serviceUnits(): array + { + return app(CatalogQueries::class)->activeServiceUnits(); + } + + /** + * Users who can be responsible for a job (not subcontractors). + * + * @return list + */ + #[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')); + } +}; +?> + +
+
+

{{ __('jobs.quick.title') }}

+

{{ __('jobs.quick.intro') }}

+
+ +
+ @if ($createdJobId !== null) +
+

+

+

+ {{ __('jobs.quick.open', ['number' => $createdNumber]) }} + {{ __('jobs.quick.complete') }} +

+
+ @endif +
+ +

{{ $statusMessage }}

+ +
+ + + + + + + {{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}} + + + @foreach ($this->serviceUnits as $unit) + + @endforeach + + + + + @foreach ($this->staff as $user) + + @endforeach + + + + + + +
diff --git a/app/Modules/Jobs/Presentation/Routes/web.php b/app/Modules/Jobs/Presentation/Routes/web.php index b29f1ff..87b4818 100644 --- a/app/Modules/Jobs/Presentation/Routes/web.php +++ b/app/Modules/Jobs/Presentation/Routes/web.php @@ -8,6 +8,7 @@ Route::middleware(['web', 'auth', 'can:jobs.view']) ->group(function () { Route::livewire('/', 'jobs::index')->name('index'); 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}/edit', 'jobs::form')->whereNumber('job')->middleware('can:jobs.manage')->name('edit'); }); diff --git a/docs/maarittely.md b/docs/maarittely.md index 8a55da9..9f9bb10 100644 --- a/docs/maarittely.md +++ b/docs/maarittely.md @@ -204,7 +204,9 @@ Asiakastyön kenttien muutokset tallennetaan: kuka, milloin, mikä kenttä, vanh - 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. -- 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. ## 7. Pikamyynti *(K19)* @@ -411,7 +413,7 @@ Jokainen sivu täyttää saavutettavuusvaatimukset ja saa selaintestin (vaalea/t - Muutoshistoria näkyy työn sivulla. ### 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 - Sarakkeet tiloittain, arkistoitu pois. Kortin tila vaihdetaan vetämällä tai kortin valikosta (näppäimistö). Muutos ilmoitetaan `aria-live`-alueella. diff --git a/lang/fi/jobs.php b/lang/fi/jobs.php index 2792208..e2dd6c6 100644 --- a/lang/fi/jobs.php +++ b/lang/fi/jobs.php @@ -14,6 +14,18 @@ return [ 'late' => 'Myöhässä', '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' => [ 'search' => 'Hae asiakastyötä', 'search_description' => 'Hae numerolla, nimellä tai asiakkaan nimellä.', diff --git a/lang/fi/layout.php b/lang/fi/layout.php index d006f20..0df2f8e 100644 --- a/lang/fi/layout.php +++ b/lang/fi/layout.php @@ -5,6 +5,7 @@ return [ 'main_menu' => 'Päävalikko', 'home' => 'Etusivu', 'jobs' => 'Asiakastyöt', + 'quick_intake' => 'Pikavastaanotto', 'customers' => 'Asiakkaat', 'users' => 'Käyttäjät', 'catalog' => 'Pohjatiedot', diff --git a/phpstan.neon b/phpstan.neon index 598c435..a8dfa66 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -8,3 +8,8 @@ parameters: excludePaths: # Livewire single-file components mix PHP and Blade, so PHPStan cannot analyse them. - 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/* diff --git a/resources/views/components/jobs/customer-picker.blade.php b/resources/views/components/jobs/customer-picker.blade.php new file mode 100644 index 0000000..c8133d1 --- /dev/null +++ b/resources/views/components/jobs/customer-picker.blade.php @@ -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', +]) + +
class('space-y-2') }}> + @if ($customerId !== '') +

{{ __('jobs.fields.customer') }}

+
+ {{ $customerName }} + +
+ @else + + + @error($errorKey) +

{{ $message }}

+ @enderror + + @if (mb_strlen(trim($search)) >= 2) +

+ {{ trans_choice('jobs.customer_picker.results', count($results), ['count' => count($results)]) }} +

+ +
    + @foreach ($results as $customer) +
  • + +
  • + @endforeach +
+ + @can('customers.use') + + @endcan + @endif + @endif +
diff --git a/resources/views/layouts/app.blade.php b/resources/views/layouts/app.blade.php index ab09f66..27c74e6 100644 --- a/resources/views/layouts/app.blade.php +++ b/resources/views/layouts/app.blade.php @@ -55,7 +55,11 @@