Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGFIX] Sur Pix App .org corriger les liens vers le support qui ne sont pas bons sur les pages de réinitialisation du mot de passe (PIX-16033) #11065

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import PasswordResetDemandReceivedInfo from './password-reset-demand-received-in
export default class PasswordResetDemandForm extends Component {
@service errors;
@service requestManager;
@service url;

@tracked globalError = this.errors.hasErrors && this.errors.shift();
@tracked isLoading = false;
Expand Down Expand Up @@ -114,7 +115,7 @@ export default class PasswordResetDemandForm extends Component {
<section class="authentication-password-reset-demand-form__help">
<h2>
{{t "components.authentication.password-reset-demand-form.no-email-question"}}</h2>
<a href="{{t 'components.authentication.password-reset-demand-form.contact-us-link.link-url'}}">
<a href="{{this.url.supportHomeUrl}}">
{{t "components.authentication.password-reset-demand-form.contact-us-link.link-text"}}
</a>
</section>
Expand Down
11 changes: 11 additions & 0 deletions mon-pix/app/services/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export const ENGLISH_INTERNATIONAL_LOCALE = 'en';
export const FRENCH_FRANCE_LOCALE = 'fr-FR';
export const DEFAULT_LOCALE = FRENCH_INTERNATIONAL_LOCALE;

const SUPPORTED_LOCALES = ['en', 'es', 'fr', 'fr-BE', 'fr-FR', 'nl-BE', 'nl'];

const supportedLanguages = Object.keys(languages);

export default class LocaleService extends Service {
Expand All @@ -16,6 +18,15 @@ export default class LocaleService extends Service {
@service intl;
@service dayjs;

isSupportedLocale(locale) {
try {
const localeCanonicalName = Intl.getCanonicalLocales(locale)?.[0];
return SUPPORTED_LOCALES.some((supportedLocale) => localeCanonicalName == supportedLocale);
} catch {
return false;
}
}

handleUnsupportedLanguage(language) {
if (!language) return;
return supportedLanguages.includes(language) ? language : DEFAULT_LOCALE;
Expand Down
21 changes: 11 additions & 10 deletions mon-pix/app/services/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const SPANISH_INTERNATIONAL_LOCALE = 'es';
export default class Url extends Service {
@service currentDomain;
@service intl;
@service locale;

definedHomeUrl = ENV.rootURL;

Expand Down Expand Up @@ -108,22 +109,22 @@ export default class Url extends Service {
}

get supportHomeUrl() {
const currentLanguage = this.intl.primaryLocale;
const currentLocale = this.intl.primaryLocale;

if (this.currentDomain.isFranceDomain) {
return 'https://pix.fr/support';
}

switch (currentLanguage) {
case ENGLISH_INTERNATIONAL_LOCALE:
return 'https://pix.org/en/support';
case DUTCH_INTERNATIONAL_LOCALE:
return 'https://pix.org/nl-be/support';
case SPANISH_INTERNATIONAL_LOCALE:
return 'https://pix.org/en/support';
default:
return 'https://pix.org/fr/support';
let locale;
if (currentLocale == 'nl') {
locale = 'nl-BE';
} else if (this.locale.isSupportedLocale(currentLocale)) {
locale = currentLocale;
} else {
locale = ENGLISH_INTERNATIONAL_LOCALE;
}

return `https://pix.org/${locale}/support`;
}

get serverStatusUrl() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { fillByLabel, render } from '@1024pix/ember-testing-library';
import Service from '@ember/service';
import { click } from '@ember/test-helpers';
import { setLocale, t } from 'ember-intl/test-support';
import PasswordResetDemandForm from 'mon-pix/components/authentication/password-reset-demand/password-reset-demand-form';
Expand Down Expand Up @@ -30,6 +31,17 @@ module('Integration | Component | Authentication | PasswordResetDemand | passwor

test('it displays all elements of component successfully', async function (assert) {
// given
class CurrentDomainServiceStub extends Service {
get isFranceDomain() {
return true;
}

getExtension() {
return '.fr';
}
}
this.owner.register('service:currentDomain', CurrentDomainServiceStub);

const screen = await render(<template><PasswordResetDemandForm /></template>);

// then
Expand Down
54 changes: 54 additions & 0 deletions mon-pix/tests/unit/services/locale-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,60 @@ module('Unit | Services | locale', function (hooks) {
sinon.stub(intlService, 'setLocale');
});

module('#isSupportedLocale', function () {
module('when locale is supported', function () {
test('returns true', function (assert) {
// given
const locale = 'nl-BE';

// when
const result = localeService.isSupportedLocale(locale);

// then
assert.true(result);
});
});

module('when locale is supported but not given in canonical form', function () {
test('returns true', function (assert) {
// given
const locale = 'nl-be';

// when
const result = localeService.isSupportedLocale(locale);

// then
assert.true(result);
});
});

module('when locale is valid but not supported', function () {
test('returns false', function (assert) {
// given
const locale = 'ko';

// when
const result = localeService.isSupportedLocale(locale);

// then
assert.false(result);
});
});

module('when locale is invalid', function () {
test('returns false', function (assert) {
// given
const locale = 'invalid_locale_in_bad_format';

// when
const result = localeService.isSupportedLocale(locale);

// then
assert.false(result);
});
});
});

module('#handleUnsupportedLanguage', function () {
module('when language is not supported', function () {
test('returns default language', function (assert) {
Expand Down
2 changes: 1 addition & 1 deletion mon-pix/tests/unit/services/url-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ module('Unit | Service | url', function (hooks) {
const service = this.owner.lookup('service:url');
service.currentDomain = { isFranceDomain: false };
service.intl = { primaryLocale: DUTCH_INTERNATIONAL_LOCALE };
const expectedSupportHomeUrl = 'https://pix.org/nl-be/support';
const expectedSupportHomeUrl = 'https://pix.org/nl-BE/support';

// when
const supportHomeUrl = service.supportHomeUrl;
Expand Down
3 changes: 1 addition & 2 deletions mon-pix/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@
"receive-reset-button": "Receive a reset link"
},
"contact-us-link": {
"link-text": "Contact us",
"link-url": "https://pix.org/en/support"
"link-text": "Contact us"
},
"fields": {
"email": {
Expand Down
3 changes: 1 addition & 2 deletions mon-pix/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@
"receive-reset-button": "Reiniciar contraseña"
},
"contact-us-link": {
"link-text": "Contáctanos.",
"link-url": "https://pix.fr/support"
"link-text": "Contáctanos."
},
"fields": {
"email": {
Expand Down
3 changes: 1 addition & 2 deletions mon-pix/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,7 @@
"receive-reset-button": "Recevoir un lien de réinitialisation"
},
"contact-us-link": {
"link-text": "Contactez-nous",
"link-url": "https://pix.fr/support"
"link-text": "Contactez-nous"
},
"fields": {
"email": {
Expand Down
3 changes: 1 addition & 2 deletions mon-pix/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,7 @@
"receive-reset-button": "Een reset-link ontvangen"
},
"contact-us-link": {
"link-text": "Contacteer ons",
"link-url": "https://pix.fr/support"
"link-text": "Contacteer ons"
},
"fields": {
"email": {
Expand Down
Loading