mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-07 19:28:09 +00:00
feat: create prop for Notification; small readability changes
This commit is contained in:
@@ -7,6 +7,7 @@ type NotificationType = "success" | "error";
|
|||||||
export type Notification = {
|
export type Notification = {
|
||||||
text: string;
|
text: string;
|
||||||
type: NotificationType;
|
type: NotificationType;
|
||||||
|
timeoutMs?: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
type NotificationContextState = {
|
type NotificationContextState = {
|
||||||
@@ -36,14 +37,20 @@ const NotificationProvider = ({ children }: NotificationProviderProps) => {
|
|||||||
return setNotifications([]);
|
return setNotifications([]);
|
||||||
};
|
};
|
||||||
|
|
||||||
const createNotification = ({ text, type = "success" }: Notification) => {
|
const createNotification = ({
|
||||||
|
text,
|
||||||
|
type = "success",
|
||||||
|
timeoutMs = 2000,
|
||||||
|
}: Notification) => {
|
||||||
const doesNotifExist = notifications.some((notif) => notif.text === text);
|
const doesNotifExist = notifications.some((notif) => notif.text === text);
|
||||||
|
|
||||||
if (doesNotifExist) {
|
if (doesNotifExist) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return setNotifications((state) => [...state, { text, type }]);
|
const newNotification: Notification = { text, type, timeoutMs };
|
||||||
|
|
||||||
|
return setNotifications((state) => [...state, newNotification]);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user