From 6074192510112d1055e3f1cbe1864cf45ded2745 Mon Sep 17 00:00:00 2001 From: karishmas6 Date: Sat, 15 Jun 2024 21:02:17 +0530 Subject: [PATCH] feat: alert --- src/components/atoms/AlertSnackbar.tsx | 40 ++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 src/components/atoms/AlertSnackbar.tsx diff --git a/src/components/atoms/AlertSnackbar.tsx b/src/components/atoms/AlertSnackbar.tsx new file mode 100644 index 00000000..0b3a5382 --- /dev/null +++ b/src/components/atoms/AlertSnackbar.tsx @@ -0,0 +1,40 @@ +import * as React from 'react'; +import Snackbar from '@mui/material/Snackbar'; +import MuiAlert, { AlertProps } from '@mui/material/Alert'; +import { useGlobalInfoStore } from "../../context/globalInfo"; + +const Alert = React.forwardRef(function Alert( + props, + ref, +) { + return ; +}); + +export interface AlertSnackbarProps { + severity: 'error' | 'warning' | 'info' | 'success', + message: string, + isOpen: boolean, +}; + +export const AlertSnackbar = ({ severity, message, isOpen }: AlertSnackbarProps) => { + const [open, setOpen] = React.useState(isOpen); + + const { closeNotify } = useGlobalInfoStore(); + + const handleClose = (event?: React.SyntheticEvent | Event, reason?: string) => { + if (reason === 'clickaway') { + return; + } + + closeNotify(); + setOpen(false); + }; + + return ( + + + {message} + + + ); +}