@croz/nrich-notification-core
Version:
Contains core utilities related to the nrich-notification module
83 lines (77 loc) • 2.75 kB
TypeScript
type NotificationSeverity = "INFO" | "WARNING" | "ERROR";
interface Notification {
/**
* Title of the notification.
*/
title: string;
/**
* Content of the notification (i.e. for exception
* notification this will contain resolved message for exception or 'Error occurred' text).
*/
content: string;
/**
* List of messages (i.e. for validation failure notification
* this will contain all validation failure messages).
*/
messageList: string[];
/**
* Severity indicating importance of notification.
*/
severity: NotificationSeverity;
/**
* Custom override data sent from the server. Each component library will have its own data here.
* For example current supported options in mui implementation are position and autoClose.
*/
uxNotificationOptions?: Record<string, unknown>;
/**
* Timestamp of notification.
*/
timestamp: Date;
}
interface NotificationResponse {
/**
* Notification
*/
notification: Notification;
}
/**
* Fetch API interceptor which clones the response and checks
* whether the response matches the proposed notification format.
*
* @returns A function which can be called to register the interceptor.
*/
declare const fetchNotificationInterceptor: () => void;
/**
* XHR interceptor which listens for the response to be acquired
* and checks whether the response matches the proposed notification format.
*
* @returns A function which can be called to register the interceptor.
*/
declare const xhrNotificationInterceptor: () => void;
type NotificationOptions = {
/**
* Array of current state notifications.
*/
notifications: Notification[];
/**
* Adds notification to state.
* @param notification notification to add
*/
add: (notification: Notification) => void;
/**
* Removes notification from state.
* @param notification
*/
remove: (notification: Notification) => void;
};
type UseNotifications = () => NotificationOptions;
/**
* A hook which simplifies the usage of the intercepted notification state.
* Uses the internal {@link useNotificationStore} hook for managing the notification state.
*
* @returns An array of options to access the notification state and remove a single notification.
*/
declare const useNotifications: UseNotifications;
declare const addNotification: (notification: Notification) => void;
declare const removeNotification: (notification: Notification) => void;
export { Notification, NotificationOptions, NotificationResponse, NotificationSeverity, UseNotifications, addNotification, fetchNotificationInterceptor, removeNotification, useNotifications, xhrNotificationInterceptor };