diff --git a/src/frontend/src/alerts/notice/index.tsx b/src/frontend/src/alerts/notice/index.tsx index 540deec0d..350de8001 100644 --- a/src/frontend/src/alerts/notice/index.tsx +++ b/src/frontend/src/alerts/notice/index.tsx @@ -6,21 +6,32 @@ import { NoticeAlertType } from "../../types/alerts"; export default function NoticeAlert({ title, - link = "", + link, id, removeAlert, }: NoticeAlertType): JSX.Element { const [show, setShow] = useState(true); + useEffect(() => { - if (show) { + const timeoutId = setTimeout(() => { + setShow(false); + // Wait for the leave transition before calling removeAlert setTimeout(() => { - setShow(false); - setTimeout(() => { - removeAlert(id); - }, 500); - }, 5000); - } - }, [id, removeAlert, show]); + removeAlert(id); + }, 500); // match the duration of the leave transition + }, 5000); // auto-dismiss alert after 5 seconds + + return () => clearTimeout(timeoutId); // Cleanup timeout on component unmount or re-render + }, [id, removeAlert]); + + const handleClick = () => { + setShow(false); + // Wait for the leave transition before calling removeAlert + setTimeout(() => { + removeAlert(id); + }, 500); // Ensure the alert is removed after the animation + }; + return (
{ - setShow(false); - removeAlert(id); - }} + onClick={handleClick} className="noflow nowheel nopan nodelete nodrag mt-6 w-96 rounded-md bg-info-background p-4 shadow-xl" >
@@ -51,15 +59,13 @@ export default function NoticeAlert({ {title}

- {link !== "" ? ( + {link && ( Details - ) : ( - <> )}

diff --git a/src/frontend/src/types/alerts/index.ts b/src/frontend/src/types/alerts/index.ts index 18c7faf9b..8dfe0a1a4 100644 --- a/src/frontend/src/types/alerts/index.ts +++ b/src/frontend/src/types/alerts/index.ts @@ -6,7 +6,7 @@ export type ErrorAlertType = { }; export type NoticeAlertType = { title: string; - link: string | undefined; + link?: string; id: string; removeAlert: (id: string) => void; };