mirror of
https://github.com/strapi/strapi.git
synced 2025-08-06 07:50:02 +00:00
Merge pull request #15462 from strapi/chore/notification-variant
Add new notification variant to notification component
This commit is contained in:
commit
2ec1651ea2
@ -6,7 +6,7 @@ import { Link } from '@strapi/design-system/v2/Link';
|
|||||||
|
|
||||||
const Notification = ({ dispatch, notification }) => {
|
const Notification = ({ dispatch, notification }) => {
|
||||||
const { formatMessage } = useIntl();
|
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) =>
|
const formattedMessage = (msg) =>
|
||||||
typeof msg === 'string' ? msg : formatMessage(msg, msg.values);
|
typeof msg === 'string' ? msg : formatMessage(msg, msg.values);
|
||||||
@ -37,6 +37,7 @@ const Notification = ({ dispatch, notification }) => {
|
|||||||
let variant;
|
let variant;
|
||||||
let alertTitle;
|
let alertTitle;
|
||||||
|
|
||||||
|
// TODO break out this logic into separate file
|
||||||
if (type === 'info') {
|
if (type === 'info') {
|
||||||
variant = 'default';
|
variant = 'default';
|
||||||
alertTitle = formatMessage({
|
alertTitle = formatMessage({
|
||||||
@ -44,17 +45,29 @@ const Notification = ({ dispatch, notification }) => {
|
|||||||
defaultMessage: 'Information:',
|
defaultMessage: 'Information:',
|
||||||
});
|
});
|
||||||
} else if (type === 'warning') {
|
} else if (type === 'warning') {
|
||||||
|
// type should be renamed to danger in the future, but it might introduce changes if done now
|
||||||
|
variant = 'danger';
|
||||||
|
alertTitle = formatMessage({
|
||||||
|
id: 'notification.warning.title',
|
||||||
|
defaultMessage: 'Warning:',
|
||||||
|
});
|
||||||
|
} else if (type === 'softWarning') {
|
||||||
|
// type should be renamed to just warning in the future
|
||||||
|
variant = 'warning';
|
||||||
alertTitle = formatMessage({
|
alertTitle = formatMessage({
|
||||||
id: 'notification.warning.title',
|
id: 'notification.warning.title',
|
||||||
defaultMessage: 'Warning:',
|
defaultMessage: 'Warning:',
|
||||||
});
|
});
|
||||||
variant = 'danger';
|
|
||||||
} else {
|
} else {
|
||||||
|
variant = 'success';
|
||||||
alertTitle = formatMessage({
|
alertTitle = formatMessage({
|
||||||
id: 'notification.success.title',
|
id: 'notification.success.title',
|
||||||
defaultMessage: 'Success:',
|
defaultMessage: 'Success:',
|
||||||
});
|
});
|
||||||
variant = 'success';
|
}
|
||||||
|
|
||||||
|
if (title) {
|
||||||
|
alertTitle = typeof title === 'string' ? title : formatMessage(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -125,6 +138,14 @@ Notification.propTypes = {
|
|||||||
onClose: PropTypes.func,
|
onClose: PropTypes.func,
|
||||||
timeout: PropTypes.number,
|
timeout: PropTypes.number,
|
||||||
blockTransition: PropTypes.bool,
|
blockTransition: PropTypes.bool,
|
||||||
|
title: PropTypes.oneOfType([
|
||||||
|
PropTypes.string,
|
||||||
|
PropTypes.shape({
|
||||||
|
id: PropTypes.string.isRequired,
|
||||||
|
defaultMessage: PropTypes.string,
|
||||||
|
values: PropTypes.object,
|
||||||
|
}),
|
||||||
|
]),
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ const notificationReducer = (state = initialState, action) =>
|
|||||||
timeout: get(action, ['config', 'timeout'], 2500),
|
timeout: get(action, ['config', 'timeout'], 2500),
|
||||||
blockTransition: get(action, ['config', 'blockTransition'], false),
|
blockTransition: get(action, ['config', 'blockTransition'], false),
|
||||||
onClose: get(action, ['config', 'onClose'], null),
|
onClose: get(action, ['config', 'onClose'], null),
|
||||||
|
title: get(action, ['config', 'title'], null),
|
||||||
});
|
});
|
||||||
draftState.notifId = state.notifId + 1;
|
draftState.notifId = state.notifId + 1;
|
||||||
break;
|
break;
|
||||||
|
@ -36,6 +36,7 @@ describe('ADMIN | COMPONENTS | NOTIFICATIONS | reducer', () => {
|
|||||||
timeout: 2500,
|
timeout: 2500,
|
||||||
blockTransition: false,
|
blockTransition: false,
|
||||||
onClose: null,
|
onClose: null,
|
||||||
|
title: null,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
notifId: 1,
|
notifId: 1,
|
||||||
|
@ -20,7 +20,7 @@ const HomePage = () => {
|
|||||||
const handleClick = () => {
|
const handleClick = () => {
|
||||||
toggleNotification({
|
toggleNotification({
|
||||||
// required
|
// required
|
||||||
type: 'info|success|warning',
|
type: 'info|success|warning|softWarning',
|
||||||
// required
|
// required
|
||||||
message: { id: 'notification.version.update.message', defaultMessage: 'A new version is available' },
|
message: { id: 'notification.version.update.message', defaultMessage: 'A new version is available' },
|
||||||
// optional
|
// optional
|
||||||
@ -35,6 +35,8 @@ const HomePage = () => {
|
|||||||
blockTransition: true,
|
blockTransition: true,
|
||||||
// optional
|
// optional
|
||||||
onClose: () => localStorage.setItem('STRAPI_UPDATE_NOTIF', true),
|
onClose: () => localStorage.setItem('STRAPI_UPDATE_NOTIF', true),
|
||||||
|
// optional
|
||||||
|
title: { id: 'notification.default.title, defaultMessage: 'Warning: '}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user