Files
front-AT/app/Components/AlertBox/AlertBox.tsx
T

42 lines
811 B
TypeScript
Raw Normal View History

2025-09-22 14:53:19 -06:00
"use client";
2025-09-17 19:42:13 -06:00
import { useEffect, useState } from "react";
import "./AlertBox.css";
interface AlertBoxProps {
2025-09-22 11:57:52 -06:00
message: string | null;
2025-09-17 19:42:13 -06:00
type: "error" | "success";
duration?: number;
}
2025-09-22 14:53:19 -06:00
export default function AlertBox({
message,
type,
duration = 6000,
}: AlertBoxProps) {
2025-09-17 19:42:13 -06:00
const [visible, setVisible] = useState(false);
const [text, setText] = useState("");
useEffect(() => {
if (message) {
setText(message);
setVisible(true);
const timeout = setTimeout(() => {
setVisible(false);
setTimeout(() => setText(""), 500);
}, duration);
return () => clearTimeout(timeout);
}
}, [message, duration]);
if (!text) return null;
return (
<div className={`messageBox ${type} ${!visible ? "hidden" : ""}`}>
{text}
</div>
);
}