mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Refactor register form logic in RegisterOrLogin component
This commit is contained in:
parent
46bd2be274
commit
dbf5b4166e
@ -70,7 +70,7 @@ class RegisterOrLogin extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->state['login_form'] = false;
|
$this->state['login_form'] = false;
|
||||||
$this->state['register_form'] = true;
|
$this->registerForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function handlePassword()
|
public function handlePassword()
|
||||||
@ -100,7 +100,7 @@ class RegisterOrLogin extends Component
|
|||||||
->first();
|
->first();
|
||||||
|
|
||||||
if ($contact === null) {
|
if ($contact === null) {
|
||||||
$this->state['register_form'] = true;
|
$this->registerForm();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -157,7 +157,7 @@ class RegisterOrLogin extends Component
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->state['otp_form'] = false;
|
$this->state['otp_form'] = false;
|
||||||
$this->state['register_form'] = true;
|
$this->registerForm();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function register(array $data)
|
public function register(array $data)
|
||||||
@ -165,8 +165,8 @@ class RegisterOrLogin extends Component
|
|||||||
$service = new ClientRegisterService(
|
$service = new ClientRegisterService(
|
||||||
company: $this->subscription->company,
|
company: $this->subscription->company,
|
||||||
);
|
);
|
||||||
|
|
||||||
$rules = $service->rules();
|
$rules = $service->rules();
|
||||||
$data = Validator::make($data, $rules)->validate();
|
$data = Validator::make($data, $rules)->validate();
|
||||||
|
|
||||||
$client = $service->createClient($data);
|
$client = $service->createClient($data);
|
||||||
@ -178,11 +178,38 @@ class RegisterOrLogin extends Component
|
|||||||
$this->dispatch('purchase.next');
|
$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()
|
public function mount()
|
||||||
{
|
{
|
||||||
if (auth()->guard('contact')->check()) {
|
if (auth()->guard('contact')->check()) {
|
||||||
$this->dispatch('purchase.context', property: 'contact', value: auth()->guard('contact')->user());
|
$this->dispatch('purchase.context', property: 'contact', value: auth()->guard('contact')->user());
|
||||||
$this->dispatch('purchase.next');
|
$this->dispatch('purchase.next');
|
||||||
|
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user