Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | 1x 1x | import React from "react"; import { Snackbar, SnackbarCloseReason, Alert, Theme } from "@mui/material"; import { makeStyles } from "@mui/styles"; interface Props { message?: string; type: string; open: boolean; setOpen: Function; } const useStyles = makeStyles((theme: Theme) => ({ root: { width: "100%", "& > * + *": { marginTop: theme.spacing(1) } } })); const ToastAlert = ({ message = "", type, open, setOpen }: Props) => { const handleClose = (_: any, reason: SnackbarCloseReason) => { if (reason === "clickaway") { return; } setOpen(false); }; const classes = useStyles(); return message !== "" ? ( <div className={classes.root}> {type === "error" ? ( <Snackbar anchorOrigin={{ vertical: "top", horizontal: "center" }} open={open} autoHideDuration={2000} onClose={handleClose} > <Alert severity="error">{message}</Alert> </Snackbar> ) : ( <Snackbar anchorOrigin={{ vertical: "top", horizontal: "center" }} open={open} autoHideDuration={2000} onClose={handleClose} > <Alert severity="success">{message}</Alert> </Snackbar> )} </div> ) : null; }; export default ToastAlert; |