From 9c04d8bbe31027ba893515752bbab1c6e7a8acfa Mon Sep 17 00:00:00 2001 From: janrembold Date: Wed, 24 Apr 2024 12:55:06 +0200 Subject: [PATCH 1/2] fix: set preferred language in registration --- .../components/registration/Registration.tsx | 9 ++++++--- src/globalState/provider/LocaleProvider.tsx | 11 +++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/extensions/components/registration/Registration.tsx b/src/extensions/components/registration/Registration.tsx index a904c4291..5cc996499 100644 --- a/src/extensions/components/registration/Registration.tsx +++ b/src/extensions/components/registration/Registration.tsx @@ -32,7 +32,8 @@ import { registrationSessionStorageKey, RegistrationData, NotificationsContext, - NOTIFICATION_TYPE_ERROR + NOTIFICATION_TYPE_ERROR, + LocaleContext } from '../../../globalState'; import { GlobalComponentContext } from '../../../globalState/provider/GlobalComponentContext'; import { @@ -83,6 +84,7 @@ export const Registration = () => { } = useContext(RegistrationContext); const { consultant: preselectedConsultant } = useContext(UrlParamsContext); const { tenant } = useContext(TenantContext); + const { locale } = useContext(LocaleContext); const [stepData, setStepData] = useState>({}); const [redirectOverlayActive, setRedirectOverlayActive] = @@ -185,7 +187,7 @@ export const Registration = () => { agencyId: registrationData.agency.id.toString(), postcode: registrationData.zipcode, termsAccepted: 'true', - preferredLanguage: 'de', + preferredLanguage: locale || 'de', consultingType: registrationData.agency.consultingType, ...(preselectedConsultant ? { consultantId: preselectedConsultant?.consultantId } @@ -222,7 +224,8 @@ export const Registration = () => { settings.multitenancyWithSingleDomainEnabled, tenant, addNotification, - t + t, + locale ]); const stepPaths = useMemo( diff --git a/src/globalState/provider/LocaleProvider.tsx b/src/globalState/provider/LocaleProvider.tsx index 26d5a5eba..05fffae72 100644 --- a/src/globalState/provider/LocaleProvider.tsx +++ b/src/globalState/provider/LocaleProvider.tsx @@ -3,7 +3,10 @@ import { useContext, useEffect, useMemo, useState } from 'react'; import i18n, { FALLBACK_LNG, init } from '../../i18n'; import { InformalContext } from './InformalProvider'; import { useAppConfig } from '../../hooks/useAppConfig'; -import { setValueInCookie } from '../../components/sessionCookie/accessSessionCookie'; +import { + getValueFromCookie, + setValueInCookie +} from '../../components/sessionCookie/accessSessionCookie'; import { useTenant } from './TenantProvider'; import useTenantTheming from '../../utils/useTenantTheming'; import { LocaleContext, TLocaleContext } from '../context/LocaleContext'; @@ -18,7 +21,11 @@ export function LocaleProvider(props) { const [initLocale, setInitLocale] = useState(null); const { informal } = useContext(InformalContext); const [locales, setLocales] = useState([]); - const [locale, setLocale] = useState(null); + const [locale, setLocale] = useState( + getValueFromCookie('lang') || + localStorage.getItem(STORAGE_KEY_LOCALE) || + null + ); useEffect(() => { // If using the tenant service we should load first the tenant because we need the From f09ab26b45b572c794719d716f6575beaf843e2b Mon Sep 17 00:00:00 2001 From: janrembold Date: Wed, 24 Apr 2024 13:07:44 +0200 Subject: [PATCH 2/2] fix: remove cookie value from default locale state --- src/globalState/provider/LocaleProvider.tsx | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/globalState/provider/LocaleProvider.tsx b/src/globalState/provider/LocaleProvider.tsx index 05fffae72..3d3f6133f 100644 --- a/src/globalState/provider/LocaleProvider.tsx +++ b/src/globalState/provider/LocaleProvider.tsx @@ -3,10 +3,7 @@ import { useContext, useEffect, useMemo, useState } from 'react'; import i18n, { FALLBACK_LNG, init } from '../../i18n'; import { InformalContext } from './InformalProvider'; import { useAppConfig } from '../../hooks/useAppConfig'; -import { - getValueFromCookie, - setValueInCookie -} from '../../components/sessionCookie/accessSessionCookie'; +import { setValueInCookie } from '../../components/sessionCookie/accessSessionCookie'; import { useTenant } from './TenantProvider'; import useTenantTheming from '../../utils/useTenantTheming'; import { LocaleContext, TLocaleContext } from '../context/LocaleContext'; @@ -22,9 +19,7 @@ export function LocaleProvider(props) { const { informal } = useContext(InformalContext); const [locales, setLocales] = useState([]); const [locale, setLocale] = useState( - getValueFromCookie('lang') || - localStorage.getItem(STORAGE_KEY_LOCALE) || - null + localStorage.getItem(STORAGE_KEY_LOCALE) || null ); useEffect(() => {