diff --git a/client/src/Components/Toast/body.jsx b/client/src/Components/Toast/body.jsx new file mode 100644 index 000000000..04d5aee99 --- /dev/null +++ b/client/src/Components/Toast/body.jsx @@ -0,0 +1,34 @@ +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; + +import { useTheme } from "@emotion/react"; +import PropTypes from "prop-types"; + +const ToastBody = ({ body }) => { + const theme = useTheme(); + + if (Array.isArray(body)) { + return ( + + {body.map((item, idx) => ( + + {item} + + ))} + + ); + } else if (typeof body === "string") { + return {body}; + } + + return null; +}; + +ToastBody.propTypes = { + body: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), +}; + +export default ToastBody; diff --git a/client/src/Components/Toast/index.jsx b/client/src/Components/Toast/index.jsx new file mode 100644 index 000000000..36df0e631 --- /dev/null +++ b/client/src/Components/Toast/index.jsx @@ -0,0 +1,96 @@ +import Stack from "@mui/material/Stack"; +import IconButton from "@mui/material/IconButton"; +import Typography from "@mui/material/Typography"; +import Button from "@mui/material/Button"; +import ToastBody from "./body"; +import InfoOutlinedIcon from "@mui/icons-material/InfoOutlined"; +import ErrorOutlineOutlinedIcon from "@mui/icons-material/ErrorOutlineOutlined"; +import WarningAmberOutlinedIcon from "@mui/icons-material/WarningAmberOutlined"; +import CloseIcon from "@mui/icons-material/Close"; + +// Utils +import { useTheme } from "@emotion/react"; +import PropTypes from "prop-types"; + +const icons = { + info: , + error: , + warning: , +}; + +const Toast = ({ variant, title, body, onClick, hasDismiss, hasIcon }) => { + const theme = useTheme(); + const icon = icons[variant]; + + return ( + + + {hasIcon && icon} + {title && ( + + {title} + + )} + {title && ( + + + + )} + + + + + {!title && ( + + + + )} + + {hasDismiss && ( + + )} + + ); +}; + +export default Toast; + +Toast.propTypes = { + variant: PropTypes.string.isRequired, + title: PropTypes.string, + body: PropTypes.oneOfType([PropTypes.string, PropTypes.array]), + hasDismiss: PropTypes.bool, + hasIcon: PropTypes.bool, + onClick: PropTypes.func, +}; diff --git a/client/src/Utils/toastUtils.jsx b/client/src/Utils/toastUtils.jsx index dbec9117e..21cf13e2b 100644 --- a/client/src/Utils/toastUtils.jsx +++ b/client/src/Utils/toastUtils.jsx @@ -1,7 +1,6 @@ import PropTypes from "prop-types"; import { toast, Slide } from "react-toastify"; -import Alert from "../Components/Alert"; - +import Toast from "../Components/Toast"; /** * @param {object} props * @param {'info' | 'error' | 'warning'} - The variant of the alert (e.g., "info", "error"). @@ -15,6 +14,7 @@ export const createToast = ({ variant = "info", title, body, + hasDismiss = false, hasIcon = false, config = {}, }) => { @@ -29,13 +29,14 @@ export const createToast = ({ toast( ({ closeToast }) => ( - ), toastConfig @@ -47,5 +48,6 @@ createToast.propTypes = { title: PropTypes.string, body: PropTypes.string.isRequired, hasIcon: PropTypes.bool, + hasDismiss: PropTypes.bool, config: PropTypes.object, };