1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02: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,
];
public array $register_fields = [];
public array $additional_fields = [];
public function initial(): void
{
$this->validateOnly('email', ['email' => 'required|bail|email:rfc']);
@ -57,6 +61,7 @@ class Register extends Component
{
$service = new ClientRegisterService(
company: $this->subscription->company,
additional: $this->additional_fields,
);
$rules = $service->rules();
@ -94,6 +99,43 @@ class Register extends Component
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;
}