Fix: allow custom email (!), require a mail confirmation
previous code was wrong, it was impossible to choose another email than the FC one
This commit is contained in:
parent
4cd6e08a3d
commit
2a25171738
2 changed files with 28 additions and 5 deletions
|
@ -1,12 +1,27 @@
|
|||
import { ApplicationController } from './application_controller';
|
||||
|
||||
export class EmailFranceConnectController extends ApplicationController {
|
||||
static targets = ['useFranceConnectEmail', 'emailField', 'submit', 'emailInput'];
|
||||
static targets = [
|
||||
'useFranceConnectEmail',
|
||||
'emailField',
|
||||
'submit',
|
||||
'emailInput',
|
||||
'form'
|
||||
];
|
||||
|
||||
emailFieldTarget!: HTMLElement;
|
||||
useFranceConnectEmailTargets!: HTMLInputElement[];
|
||||
submitTarget!: HTMLButtonElement;
|
||||
emailInputTarget!: HTMLInputElement;
|
||||
formTarget!: HTMLFormElement;
|
||||
|
||||
fcEmailPathValue!: string;
|
||||
customEmailPathValue!: string;
|
||||
|
||||
static values = {
|
||||
fcEmailPath: String,
|
||||
customEmailPath: String
|
||||
};
|
||||
|
||||
triggerEmailField() {
|
||||
if (this.useFCEmail()) {
|
||||
|
@ -15,11 +30,15 @@ export class EmailFranceConnectController extends ApplicationController {
|
|||
|
||||
this.emailInputTarget.removeAttribute('required');
|
||||
this.emailInputTarget.value = '';
|
||||
|
||||
this.formTarget.action = this.fcEmailPathValue;
|
||||
} else {
|
||||
this.emailFieldTarget.classList.remove('hidden');
|
||||
this.emailFieldTarget.setAttribute('aria-hidden', 'false');
|
||||
|
||||
this.emailInputTarget.setAttribute('required', '');
|
||||
|
||||
this.formTarget.action = this.customEmailPathValue;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -32,9 +51,10 @@ export class EmailFranceConnectController extends ApplicationController {
|
|||
}
|
||||
|
||||
useFCEmail() {
|
||||
return this.useFranceConnectEmailTargets.find(
|
||||
(target) => target.checked
|
||||
)?.value === 'true' || false;
|
||||
return (
|
||||
this.useFranceConnectEmailTargets.find((target) => target.checked)
|
||||
?.value === 'true' || false
|
||||
);
|
||||
}
|
||||
|
||||
isEmailInputFilled() {
|
||||
|
|
|
@ -11,7 +11,10 @@
|
|||
%fieldset.fr-fieldset
|
||||
= form_with url: france_connect_particulier_merge_using_fc_email_path,
|
||||
method: :post,
|
||||
data: { controller: 'email-france-connect' } do |f|
|
||||
data: { controller: 'email-france-connect',
|
||||
email_france_connect_fc_email_path_value: france_connect_particulier_merge_using_fc_email_path,
|
||||
email_france_connect_custom_email_path_value: france_connect_particulier_send_email_merge_request_path,
|
||||
email_france_connect_target: "form" } do |f|
|
||||
|
||||
= hidden_field_tag :merge_token, @fci.merge_token
|
||||
|
||||
|
|
Loading…
Reference in a new issue