diff --git a/web/src/components/App.tsx b/web/src/components/App.tsx index eceefa9..c9299c5 100644 --- a/web/src/components/App.tsx +++ b/web/src/components/App.tsx @@ -1,7 +1,9 @@ +import Notifications from "./Notifications"; + const App: React.FC = () => { return ( <> - <> + ); }; diff --git a/web/src/components/Notifications.tsx b/web/src/components/Notifications.tsx new file mode 100644 index 0000000..7095e73 --- /dev/null +++ b/web/src/components/Notifications.tsx @@ -0,0 +1,80 @@ +import { useToast, type ToastPositionWithLogical, Box } from "@chakra-ui/react"; +import { useNuiEvent } from "../hooks/useNuiEvent"; +import { debugData } from "../utils/debugData"; + +interface Props { + title?: string; + description: string; + duration?: number; + position?: ToastPositionWithLogical; + status?: "info" | "warning" | "success" | "error"; + color?: string; + icon?: string; + id?: number; +} + +interface CustomProps { + style?: React.CSSProperties; + text: string; + duration?: number; + icon?: string; + position?: ToastPositionWithLogical; + id?: number; +} + +debugData([ + { + action: "notify", + data: { + description: "Dunak is nerd", + color: "red", + id: 1, + }, + }, +]); + +debugData([ + { + action: "customNotify", + data: { + text: "Dunak is nerd", + style: { + backgroundColor: "red", + color: "purple", + }, + }, + }, +]); + +const Notifications: React.FC = () => { + const toast = useToast(); + + // todo: figure out icon support + useNuiEvent("customNotify", (data) => { + if (data.id && toast.isActive(data.id)) return; + toast({ + duration: data.duration || 4000, + position: data.position || "top-right", + render: () => ( + + {data.text} + + ), + }); + }); + + useNuiEvent("notify", (data) => { + if (data.id && toast.isActive(data.id)) return; + toast({ + title: data.title, + description: data.description, + duration: data.duration || 4000, + position: data.position || "top-right", + status: data.status, + }); + }); + + return <>; +}; + +export default Notifications;