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