authorize('jobs.manage'); $this->inDialog = $inDialog; $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, )); } /** * @return list */ #[Computed] public function contacts(): array { return $this->form->customer_id === '' ? [] : app(CustomerQueries::class)->contactsOf((int) $this->form->customer_id); } public function save(CreateCustomerJob $createJob, CustomerJobQueries $jobQueries, AddContact $addContact): void { $this->authorize('jobs.manage'); $this->form->validate(); if ($this->form->adding_contact && trim($this->form->new_contact_name) !== '') { $this->authorize('customers.use'); try { $contactId = $addContact->execute((int) $this->form->customer_id, new ContactData( name: trim($this->form->new_contact_name), phone: trim($this->form->new_contact_phone) === '' ? null : trim($this->form->new_contact_phone), )); } catch (DomainException) { $this->addError('form.new_contact_name', __('jobs.quick.contact_name_required')); return; } $this->form->customer_contact_id = (string) $contactId; $this->form->adding_contact = false; unset($this->contacts); } $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 = ''; unset($this->contacts); if ($this->inDialog) { $this->dispatch('quick-job-created', status: $data->status); $this->dispatch('job-editor-saved', message: $this->createdMessage); $this->js("document.getElementById('".self::DIALOG."').close()"); return; } $this->js("document.getElementById('quick-created')?.focus()"); } public function render(): mixed { return $this->view()->title(__('jobs.quick.title')); } /** * A contact person of another customer no longer fits. */ protected function customerChosen(?int $customerId): void { $this->form->customer_contact_id = ''; unset($this->contacts); } }; ?>
! $inDialog])> @unless ($inDialog)
{{ __('jobs.quick.title') }}

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

@if ($createdJobId !== null)

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

@endif
@endunless

$inDialog])>{{ $statusMessage }}

! $inDialog, 'space-y-4 px-5 pb-5' => $inDialog]) novalidate>
@foreach ($this->contacts as $contact) @endforeach
@if ($form->customer_id !== '') @endif
@if ($form->adding_contact && $form->customer_id !== '')
@endif
{{-- 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 @foreach (QuickJobForm::startStatuses() as $status) @endforeach @foreach (Priority::cases() as $priority) @endforeach
@if ($inDialog)
@else @endif