Files
Checkmate/Client/src/Utils/toastUtils.jsx
T

44 lines
1.2 KiB
React
Raw Normal View History

2024-07-11 20:30:11 -04:00
import PropTypes from "prop-types";
2024-07-11 18:05:41 -04:00
import { toast } from "react-toastify";
import Alert from "../Components/Alert";
2024-07-11 20:30:11 -04:00
/**
* @param {object} props
* @param {'info' | 'error' | 'warning'} - The variant of the alert (e.g., "info", "error").
* @param {string} props.title - The title of the alert.
* @param {string} props.body - The body/content of the alert.
* @param {boolean} props.hasIcon - Whether the alert should include an icon.
* @param {object} [props.config] - Additional configuration props for the toast.
*/
2024-07-11 18:05:41 -04:00
export const createToast = ({ variant, title, body, hasIcon, config = {} }) => {
const toastConfig = {
2024-07-11 18:53:14 -04:00
position: "bottom-right",
2024-07-11 18:05:41 -04:00
autoClose: 3000,
hideProgressBar: true,
closeButton: false,
...config,
};
toast(
({ closeToast }) => (
<Alert
variant={variant}
title={title}
body={body}
isToast={true}
hasIcon={hasIcon}
onClick={closeToast}
/>
),
toastConfig
);
};
2024-07-11 20:30:11 -04:00
createToast.propTypes = {
variant: PropTypes.oneOf(["info", "error", "warning"]).isRequired,
title: PropTypes.string,
body: PropTypes.string,
hasIcon: PropTypes.bool,
config: PropTypes.object,
};