From fd6d5ac2a654a91403f023257756454e6ac68dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A2=AB=E9=9B=A8=E6=B0=B4=E8=BF=87=E6=BB=A4=E7=9A=84?= =?UTF-8?q?=E7=A9=BA=E6=B0=94-Rain?= <958414905@qq.com> Date: Fri, 28 Jul 2023 11:03:14 +0800 Subject: [PATCH] fix(theme-editor): avoid error (#2340) --- .../src/client/hooks/useThemeSettings.tsx | 4 ++-- .../src/client/hooks/useUpdateThemeSettings.tsx | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/plugins/theme-editor/src/client/hooks/useThemeSettings.tsx b/packages/plugins/theme-editor/src/client/hooks/useThemeSettings.tsx index 99ce74b89..4322b1357 100644 --- a/packages/plugins/theme-editor/src/client/hooks/useThemeSettings.tsx +++ b/packages/plugins/theme-editor/src/client/hooks/useThemeSettings.tsx @@ -68,12 +68,12 @@ function Label() { return null; } - if (!currentUser?.data?.data?.systemSettings) { + if (!currentUser) { error('Please check if provide `CurrentUserProvider` in your app.'); throw new Error('Please check if provide `CurrentUserProvider` in your app.'); } - if (!systemSettings?.data?.data?.options) { + if (!systemSettings) { error('Please check if provide `SystemSettingsProvider` in your app.'); throw new Error('Please check if provide `SystemSettingsProvider` in your app.'); } diff --git a/packages/plugins/theme-editor/src/client/hooks/useUpdateThemeSettings.tsx b/packages/plugins/theme-editor/src/client/hooks/useUpdateThemeSettings.tsx index bb88afd03..3fa6d94ff 100644 --- a/packages/plugins/theme-editor/src/client/hooks/useUpdateThemeSettings.tsx +++ b/packages/plugins/theme-editor/src/client/hooks/useUpdateThemeSettings.tsx @@ -9,14 +9,14 @@ export function useUpdateThemeSettings() { const updateUserThemeSettings = useCallback( async (themeId: number | null) => { - if (themeId === currentUser.data.data.systemSettings.themeId) { + if (themeId === currentUser.data.data.systemSettings?.themeId) { return; } try { await api.resource('users').updateProfile({ values: { systemSettings: { - ...currentUser.data.data.systemSettings, + ...(currentUser.data.data.systemSettings || {}), themeId, }, }, @@ -25,7 +25,7 @@ export function useUpdateThemeSettings() { data: { ...currentUser.data.data, systemSettings: { - ...currentUser.data.data.systemSettings, + ...(currentUser.data.data.systemSettings || {}), themeId, }, }, @@ -39,7 +39,7 @@ export function useUpdateThemeSettings() { const updateSystemThemeSettings = useCallback( async (themeId: number | null) => { - if (themeId === systemSettings.data.data.options.themeId) { + if (themeId === systemSettings.data.data.options?.themeId) { return; } await api.request({ @@ -47,7 +47,7 @@ export function useUpdateThemeSettings() { method: 'post', data: { options: { - ...systemSettings.data.data.options, + ...(systemSettings.data.data.options || {}), themeId, }, }, @@ -56,7 +56,7 @@ export function useUpdateThemeSettings() { data: { ...systemSettings.data.data, options: { - ...systemSettings.data.data.options, + ...(systemSettings.data.data.options || {}), themeId, }, },