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;
}
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.');
}

View File

@ -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,
},
},