1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Add register_fields and additional_fields to Register class

This commit is contained in:
Benjamin Beganović 2024-04-01 19:05:01 +02:00
parent ce400365a5
commit 6c6dd8f957

View File

@ -34,6 +34,10 @@ class Register extends Component
'register_form' => false, 'register_form' => false,
]; ];
public array $register_fields = [];
public array $additional_fields = [];
public function initial(): void public function initial(): void
{ {
$this->validateOnly('email', ['email' => 'required|bail|email:rfc']); $this->validateOnly('email', ['email' => 'required|bail|email:rfc']);
@ -57,6 +61,7 @@ class Register extends Component
{ {
$service = new ClientRegisterService( $service = new ClientRegisterService(
company: $this->subscription->company, company: $this->subscription->company,
additional: $this->additional_fields,
); );
$rules = $service->rules(); $rules = $service->rules();
@ -94,6 +99,43 @@ class Register extends Component
return; return;
} }
$this->register_fields = [...collect($this->subscription->company->client_registration_fields ?? [])->toArray()];
$first_gateway = collect($this->subscription->company->company_gateways)
->sortBy('sort_order')
->first();
$mappings = ClientRegisterService::mappings();
collect($first_gateway->driver()->getClientRequiredFields() ?? [])
->each(function ($field) use ($mappings) {
$mapping = $mappings[$field['name']] ?? null;
if ($mapping === null) {
return;
}
$i = collect($this->register_fields)->search(fn ($field) => $field['key'] == $mapping);
if ($i !== false) {
$this->register_fields[$i]['visible'] = true;
$this->register_fields[$i]['required'] = true;
$this->additional_fields[] = $this->register_fields[$i];
} else {
$field = [
'key' => $mapping,
'required' => true,
'visible' => true,
];
$this->register_fields[] = $field;
$this->additional_fields[] = $field;
}
})
->toArray();
return $this->state['register_form'] = true; return $this->state['register_form'] = true;
} }