-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11073 from demarches-simplifiees/confirm_FC_email
ETQ Usager, mon email est dit fiable lorsque qu'il provient de FC et que je l'ai visuellement vérifié
- Loading branch information
Showing
12 changed files
with
173 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 46 additions & 16 deletions
62
app/javascript/controllers/email_france_connect_controller.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,63 @@ | ||
import { ApplicationController } from './application_controller'; | ||
|
||
export class EmailFranceConnectController extends ApplicationController { | ||
static targets = ['useFranceConnectEmail', 'emailField']; | ||
static targets = [ | ||
'useFranceConnectEmail', | ||
'emailField', | ||
'submit', | ||
'emailInput', | ||
'form' | ||
]; | ||
|
||
emailFieldTarget!: HTMLElement; | ||
useFranceConnectEmailTargets!: HTMLInputElement[]; | ||
submitTarget!: HTMLButtonElement; | ||
emailInputTarget!: HTMLInputElement; | ||
formTarget!: HTMLFormElement; | ||
|
||
connect() { | ||
this.triggerEmailField(); | ||
} | ||
fcEmailPathValue!: string; | ||
customEmailPathValue!: string; | ||
|
||
static values = { | ||
fcEmailPath: String, | ||
customEmailPath: String | ||
}; | ||
|
||
triggerEmailField() { | ||
const checkedTarget = this.useFranceConnectEmailTargets.find( | ||
(target) => target.checked | ||
); | ||
if (this.useFCEmail()) { | ||
this.emailFieldTarget.classList.add('hidden'); | ||
this.emailFieldTarget.setAttribute('aria-hidden', 'true'); | ||
|
||
const inputElement = this.emailFieldTarget.querySelector( | ||
'input[type="email"]' | ||
) as HTMLInputElement; | ||
this.emailInputTarget.removeAttribute('required'); | ||
this.emailInputTarget.value = ''; | ||
|
||
if (checkedTarget && checkedTarget.value === 'false') { | ||
this.formTarget.action = this.fcEmailPathValue; | ||
} else { | ||
this.emailFieldTarget.classList.remove('hidden'); | ||
this.emailFieldTarget.setAttribute('aria-hidden', 'false'); | ||
inputElement.setAttribute('required', ''); | ||
|
||
this.emailInputTarget.setAttribute('required', ''); | ||
|
||
this.formTarget.action = this.customEmailPathValue; | ||
} | ||
} | ||
|
||
triggerSubmitDisabled() { | ||
if (this.useFCEmail() || this.isEmailInputFilled()) { | ||
this.submitTarget.disabled = false; | ||
} else { | ||
this.emailFieldTarget.classList.add('hidden'); | ||
this.emailFieldTarget.setAttribute('aria-hidden', 'true'); | ||
inputElement.removeAttribute('required'); | ||
inputElement.value = ''; | ||
this.submitTarget.disabled = true; | ||
} | ||
} | ||
|
||
useFCEmail() { | ||
return ( | ||
this.useFranceConnectEmailTargets.find((target) => target.checked) | ||
?.value === 'true' || false | ||
); | ||
} | ||
|
||
isEmailInputFilled() { | ||
return this.emailInputTarget.value.length > 0; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 0 additions & 12 deletions
12
app/views/france_connect/particulier/confirmation_sent.html.haml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.