From add30754397ac16bbd4e17e916fe6f12872b1457 Mon Sep 17 00:00:00 2001 From: asharonbaltazar Date: Wed, 7 Dec 2022 11:52:18 -0500 Subject: [PATCH] feat: create prop for Notification; small readability changes --- .../context/Notifications/NotificationProvider.tsx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/frontend/components/context/Notifications/NotificationProvider.tsx b/frontend/components/context/Notifications/NotificationProvider.tsx index 723319615..644cb4fa9 100644 --- a/frontend/components/context/Notifications/NotificationProvider.tsx +++ b/frontend/components/context/Notifications/NotificationProvider.tsx @@ -7,6 +7,7 @@ type NotificationType = "success" | "error"; export type Notification = { text: string; type: NotificationType; + timeoutMs?: number; }; type NotificationContextState = { @@ -36,14 +37,20 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => { return setNotifications([]); }; - const createNotification = ({ text, type = "success" }: Notification) => { + const createNotification = ({ + text, + type = "success", + timeoutMs = 2000, + }: Notification) => { const doesNotifExist = notifications.some((notif) => notif.text === text); if (doesNotifExist) { return; } - return setNotifications((state) => [...state, { text, type }]); + const newNotification: Notification = { text, type, timeoutMs }; + + return setNotifications((state) => [...state, newNotification]); }; return (