mirror of
https://github.com/strapi/strapi.git
synced 2025-09-25 16:29:34 +00:00
Add toast notification in case of error
Signed-off-by: soupette <cyril@strapi.io>
This commit is contained in:
parent
6f2dfac689
commit
5078b041e8
@ -6,7 +6,7 @@ import { Link } from '@strapi/parts/Link';
|
||||
|
||||
const Notification = ({ dispatch, notification }) => {
|
||||
const { formatMessage } = useIntl();
|
||||
const { message, link, type, id, onClose, timeout, blockTransition } = notification;
|
||||
const { message, link, type, id, onClose, timeout, blockTransition, title } = notification;
|
||||
|
||||
const formattedMessage = msg => (typeof msg === 'string' ? msg : formatMessage(msg, msg.values));
|
||||
const handleClose = useCallback(() => {
|
||||
@ -56,6 +56,10 @@ const Notification = ({ dispatch, notification }) => {
|
||||
variant = 'success';
|
||||
}
|
||||
|
||||
if (title) {
|
||||
alertTitle = title;
|
||||
}
|
||||
|
||||
return (
|
||||
<Alert
|
||||
action={
|
||||
@ -93,6 +97,7 @@ Notification.defaultProps = {
|
||||
},
|
||||
onClose: () => null,
|
||||
timeout: 2500,
|
||||
title: null,
|
||||
blockTransition: false,
|
||||
},
|
||||
};
|
||||
@ -121,6 +126,7 @@ Notification.propTypes = {
|
||||
}),
|
||||
]).isRequired,
|
||||
}),
|
||||
title: PropTypes.string,
|
||||
type: PropTypes.string,
|
||||
onClose: PropTypes.func,
|
||||
timeout: PropTypes.number,
|
||||
|
@ -14,6 +14,7 @@ const notificationReducer = (state = initialState, action) =>
|
||||
draftState.notifications.push({
|
||||
// No action.config spread to limit the notification API and avoid customization
|
||||
id: state.notifId,
|
||||
title: action.config.title || null,
|
||||
type: get(action, ['config', 'type'], 'success'),
|
||||
message: get(action, ['config', 'message'], {
|
||||
id: 'notification.success.saved',
|
||||
|
@ -30,6 +30,7 @@ describe('ADMIN | COMPONENTS | NOTIFICATIONS | reducer', () => {
|
||||
notifications: [
|
||||
{
|
||||
id: 0,
|
||||
title: null,
|
||||
type: 'success',
|
||||
message: { id: 'notification.message' },
|
||||
link: null,
|
||||
|
@ -304,6 +304,13 @@ const EditViewDataManagerProvider = ({
|
||||
console.error(err);
|
||||
|
||||
errors = getYupInnerErrors(err);
|
||||
const firstError = Object.keys(errors)[0];
|
||||
|
||||
toggleNotification({
|
||||
type: 'warning',
|
||||
title: `${firstError}:`,
|
||||
message: errors[firstError],
|
||||
});
|
||||
}
|
||||
|
||||
dispatch({
|
||||
@ -311,7 +318,16 @@ const EditViewDataManagerProvider = ({
|
||||
errors,
|
||||
});
|
||||
},
|
||||
[createFormData, isCreatingEntry, modifiedData, onPost, onPut, trackerProperty, yupSchema]
|
||||
[
|
||||
createFormData,
|
||||
isCreatingEntry,
|
||||
modifiedData,
|
||||
onPost,
|
||||
onPut,
|
||||
toggleNotification,
|
||||
trackerProperty,
|
||||
yupSchema,
|
||||
]
|
||||
);
|
||||
|
||||
const handlePublish = useCallback(async () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user