Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (process.env.NODE_ENV !== 'production')
if (notification.domain) {
if (!Object.values(NOTIFICATION_DOMAINS).includes(notification.domain))
// eslint-disable-next-line no-console
console.warn(
`Unknown notification domain "${notification.domain}"`,
notification
);
}
// eslint-disable-next-line no-console
else console.warn('Notification is missing domain', notification);
let dismissAfter = meta.dismissAfter;
if (!isNumber(dismissAfter))
dismissAfter =
notification.kind === NOTIFICATION_KINDS_SIDE.success ? 5000 : 0;
return addNotification>(notification, {
...meta,
dismissAfter,
});
}
await wait(() => {
expect(showNotification).toHaveBeenCalledWith(
expect.objectContaining({
domain: NOTIFICATION_DOMAINS.SIDE,
kind: NOTIFICATION_KINDS_SIDE.success,
text: 'foo',
}),
undefined
);
expect(dismiss).not.toHaveBeenCalled();
});
const getColorByType = (value: TAppNotificationKind) => {
switch (value) {
case NOTIFICATION_KINDS_SIDE.success:
return customProperties.colorPrimary;
case NOTIFICATION_KINDS_SIDE.info:
return customProperties.colorInfo;
case NOTIFICATION_KINDS_SIDE.error:
return customProperties.colorError;
case NOTIFICATION_KINDS_SIDE.warning:
return customProperties.colorWarning;
default:
return 'transparent';
}
};
NOTIFICATION_DOMAINS,
TAppNotificationDomain,
TAppNotificationKind,
NOTIFICATION_KINDS_SIDE,
} from '@commercetools-frontend/constants';
type Props = {
domain: TAppNotificationDomain;
kind: TAppNotificationKind;
text?: string;
meta?: { [key: string]: unknown };
dismissAfter?: number;
};
const defaultProps: Pick = {
domain: NOTIFICATION_DOMAINS.SIDE,
kind: NOTIFICATION_KINDS_SIDE.success,
};
const Notifier = (props: Props) => {
const showNotification = globalActions.useShowNotification<
Props & { id: number }
>();
React.useEffect(() => {
const notification = showNotification(
{
id: 0,
domain: props.domain,
kind: props.kind,
text: props.text,
},
isNumber(props.dismissAfter)
return (
{
dispatch(removeNotification(notification.id));
}}
/>
);
}
switch (notification.kind) {
case NOTIFICATION_KINDS_SIDE.error:
case NOTIFICATION_KINDS_SIDE.warning:
case NOTIFICATION_KINDS_SIDE.info:
case NOTIFICATION_KINDS_SIDE.success:
return (
{
dispatch(removeNotification(notification.id));
}}
/>
);
default:
return null;
}
})}