Fix snackbar errors

This commit is contained in:
Daniel Lautzenheiser 2022-10-26 11:46:44 -04:00
parent 03815ec2f0
commit e36698aa9a
6 changed files with 47 additions and 23 deletions

View File

@ -86,18 +86,22 @@ export function loginUser(credentials: Credentials) {
.then(user => { .then(user => {
dispatch(authenticate(user)); dispatch(authenticate(user));
}) })
.catch((error: Error) => { .catch((error: unknown) => {
console.error(error); console.error(error);
dispatch( if (error instanceof Error) {
addSnackbar({ dispatch(
type: 'warning', addSnackbar({
message: { type: 'warning',
key: 'ui.toast.onFailToAuth', message: {
message: error.message, key: 'ui.toast.onFailToAuth',
}, options: {
}), details: error.message,
); },
dispatch(authError(error)); },
}),
);
dispatch(authError(error));
}
}); });
}; };
} }

View File

@ -624,7 +624,9 @@ export function loadEntry(collection: Collection, slug: string, silent = false)
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToLoadEntries', key: 'ui.toast.onFailToLoadEntries',
details: error.message, options: {
details: error.message,
},
}, },
}), }),
); );
@ -744,7 +746,9 @@ export function loadEntries(collection: Collection, page = 0) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToLoadEntries', key: 'ui.toast.onFailToLoadEntries',
details: error.message, options: {
details: error.message,
},
}, },
}), }),
); );
@ -803,7 +807,9 @@ export function traverseCollectionCursor(collection: Collection, action: string)
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToLoadEntries', key: 'ui.toast.onFailToLoadEntries',
details: error.message, options: {
details: error.message,
},
}, },
}), }),
); );
@ -1071,7 +1077,9 @@ export function persistEntry(collection: Collection) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToPersist', key: 'ui.toast.onFailToPersist',
details: error, options: {
details: error,
},
}, },
}), }),
); );
@ -1102,7 +1110,9 @@ export function deleteEntry(collection: Collection, slug: string) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToDelete', key: 'ui.toast.onFailToDelete',
details: error, options: {
details: error,
},
}, },
}), }),
); );

View File

@ -337,7 +337,9 @@ export function persistMedia(file: File, opts: MediaOptions = {}) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToPersistMedia', key: 'ui.toast.onFailToPersistMedia',
details: error, options: {
details: error,
},
}, },
}), }),
); );
@ -381,7 +383,9 @@ export function deleteMedia(file: MediaFile, opts: MediaOptions = {}) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToDeleteMedia', key: 'ui.toast.onFailToDeleteMedia',
details: error.message, options: {
details: error.message,
},
}, },
}), }),
); );
@ -417,7 +421,9 @@ export function deleteMedia(file: MediaFile, opts: MediaOptions = {}) {
type: 'error', type: 'error',
message: { message: {
key: 'ui.toast.onFailToDeleteMedia', key: 'ui.toast.onFailToDeleteMedia',
details: error.message, options: {
details: error.message,
},
}, },
}), }),
); );

View File

@ -55,7 +55,10 @@ export function checkBackendStatus() {
dispatch( dispatch(
addSnackbar({ addSnackbar({
type: 'error', type: 'error',
message: { key: 'ui.toast.onBackendDown', details: status.api.statusPage }, message: {
key: 'ui.toast.onBackendDown',
options: { details: status.api.statusPage },
},
}), }),
); );
} }

View File

@ -34,7 +34,7 @@ const AzureAuthenticationPage = ({
if (err) { if (err) {
alert({ alert({
title: 'auth.errors.authTitle', title: 'auth.errors.authTitle',
body: { key: 'auth.errors.authBody', options: { details: err } }, body: { key: 'auth.errors.authBody', options: { details: err.toString() } },
}); });
return; return;
} else if (data) { } else if (data) {

View File

@ -11,9 +11,10 @@ export interface SnackbarMessage {
type: MessageType; type: MessageType;
message: message:
| string | string
| ({ | {
key: string; key: string;
} & Record<string, unknown>); options?: Record<string, unknown>;
};
} }
// Define a type for the slice state // Define a type for the slice state