From 379ac0991d475fd9c3f336a2e9c6b207efac9efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Beganovi=C4=87?= Date: Wed, 13 Mar 2024 19:24:36 +0100 Subject: [PATCH] Refactor registerForm method in Register.php --- .../BillingPortal/Authentication/Register.php | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/app/Livewire/BillingPortal/Authentication/Register.php b/app/Livewire/BillingPortal/Authentication/Register.php index c8e76762d3b6..5d75475363f4 100644 --- a/app/Livewire/BillingPortal/Authentication/Register.php +++ b/app/Livewire/BillingPortal/Authentication/Register.php @@ -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()) {