diff --git a/app/javascript/controllers/email_france_connect_controller.ts b/app/javascript/controllers/email_france_connect_controller.ts index 7fe74cee5..a5675a56e 100644 --- a/app/javascript/controllers/email_france_connect_controller.ts +++ b/app/javascript/controllers/email_france_connect_controller.ts @@ -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() { diff --git a/app/views/france_connect/particulier/choose_email.html.haml b/app/views/france_connect/particulier/choose_email.html.haml index da8ae565f..ce1118a7a 100644 --- a/app/views/france_connect/particulier/choose_email.html.haml +++ b/app/views/france_connect/particulier/choose_email.html.haml @@ -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