Refactor registerForm method in Register.php

This commit is contained in:
Benjamin Beganović 2024-03-13 19:24:36 +01:00
parent dbf5b4166e
commit 379ac0991d

View File

@ -60,7 +60,8 @@ class Register extends Component
}
$this->state['initial_completed'] = true;
$this->state['register_form'] = true;
$this->registerForm();
}
public function register(array $data)
@ -82,6 +83,31 @@ class Register extends Component
$this->dispatch('purchase.next');
}
public function registerForm()
{
$count = collect($this->subscription->company->client_registration_fields ?? [])
->filter(fn($field) => $field['required'] === true || $field['visible'] === true)
->count();
if ($count === 0) {
$service = new ClientRegisterService(
company: $this->subscription->company,
);
$client = $service->createClient([]);
$contact = $service->createClientContact([], $client);
auth()->guard('contact')->loginUsingId($contact->id, true);
$this->dispatch('purchase.context', property: 'contact', value: $contact);
$this->dispatch('purchase.next');
return;
}
return $this->steps['register_form'] = true;
}
public function mount()
{
if (auth()->guard('contact')->check()) {