fix(theme-editor): avoid error (#2340)

This commit is contained in:
被雨水过滤的空气-Rain 2023-07-28 11:03:14 +08:00 committed by GitHub
parent e7ade9ee12
commit fd6d5ac2a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 8 deletions

View File

@ -68,12 +68,12 @@ function Label() {
return null; return null;
} }
if (!currentUser?.data?.data?.systemSettings) { if (!currentUser) {
error('Please check if provide `CurrentUserProvider` in your app.'); error('Please check if provide `CurrentUserProvider` in your app.');
throw new 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.'); error('Please check if provide `SystemSettingsProvider` in your app.');
throw new Error('Please check if provide `SystemSettingsProvider` in your app.'); throw new Error('Please check if provide `SystemSettingsProvider` in your app.');
} }

View File

@ -9,14 +9,14 @@ export function useUpdateThemeSettings() {
const updateUserThemeSettings = useCallback( const updateUserThemeSettings = useCallback(
async (themeId: number | null) => { async (themeId: number | null) => {
if (themeId === currentUser.data.data.systemSettings.themeId) { if (themeId === currentUser.data.data.systemSettings?.themeId) {
return; return;
} }
try { try {
await api.resource('users').updateProfile({ await api.resource('users').updateProfile({
values: { values: {
systemSettings: { systemSettings: {
...currentUser.data.data.systemSettings, ...(currentUser.data.data.systemSettings || {}),
themeId, themeId,
}, },
}, },
@ -25,7 +25,7 @@ export function useUpdateThemeSettings() {
data: { data: {
...currentUser.data.data, ...currentUser.data.data,
systemSettings: { systemSettings: {
...currentUser.data.data.systemSettings, ...(currentUser.data.data.systemSettings || {}),
themeId, themeId,
}, },
}, },
@ -39,7 +39,7 @@ export function useUpdateThemeSettings() {
const updateSystemThemeSettings = useCallback( const updateSystemThemeSettings = useCallback(
async (themeId: number | null) => { async (themeId: number | null) => {
if (themeId === systemSettings.data.data.options.themeId) { if (themeId === systemSettings.data.data.options?.themeId) {
return; return;
} }
await api.request({ await api.request({
@ -47,7 +47,7 @@ export function useUpdateThemeSettings() {
method: 'post', method: 'post',
data: { data: {
options: { options: {
...systemSettings.data.data.options, ...(systemSettings.data.data.options || {}),
themeId, themeId,
}, },
}, },
@ -56,7 +56,7 @@ export function useUpdateThemeSettings() {
data: { data: {
...systemSettings.data.data, ...systemSettings.data.data,
options: { options: {
...systemSettings.data.data.options, ...(systemSettings.data.data.options || {}),
themeId, themeId,
}, },
}, },