Skip to content

Commit

Permalink
♻️ certif: refacto login form to gjs
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandrecoin authored Aug 14, 2024
1 parent cc202ea commit f844fc0
Show file tree
Hide file tree
Showing 15 changed files with 314 additions and 340 deletions.
43 changes: 43 additions & 0 deletions certif/app/components/language-switcher.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import PixSelect from '@1024pix/pix-ui/components/pix-select';
import { service } from '@ember/service';
import Component from '@glimmer/component';
import { t } from 'ember-intl';
import { FRENCH_INTERNATIONAL_LOCALE } from 'pix-certif/services/locale';

export default class LanguageSwitcher extends Component {
@service locale;

get alphabeticallySortedLanguages() {
const availableLanguages = this.locale.getAvailableLanguages();

const options = Object.entries(availableLanguages)
.filter(([_, config]) => config.languageSwitcherDisplayed)
.map(([key, config]) => ({
label: config.value,
value: key,
}));

const optionsWithoutFrSortedByLabel = options
.filter((option) => option.value !== FRENCH_INTERNATIONAL_LOCALE)
.sort((option) => option.label);

const frenchLanguageOption = options.find((option) => option.value === FRENCH_INTERNATIONAL_LOCALE);

return [frenchLanguageOption, ...optionsWithoutFrSortedByLabel];
}

<template>
<PixSelect
@id='language-switcher'
@icon='earth-europe'
@value={{@selectedLanguage}}
@options={{this.alphabeticallySortedLanguages}}
@onChange={{@onLanguageChange}}
@hideDefaultOption='true'
@screenReaderOnly='true'
...attributes
>
<:label>{{t 'common.forms.login.choose-language-aria-label'}}</:label>
</PixSelect>
</template>
}
12 changes: 0 additions & 12 deletions certif/app/components/language-switcher.hbs

This file was deleted.

35 changes: 0 additions & 35 deletions certif/app/components/language-switcher.js

This file was deleted.

67 changes: 0 additions & 67 deletions certif/app/components/login-form.hbs

This file was deleted.

44 changes: 44 additions & 0 deletions certif/app/components/login/form.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import PixButton from '@1024pix/pix-ui/components/pix-button';
import PixInput from '@1024pix/pix-ui/components/pix-input';
import PixInputPassword from '@1024pix/pix-ui/components/pix-input-password';
import { on } from '@ember/modifier';
import { t } from 'ember-intl';

<template>
<form class='login-main__form' {{on 'submit' @onSubmit}}>

<p class='login-main-form__mandatory-information'>
{{t 'common.form-errors.mandatory-all-fields'}}
</p>

<PixInput @id='login-email' name='login' autocomplete='email' type='email' required='true' {{on 'input' @setEmail}}>
<:label>{{t 'common.forms.login.email'}}</:label>
</PixInput>

<PixInputPassword
@id='login-password'
name='password'
autocomplete='current-password'
required='true'
{{on 'input' @setPassword}}
>
<:label>{{t 'common.forms.login.password'}}</:label>
</PixInputPassword>

{{#if @isErrorMessagePresent}}
<div class='error-message'>
<p>{{@errorMessage}}</p>
</div>
{{/if}}

<PixButton @type='submit' class='login-main-form__button'>
{{t 'pages.login.actions.login.label'}}
</PixButton>

<div class='login-main-form__forgotten-password'>
<a href={{@forgottenPasswordUrl}} target='_blank' rel='noopener noreferrer' class='link'>{{t
'common.forms.login.forgot-password'
}}</a>
</div>
</form>
</template>
21 changes: 21 additions & 0 deletions certif/app/components/login/header.gjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { t } from 'ember-intl';

<template>
<header class='login__header'>
<img src='/pix-certif-logo.svg' alt='Pix Certif' />

<h1 class='page-title'>{{t 'pages.login.title'}}</h1>

<p class='login-header__information'>
{{t 'pages.login.accessible-to'}}
</p>

{{#if @hasInvitationAlreadyBeenAccepted}}
<p class='login-header__invitation-error'>{{t 'pages.login.errors.invitation-already-accepted' htmlSafe=true}}</p>
{{/if}}

{{#if @isInvitationCancelled}}
<p class='login-header__invitation-error'>{{t 'pages.login.errors.invitation-was-cancelled' htmlSafe=true}}</p>
{{/if}}
</header>
</template>
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ import { tracked } from '@glimmer/tracking';
import get from 'lodash/get';
import ENV from 'pix-certif/config/environment';

export default class LoginForm extends Component {
import LoginForm from './form';
import LoginHeader from './header';

export default class Login extends Component {
@service url;
@service intl;
@service session;
Expand Down Expand Up @@ -87,4 +90,25 @@ export default class LoginForm extends Component {
return ENV.APP.API_ERROR_MESSAGES.INTERNAL_SERVER_ERROR.I18N_KEY;
}
}

<template>
<div class='login'>
<LoginHeader
@hasInvitationAlreadyBeenAccepted={{@hasInvitationAlreadyBeenAccepted}}
@isInvitationCancelled={{@isInvitationCancelled}}
/>

<main class='login__main'>

<LoginForm
@onSubmit={{this.authenticate}}
@setEmail={{this.setEmail}}
@setPassword={{this.setPassword}}
@isErrorMessagePresent={{this.isErrorMessagePresent}}
@errorMessage={{this.errorMessage}}
@forgottenPasswordUrl={{this.forgottenPasswordUrl}}
/>
</main>
</div>
</template>
}
4 changes: 4 additions & 0 deletions certif/app/services/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class LocaleService extends Service {
@service intl;
@service dayjs;

getAvailableLanguages() {
return languages;
}

handleUnsupportedLanguage(language) {
if (!language) return;
return this.isLanguageSupported(language) ? language : DEFAULT_LOCALE;
Expand Down
2 changes: 1 addition & 1 deletion certif/app/templates/login.hbs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{{page-title (t "pages.login.title")}}
<main class="login-page">
<div>
<LoginForm
<Login
@hasInvitationAlreadyBeenAccepted={{this.hasInvitationAlreadyBeenAccepted}}
@isInvitationCancelled={{this.isInvitationCancelled}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ module('Integration | Component | Auth::ToggableLoginForm', function (hooks) {
// then
assert.dom(screen.getByRole('textbox', { name: emailInputLabel })).exists();
assert.dom(screen.getByLabelText(passwordInputLabel)).exists();
assert.dom(screen.getByText(loginLabel)).exists();
});

test('[a11y] it should display a message that all inputs are required', async function (assert) {
Expand Down
Loading

0 comments on commit f844fc0

Please sign in to comment.