Fixes localization 500 error (#1858)

* fix localization crash

* add optional chain on themeTypes object

* add comment
This commit is contained in:
Jenny 2022-01-18 18:48:32 -05:00 committed by GitHub
parent 105d0dffb0
commit b2b61c26ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -115,13 +115,18 @@ export const LocalizationTab = ({
useFetch( useFetch(
async () => { async () => {
let result = await adminClient.realms.getRealmLocalizationTexts({ let result = await adminClient.realms
first, .getRealmLocalizationTexts({
max, first,
realm: realm.realm!, max,
selectedLocale: realm: realm.realm!,
selectMenuLocale || getValues("defaultLocale") || whoAmI.getLocale(), selectedLocale:
}); selectMenuLocale ||
getValues("defaultLocale") ||
whoAmI.getLocale(),
})
// prevents server error in dev mode due to snowpack
.catch(() => []);
const searchInBundles = (idx: number) => { const searchInBundles = (idx: number) => {
return Object.entries(result).filter((i) => i[idx].includes(filter)); return Object.entries(result).filter((i) => i[idx].includes(filter));
@ -405,17 +410,20 @@ export const LocalizationTab = ({
isOpen={supportedLocalesOpen} isOpen={supportedLocalesOpen}
placeholderText={t("selectLocales")} placeholderText={t("selectLocales")}
> >
{themeTypes.login![0].locales.map( {
(locale: string, idx: number) => ( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
<SelectOption themeTypes.login![0].locales?.map(
selected={value.includes(locale)} (locale: string, idx: number) => (
key={`locale-${idx}`} <SelectOption
value={locale} selected={value.includes(locale)}
> key={`locale-${idx}`}
{t(`allSupportedLocales.${locale}`)} value={locale}
</SelectOption> >
{t(`allSupportedLocales.${locale}`)}
</SelectOption>
)
) )
)} }
</Select> </Select>
)} )}
/> />