From 616927d388c9a77517c2fff45b82458698d14c5c Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 16 Jul 2025 10:32:19 -0700 Subject: [PATCH 1/3] Add new toast component --- client/src/Components/Toast/body.jsx | 34 +++++++++++ client/src/Components/Toast/index.jsx | 83 +++++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 client/src/Components/Toast/body.jsx create mode 100644 client/src/Components/Toast/index.jsx 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..4505b758b --- /dev/null +++ b/client/src/Components/Toast/index.jsx @@ -0,0 +1,83 @@ +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} + + )} + + + + + + + {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, +}; From c58801f6f727d591e9f8c12503d6e425fe51bd93 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 16 Jul 2025 10:33:06 -0700 Subject: [PATCH 2/3] update toastUtils to use Toast component --- client/src/Utils/toastUtils.jsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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, }; From 4cd5cd4bae7e5031942012565239740dae8a6745 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Wed, 16 Jul 2025 12:51:52 -0700 Subject: [PATCH 3/3] fix close icon placement for toasts without title --- client/src/Components/Toast/index.jsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/client/src/Components/Toast/index.jsx b/client/src/Components/Toast/index.jsx index 4505b758b..36df0e631 100644 --- a/client/src/Components/Toast/index.jsx +++ b/client/src/Components/Toast/index.jsx @@ -48,12 +48,25 @@ const Toast = ({ variant, title, body, onClick, hasDismiss, hasIcon }) => { {title} )} - - - + {title && ( + + + + )} - + + + {!title && ( + + + + )} + {hasDismiss && (