import React, { useState } from "react" import PropTypes from "prop-types" import { SnackbarKey, SnackbarMessage, useSnackbar } from "notistack" import Collapse from "@material-ui/core/Collapse" import Paper from "@material-ui/core/Paper" import Typography from "@material-ui/core/Typography" import Card from "@material-ui/core/Card" import CardActions from "@material-ui/core/CardActions" import Button from "@material-ui/core/Button" import IconButton from "@material-ui/core/IconButton" import CloseIcon from "@material-ui/icons/Close" import ExpandMoreIcon from "@material-ui/icons/ExpandMore" import CheckCircleIcon from "@material-ui/icons/OpenInNew" import { useStyles } from "./styles" import { SeverityType } from "@/core/notice/types" import { useTheme } from "@material-ui/core/styles" import { LocalDataRoute } from "@/utils/routes" import { useRouter } from "next/router" import { useSelector } from "react-redux" import { selectNotice } from "@/slices/noticeSlice" interface State { severity?: SeverityType content?: string | null } const SnackMessage = React.forwardRef( (props: { id: SnackbarKey; message: SnackbarMessage }, ref) => { const notice = useSelector(selectNotice) const router = useRouter() const theme = useTheme() const classes = useStyles() const { closeSnackbar } = useSnackbar() const [expanded, setExpanded] = useState(false) const [state, setState] = useState({}) const colors = { none: null, success: `linear-gradient(45deg, ${theme.palette.success.light} 30%, rgba(200, 200, 200, 0.88) 125%)`, error: `linear-gradient(45deg, ${theme.palette.error.light} 30%, rgba(200, 200, 200, 0.88) 125%)`, warning: `linear-gradient(45deg, ${theme.palette.warning.light} 30%, rgba(200, 200, 200, 0.88) 125%)`, info: `linear-gradient(45deg, ${theme.palette.info.light} 30%, rgba(200, 200, 200, 0.88) 125%)` } React.useEffect(() => { setState({ severity: notice.severity || "success", content: notice.content }) }, [notice]) const handleExpandClick = () => { setExpanded(!expanded) } const handleDismiss = () => { closeSnackbar(props.id) } return ( {props.message}
{state.content && ( )}
{state.content}
) } ) SnackMessage.propTypes = { id: PropTypes.number.isRequired } export default SnackMessage