-
Notifications
You must be signed in to change notification settings - Fork 27
/
show-notification.ts
36 lines (33 loc) 路 1.13 KB
/
show-notification.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import isNumber from 'lodash/isNumber';
import {
addNotification,
TNotificationMetaOptions,
} from '@commercetools-frontend/notifications';
import {
NOTIFICATION_DOMAINS,
NOTIFICATION_KINDS_SIDE,
} from '@commercetools-frontend/constants';
import { TShowNotification } from '../types';
export default function showNotification<
Notification extends TShowNotification
>(notification: Notification, meta: TNotificationMetaOptions = {}) {
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<Pick<Notification, 'id'>>(notification, {
...meta,
dismissAfter,
});
}