Fix locale fetch (#1017)
This commit is contained in:
parent
71589721ef
commit
7c304702d6
1 changed files with 29 additions and 24 deletions
|
@ -418,34 +418,39 @@ function App(props: Props) {
|
||||||
document.head.appendChild(secondScript);
|
document.head.appendChild(secondScript);
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchLocaleApi().then((response) => {
|
const shouldFetchLanguage = !localeLangs && !localeSwitchDismissed;
|
||||||
if (!localeLangs && !localeSwitchDismissed) {
|
const shouldFetchGdpr = gdprRequired === null || gdprRequired === undefined;
|
||||||
const countryCode = response?.data?.country;
|
|
||||||
const langs = getLanguagesForCountry(countryCode);
|
|
||||||
|
|
||||||
const supportedLangs = [];
|
if (shouldFetchLanguage || shouldFetchGdpr) {
|
||||||
langs.forEach((lang) => lang !== 'en' && SUPPORTED_LANGUAGES[lang] && supportedLangs.push(lang));
|
fetchLocaleApi().then((response) => {
|
||||||
|
if (shouldFetchLanguage) {
|
||||||
|
const countryCode = response?.data?.country;
|
||||||
|
const langs = getLanguagesForCountry(countryCode);
|
||||||
|
|
||||||
if (supportedLangs.length > 0) setLocaleLangs(supportedLangs);
|
const supportedLangs = [];
|
||||||
}
|
langs.forEach((lang) => lang !== 'en' && SUPPORTED_LANGUAGES[lang] && supportedLangs.push(lang));
|
||||||
|
|
||||||
// haven't done a gdpr check, do it now
|
if (supportedLangs.length > 0) setLocaleLangs(supportedLangs);
|
||||||
if (gdprRequired === null || gdprRequired === undefined) {
|
|
||||||
const gdprRequiredBasedOnLocation = response?.data?.gdpr_required;
|
|
||||||
|
|
||||||
// note we need gdpr and load script
|
|
||||||
if (gdprRequiredBasedOnLocation) {
|
|
||||||
setGdprRequired(true);
|
|
||||||
// $FlowFixMe
|
|
||||||
document.head.appendChild(script);
|
|
||||||
// $FlowFixMe
|
|
||||||
document.head.appendChild(secondScript);
|
|
||||||
// note we don't need gdpr, save to session
|
|
||||||
} else if (gdprRequiredBasedOnLocation === false) {
|
|
||||||
setGdprRequired(false);
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
// haven't done a gdpr check, do it now
|
||||||
|
if (shouldFetchGdpr) {
|
||||||
|
const gdprRequiredBasedOnLocation = response?.data?.gdpr_required;
|
||||||
|
|
||||||
|
// note we need gdpr and load script
|
||||||
|
if (gdprRequiredBasedOnLocation) {
|
||||||
|
setGdprRequired(true);
|
||||||
|
// $FlowFixMe
|
||||||
|
document.head.appendChild(script);
|
||||||
|
// $FlowFixMe
|
||||||
|
document.head.appendChild(secondScript);
|
||||||
|
// note we don't need gdpr, save to session
|
||||||
|
} else if (gdprRequiredBasedOnLocation === false) {
|
||||||
|
setGdprRequired(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue