From f4068debb8cd70b9f38201d2e5795ee3439734e0 Mon Sep 17 00:00:00 2001 From: Erik Jan de Wit Date: Wed, 3 Nov 2021 20:47:42 +0100 Subject: [PATCH] can't remove english from supported locals (#1461) fixes: #1059 --- src/realm-settings/LocalizationTab.tsx | 188 ++++++++++------------- src/realm-settings/RealmSettingsTabs.tsx | 5 +- src/realm-settings/messages.ts | 1 + 3 files changed, 88 insertions(+), 106 deletions(-) diff --git a/src/realm-settings/LocalizationTab.tsx b/src/realm-settings/LocalizationTab.tsx index d5f1592746..269669f72c 100644 --- a/src/realm-settings/LocalizationTab.tsx +++ b/src/realm-settings/LocalizationTab.tsx @@ -59,7 +59,6 @@ export const LocalizationTab = ({ const [selectMenuLocale, setSelectMenuLocale] = useState(DEFAULT_LOCALE); const { getValues, control, handleSubmit, formState } = useFormContext(); - const [valueSelected, setValueSelected] = useState(false); const [selectMenuValueSelected, setSelectMenuValueSelected] = useState(false); const themeTypes = useServerInfo().themes!; @@ -174,63 +173,54 @@ export const LocalizationTab = ({ /> )} - - - - } - > - ( - - )} + - - + ( + - } - > - { - return internationalizationEnabled ? ( + )} + /> + + {internationalizationEnabled && ( + <> + + ( - ) : ( -
- ); - }} - /> - - - } - > - { - return internationalizationEnabled ? ( + + + ( - ) : ( -
- ); - }} - /> - - - - - - - + )} + /> + + + )} + + + + + diff --git a/src/realm-settings/RealmSettingsTabs.tsx b/src/realm-settings/RealmSettingsTabs.tsx index ddb7289ad1..e895ea32da 100644 --- a/src/realm-settings/RealmSettingsTabs.tsx +++ b/src/realm-settings/RealmSettingsTabs.tsx @@ -47,6 +47,7 @@ import { PartialExportDialog } from "./PartialExport"; import { toRealmSettings } from "./routes/RealmSettings"; import { LocalizationTab } from "./LocalizationTab"; import { HelpItem } from "../components/help-enabler/HelpItem"; +import { DEFAULT_LOCALE } from "../i18n"; type RealmSettingsHeaderProps = { onChange: (value: boolean) => void; @@ -168,7 +169,7 @@ export const RealmSettingsTabs = ({ const kpComponentTypes = useServerInfo().componentTypes?.[KEY_PROVIDER_TYPE] ?? []; - const form = useForm({ mode: "onChange" }); + const form = useForm({ mode: "onChange", shouldUnregister: false }); const { control, getValues, setValue, reset: resetForm } = form; const [activeTab, setActiveTab] = useState(0); @@ -182,6 +183,8 @@ export const RealmSettingsTabs = ({ Object.entries(r).map(([key, value]) => { if (key === "attributes") { convertToFormValues(value, "attributes", setValue); + } else if (key === "supportedLocales" && value?.length === 0) { + setValue(key, [DEFAULT_LOCALE]); } else { setValue(key, value); } diff --git a/src/realm-settings/messages.ts b/src/realm-settings/messages.ts index ff73523cc5..a463778abb 100644 --- a/src/realm-settings/messages.ts +++ b/src/realm-settings/messages.ts @@ -336,6 +336,7 @@ export default { pairCreatedError: "Error creating localization text.", supportedLocales: "Supported locales", defaultLocale: "Default locale", + selectLocales: "Select locales", addMessageBundle: "Add message bundle", eventType: "Event saved type", searchEventType: "Search saved event type",