From 7cdafe0eedcac5748c371fc28ee201ff2454642d Mon Sep 17 00:00:00 2001 From: Vladyslav Matsiiako Date: Sun, 11 Dec 2022 13:01:40 -0500 Subject: [PATCH] Updated notifications --- .../context/Notifications/Notification.tsx | 40 +++++++++++-------- .../Notifications/NotificationProvider.tsx | 14 +++---- .../context/Notifications/Notifications.tsx | 8 ++-- 3 files changed, 34 insertions(+), 28 deletions(-) diff --git a/frontend/components/context/Notifications/Notification.tsx b/frontend/components/context/Notifications/Notification.tsx index e473ddb52..ad556a6f5 100644 --- a/frontend/components/context/Notifications/Notification.tsx +++ b/frontend/components/context/Notifications/Notification.tsx @@ -1,9 +1,8 @@ -import { useEffect, useRef } from "react"; -import { faXmarkCircle } from "@fortawesome/free-solid-svg-icons"; -import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; -import classnames from "classnames"; +import { useEffect, useRef } from 'react'; +import { faX } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { Notification as NotificationType } from "./NotificationProvider"; +import { Notification as NotificationType } from './NotificationProvider'; interface NotificationProps { notification: Required; @@ -12,7 +11,7 @@ interface NotificationProps { const Notification = ({ notification, - clearNotification, + clearNotification }: NotificationProps) => { const timeout = useRef(); @@ -37,22 +36,29 @@ const Notification = ({ return (
-

{notification.text}

+ {notification.type === 'error' && ( +
+ )} + {notification.type === 'success' && ( +
+ )} + {notification.type === 'info' && ( +
+ )} +

+ {notification.text} +

); diff --git a/frontend/components/context/Notifications/NotificationProvider.tsx b/frontend/components/context/Notifications/NotificationProvider.tsx index b029dc6c6..05f9eee19 100644 --- a/frontend/components/context/Notifications/NotificationProvider.tsx +++ b/frontend/components/context/Notifications/NotificationProvider.tsx @@ -1,8 +1,8 @@ -import { createContext, ReactNode, useContext, useState } from "react"; +import { createContext, ReactNode, useContext, useState } from 'react'; -import Notifications from "./Notifications"; +import Notifications from './Notifications'; -type NotificationType = "success" | "error" | "info"; +type NotificationType = 'success' | 'error' | 'info'; export type Notification = { text: string; @@ -15,7 +15,7 @@ type NotificationContextState = { }; const NotificationContext = createContext({ - createNotification: () => console.log("createNotification not set!"), + createNotification: () => console.log('createNotification not set!') }); export const useNotificationContext = () => useContext(NotificationContext); @@ -37,8 +37,8 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => { const createNotification = ({ text, - type = "success", - timeoutMs = 2000, + type = 'success', + timeoutMs = 5000 }: Notification) => { const doesNotifExist = notifications.some((notif) => notif.text === text); @@ -54,7 +54,7 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => { return ( []; @@ -8,14 +8,14 @@ interface NoticationsProps { const Notifications = ({ notifications, - clearNotification, + clearNotification }: NoticationsProps) => { if (!notifications.length) { return null; } return ( -
+
{notifications.map((notif) => (