From 81f9fbc48379afc7de5d84e3614097ee37a1424b Mon Sep 17 00:00:00 2001 From: Xiao Yijun Date: Sun, 9 Oct 2022 16:47:05 +0800 Subject: [PATCH] fix(console): set undefined value to empty string in custom phrases (#2074) --- packages/console/package.json | 1 + .../components/ManageLanguageModal/LanguageEditor.tsx | 6 ++---- pnpm-lock.yaml | 2 ++ 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/console/package.json b/packages/console/package.json index b3948b6c7..08695cbde 100644 --- a/packages/console/package.json +++ b/packages/console/package.json @@ -48,6 +48,7 @@ "cross-env": "^7.0.3", "csstype": "^3.0.11", "dayjs": "^1.10.5", + "deepmerge": "^4.2.2", "dnd-core": "^16.0.0", "eslint": "^8.21.0", "history": "^5.3.0", diff --git a/packages/console/src/pages/SignInExperience/components/ManageLanguageModal/LanguageEditor.tsx b/packages/console/src/pages/SignInExperience/components/ManageLanguageModal/LanguageEditor.tsx index b37f1449b..dd71d89a1 100644 --- a/packages/console/src/pages/SignInExperience/components/ManageLanguageModal/LanguageEditor.tsx +++ b/packages/console/src/pages/SignInExperience/components/ManageLanguageModal/LanguageEditor.tsx @@ -3,6 +3,7 @@ import resource, { isBuiltInLanguageTag } from '@logto/phrases-ui'; import en from '@logto/phrases-ui/lib/locales/en'; import { SignInExperience, Translation } from '@logto/schemas'; import cleanDeep from 'clean-deep'; +import deepmerge from 'deepmerge'; import { useCallback, useContext, useEffect, useMemo, useState } from 'react'; import { FormProvider, useForm } from 'react-hook-form'; import { toast } from 'react-hot-toast'; @@ -56,10 +57,7 @@ const LanguageEditor = () => { ); const defaultFormValues = useMemo( - () => - customPhrase && Object.keys(customPhrase.translation).length > 0 - ? customPhrase.translation - : emptyUiTranslation, + () => deepmerge(emptyUiTranslation, customPhrase?.translation ?? {}), [customPhrase] ); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2a0c72e97..b8b97356d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,6 +51,7 @@ importers: cross-env: ^7.0.3 csstype: ^3.0.11 dayjs: ^1.10.5 + deepmerge: ^4.2.2 dnd-core: ^16.0.0 eslint: ^8.21.0 history: ^5.3.0 @@ -117,6 +118,7 @@ importers: cross-env: 7.0.3 csstype: 3.0.11 dayjs: 1.10.7 + deepmerge: 4.2.2 dnd-core: 16.0.0 eslint: 8.21.0 history: 5.3.0