mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-07 10:17:30 -04:00
Duplicate filtering & parsing
This commit is contained in:
parent
dd9f1b1afe
commit
489489301b
@ -41,7 +41,6 @@ class RegisterOrLogin extends Component
|
|||||||
'initial_completed' => false,
|
'initial_completed' => false,
|
||||||
];
|
];
|
||||||
|
|
||||||
public array $registration_fields = [];
|
|
||||||
public array $fields = [];
|
public array $fields = [];
|
||||||
|
|
||||||
public function initial()
|
public function initial()
|
||||||
@ -198,38 +197,44 @@ class RegisterOrLogin extends Component
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$first_gateway = collect($this->subscription->company->company_gateways)
|
$this->fields = [...collect($this->subscription->company->client_registration_fields ?? [])->toArray()];
|
||||||
->sortBy('sort_order')
|
|
||||||
->first();
|
|
||||||
|
|
||||||
$gateway_fields = $first_gateway->driver()->getClientRequiredFields() ?? [];
|
$registration_keys = collect($this->fields)->pluck('key')->toArray();
|
||||||
$registration_fields = $this->subscription->company->client_registration_fields ?? [];
|
|
||||||
|
|
||||||
$mappings = [
|
$mappings = [
|
||||||
'contact_first_name' => 'first_name',
|
'contact_first_name' => 'first_name',
|
||||||
'contact_last_name' => 'last_name',
|
'contact_last_name' => 'last_name',
|
||||||
'contact_email' => 'email',
|
'contact_email' => 'email',
|
||||||
|
'client_city' => 'city',
|
||||||
|
'client_address_line_1' => 'address1',
|
||||||
];
|
];
|
||||||
|
|
||||||
$gateway_fields_keys = collect($gateway_fields)->map(fn($field) => $field['name'])->toArray();
|
$first_gateway = collect($this->subscription->company->company_gateways)
|
||||||
$registration_fields_keys = collect($registration_fields)->map(fn($field) => $field['key'])->toArray();
|
->sortBy('sort_order')
|
||||||
|
->first();
|
||||||
|
|
||||||
foreach ($gateway_fields_keys as $key) {
|
$gateway_fields = collect($first_gateway->driver()->getClientRequiredFields() ?? [])->map(function ($field) {
|
||||||
$mapping = $mappings[$key] ?? null;
|
return [
|
||||||
|
'key' => $field['name'],
|
||||||
|
'required' => true,
|
||||||
|
'visible' => true,
|
||||||
|
'label' => str_replace(['client_', 'contact_'], '', $field['name'])
|
||||||
|
];
|
||||||
|
})->toArray();
|
||||||
|
|
||||||
if ($mapping === null) {
|
$gateway_fields = collect($gateway_fields)
|
||||||
continue;
|
->filter(function ($field) use ($registration_keys, $mappings) {
|
||||||
}
|
$mapping = $mappings[$field['key']] ?? null;
|
||||||
|
|
||||||
$field = collect($registration_fields)->first(fn($field) => $field['key'] === $mappings[$key]);
|
if ($mapping === null) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (in_array($mappings[$key], $registration_fields_keys) && $field['required'] === true) {
|
return !in_array($mapping, $registration_keys);
|
||||||
unset($gateway_fields[array_search($key, $gateway_fields_keys)]);
|
})
|
||||||
}
|
->toArray();
|
||||||
}
|
|
||||||
|
|
||||||
$this->fields = $gateway_fields;
|
$this->fields = array_merge($this->fields, $gateway_fields);
|
||||||
$this->registration_fields = $registration_fields;
|
|
||||||
|
|
||||||
return $this->state['register_form'] = true;
|
return $this->state['register_form'] = true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user