2018-10-24 14:33:53 +02:00
|
|
|
import { AppNotification, AppNotificationSeverity, AppNotificationTimeout } from 'app/types';
|
2019-02-06 19:42:04 +01:00
|
|
|
import { getMessageFromError } from 'app/core/utils/errors';
|
2018-10-24 14:33:53 +02:00
|
|
|
|
2019-08-05 12:07:35 +02:00
|
|
|
const defaultSuccessNotification = {
|
2018-10-24 14:33:53 +02:00
|
|
|
title: '',
|
|
|
|
|
text: '',
|
|
|
|
|
severity: AppNotificationSeverity.Success,
|
2020-04-12 22:20:02 +02:00
|
|
|
icon: 'check',
|
2018-10-24 14:33:53 +02:00
|
|
|
timeout: AppNotificationTimeout.Success,
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-05 12:07:35 +02:00
|
|
|
const defaultWarningNotification = {
|
2018-10-24 14:33:53 +02:00
|
|
|
title: '',
|
|
|
|
|
text: '',
|
|
|
|
|
severity: AppNotificationSeverity.Warning,
|
2020-04-12 22:20:02 +02:00
|
|
|
icon: 'exclamation-triangle',
|
2018-10-24 14:33:53 +02:00
|
|
|
timeout: AppNotificationTimeout.Warning,
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-05 12:07:35 +02:00
|
|
|
const defaultErrorNotification = {
|
2018-10-24 14:33:53 +02:00
|
|
|
title: '',
|
|
|
|
|
text: '',
|
|
|
|
|
severity: AppNotificationSeverity.Error,
|
2020-04-12 22:20:02 +02:00
|
|
|
icon: 'exclamation-triangle',
|
2018-10-24 14:33:53 +02:00
|
|
|
timeout: AppNotificationTimeout.Error,
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-14 09:27:47 +01:00
|
|
|
export const createSuccessNotification = (title: string, text = ''): AppNotification => ({
|
2018-10-24 14:33:53 +02:00
|
|
|
...defaultSuccessNotification,
|
|
|
|
|
title: title,
|
|
|
|
|
text: text,
|
|
|
|
|
id: Date.now(),
|
|
|
|
|
});
|
|
|
|
|
|
2019-11-14 10:59:41 +01:00
|
|
|
export const createErrorNotification = (title: string, text = '', component?: React.ReactElement): AppNotification => {
|
2019-02-05 14:42:29 +01:00
|
|
|
return {
|
|
|
|
|
...defaultErrorNotification,
|
2019-02-06 19:42:04 +01:00
|
|
|
text: getMessageFromError(text),
|
2019-11-14 10:59:41 +01:00
|
|
|
title,
|
2019-02-05 14:42:29 +01:00
|
|
|
id: Date.now(),
|
2019-11-14 10:59:41 +01:00
|
|
|
component,
|
2019-02-05 14:42:29 +01:00
|
|
|
};
|
|
|
|
|
};
|
2018-10-24 14:33:53 +02:00
|
|
|
|
2019-10-14 09:27:47 +01:00
|
|
|
export const createWarningNotification = (title: string, text = ''): AppNotification => ({
|
2018-10-24 14:33:53 +02:00
|
|
|
...defaultWarningNotification,
|
|
|
|
|
title: title,
|
|
|
|
|
text: text,
|
|
|
|
|
id: Date.now(),
|
|
|
|
|
});
|