function useNotifications()

in web/src/components/layout/notifications/notifications.logic.ts [21:47]


function useNotifications(): NotificationsType {
  const notifications = useRecoilValue(notificationsState);
  const setNotifications = useSetRecoilState(notificationsState);

  return {
    notifications,
    showErrorNotification,
  };

  function showErrorNotification({ header, content }: NotificationContents): void {
    const id = generateGuid();

    setNotifications((oldNotifications) => [{
      header,
      type: 'error',
      content,
      dismissible: true,
      dismissLabel: i18n.dismissLabel,
      id,
      onDismiss: () => removeNotification(id),
    }, ...oldNotifications]);
  }

  function removeNotification(id: string): void {
    setNotifications((oldNotifications) => oldNotifications.filter(n => n.id !== id));
  }
}