Skip to content

Commit a885261

Browse files
committed
fix(account-creation): add subsidiary info to language selection
ref: #MANAGER-20902 Signed-off-by: Dustin Kroger <dustin.kroger.ext@ovhcloud.com>
1 parent b835464 commit a885261

File tree

5 files changed

+64
-24
lines changed

5 files changed

+64
-24
lines changed

packages/manager/apps/account-creation/src/data/hooks/settings/useSettings.spec.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ describe('useSettings', () => {
109109
});
110110

111111
describe('useLanguageSettings', () => {
112-
it('should give a list of unique languages available for the given country', async () => {
112+
it('should give a list of unique languages with subsidiary available for the given country', async () => {
113113
getSettingsApiSpy.mockImplementationOnce(() =>
114114
Promise.resolve(mockedGetSettingsApiResult),
115115
);
@@ -118,7 +118,10 @@ describe('useSettings', () => {
118118
});
119119

120120
await waitFor(() => {
121-
expect(result.current.data).toStrictEqual(['fr-FR', 'en-IE']);
121+
expect(result.current.data).toStrictEqual([
122+
{ ietfLanguageTag: 'fr-FR', ovhSubsidiary: 'FR' },
123+
{ ietfLanguageTag: 'en-IE', ovhSubsidiary: 'IE' },
124+
]);
122125
});
123126
});
124127
it('should give an empty list of languages if no country is given', async () => {

packages/manager/apps/account-creation/src/data/hooks/settings/useSettings.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,38 @@ export const useCurrencySettings = (country?: string) =>
4848
);
4949
});
5050

51+
export type LanguageOption = {
52+
ietfLanguageTag: SupportLanguage;
53+
ovhSubsidiary: string;
54+
};
55+
5156
export const useLanguageSettings = (country?: string, currency?: string) =>
5257
useSettingsQuery((settings) => {
5358
if (!(country && currency)) return [];
54-
59+
const seen = new Set<SupportLanguage>();
5560
return (
56-
settings
57-
.get(country)
58-
?.reduce((languages: SupportLanguage[], billingCountry) => {
59-
if (
60-
currency === billingCountry.currency.code &&
61-
!languages.includes(billingCountry.ietfLanguageTag)
62-
) {
63-
languages.push(billingCountry.ietfLanguageTag);
64-
}
65-
return languages;
66-
}, []) ?? []
61+
settings.get(country)?.reduce((acc: LanguageOption[], billingCountry) => {
62+
if (
63+
currency === billingCountry.currency.code &&
64+
!seen.has(billingCountry.ietfLanguageTag)
65+
) {
66+
seen.add(billingCountry.ietfLanguageTag);
67+
acc.push({
68+
ietfLanguageTag: billingCountry.ietfLanguageTag,
69+
ovhSubsidiary: billingCountry.ovhSubsidiary,
70+
});
71+
}
72+
return acc;
73+
}, []) ?? []
6774
);
6875
});
6976

7077
export const useSubsidiarySettings = (
7178
country?: string,
7279
currency?: string,
7380
language?: string,
74-
) => useSettingsQuery<string | null>((settings) => {
81+
) =>
82+
useSettingsQuery<string | null>((settings) => {
7583
if (!(country && currency && language)) {
7684
return null;
7785
}

packages/manager/apps/account-creation/src/pages/settings/settings.constants.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { Subsidiary } from '@ovh-ux/manager-config';
2+
13
export const WEBSITE_LABEL_BY_LOCALE = {
24
'fr-FR': 'OVHcloud France (Français)',
35
'es-ES': 'OVHcloud España (Español)',
@@ -21,4 +23,16 @@ export const WEBSITE_LABEL_BY_LOCALE = {
2123
'en-US': 'OVHcloud United States (English)',
2224
};
2325

26+
export const WEBSITE_LABEL_BY_LOCALE_OVERWRITES: Partial<Record<
27+
Subsidiary,
28+
Record<string, string>
29+
>> = {
30+
WS: {
31+
'es-ES': 'OVHcloud World (Español)',
32+
},
33+
WE: {
34+
'en-CA': 'OVHcloud World (English)',
35+
},
36+
};
37+
2438
export const DEFAULT_REDIRECT_URL = 'https://ovhcloud.com/';

packages/manager/apps/account-creation/src/pages/settings/settings.page.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,8 @@ import {
3939
} from '@/hooks/redirection/useSettingsRedirecions';
4040
import { useSettingsSchema } from '@/hooks/settings/useSettings';
4141
import { useTrackError } from '@/hooks/tracking/useTracking';
42-
import {
43-
DEFAULT_REDIRECT_URL,
44-
WEBSITE_LABEL_BY_LOCALE,
45-
} from './settings.constants';
42+
import { DEFAULT_REDIRECT_URL } from './settings.constants';
43+
import { getWebsiteLabel } from './settings.utils';
4644
import AccountSettingsPopoverContent from './popover-content/PopoverContent';
4745
import { useLocalCountry } from '@/hooks/useLocalCountry/useLocalCountry';
4846

@@ -144,7 +142,9 @@ export default function Settings() {
144142

145143
useEffect(() => {
146144
if (languages?.length === 1) {
147-
setValue('language', languages[0], { shouldValidate: true });
145+
setValue('language', languages[0].ietfLanguageTag, {
146+
shouldValidate: true,
147+
});
148148
}
149149
}, [languages, selectedCountry, selectedCurrency, setValue]);
150150

@@ -161,7 +161,7 @@ export default function Settings() {
161161
}, [setValue]);
162162

163163
const submitSettings: SubmitHandler<SettingsFormData> = useCallback(
164-
({ country, currency, language }: SettingsFormData) => {
164+
({ country, language }: SettingsFormData) => {
165165
if (pageTracking) {
166166
trackClick(pageTracking, {
167167
location: PageLocation.page,
@@ -173,7 +173,6 @@ export default function Settings() {
173173
],
174174
});
175175
}
176-
console.log({ country, currency, language });
177176
// In case the signup url is not valid, we will redirect to the website
178177
if (redirectToSignUpUrl !== null) {
179178
const params = `ovhSubsidiary=${ovhSubsidiary}&country=${country}&language=${language}`;
@@ -353,8 +352,11 @@ export default function Settings() {
353352
data-testid="language-select"
354353
>
355354
{(languages || []).map((language) => (
356-
<option key={`site_${language}`} value={language}>
357-
{WEBSITE_LABEL_BY_LOCALE[language]}
355+
<option
356+
key={`site_${language.ietfLanguageTag}`}
357+
value={language.ietfLanguageTag}
358+
>
359+
{getWebsiteLabel(language)}
358360
</option>
359361
))}
360362
</OdsSelect>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { LanguageOption } from '@/data/hooks/settings/useSettings';
2+
import {
3+
WEBSITE_LABEL_BY_LOCALE,
4+
WEBSITE_LABEL_BY_LOCALE_OVERWRITES,
5+
} from './settings.constants';
6+
import { Subsidiary } from '@ovh-ux/manager-config';
7+
8+
export const getWebsiteLabel = (language: LanguageOption): string =>
9+
(language.ovhSubsidiary &&
10+
WEBSITE_LABEL_BY_LOCALE_OVERWRITES[language.ovhSubsidiary as Subsidiary]?.[
11+
language.ietfLanguageTag
12+
]) ??
13+
WEBSITE_LABEL_BY_LOCALE[language.ietfLanguageTag];

0 commit comments

Comments
 (0)