Updated toast with prop, prop validation, and JSDocs.

This commit is contained in:
M M committed 2024-06-17 16:59:07 -07:00
1 parent a26d221f8f
commit 7fa3f95cd0
1 file changed
+25 -5
+25 -5
View File
@@ -1,19 +1,32 @@
import PropTypes from "prop-types";
import ComplexAlert from "../../Components/Icons/ComplexAlert/ComplexAlert"; import ComplexAlert from "../../Components/Icons/ComplexAlert/ComplexAlert";
import AnnouncementsDualButtonWithIcon from "../../Components/Announcements/AnnouncementsDualButtonWithIcon/AnnouncementsDualButtonWithIcon"; import AnnouncementsDualButtonWithIcon from "../../Components/Announcements/AnnouncementsDualButtonWithIcon/AnnouncementsDualButtonWithIcon";
import "react-toastify/dist/ReactToastify.css"; import "react-toastify/dist/ReactToastify.css";
import { toast, ToastContainer } from "react-toastify"; import { toast, ToastContainer } from "react-toastify";
import "./index.css"; import "./index.css";
const ToastComponent = () => { /**
* ToastComponent displays a notification that is triggered by error messages.
*
* @component
* @param {Object} props - The component props
* @param {string} props.subject - The subject or title of the toast message
* @param {string} props.body - The body content of the toast message
* @param {string} props.esc - The text for the dismiss action button
* @param {string} props.primary - The text for the primary action button
* @returns {JSX.Element} JSX element representing the ToastComponent
*/
const ToastComponent = ({ subject, body, esc, primary }) => {
const displayMsg = () => { const displayMsg = () => {
toast( toast(
({ closeToast, toastProps }) => ( ({ closeToast, toastProps }) => (
<AnnouncementsDualButtonWithIcon <AnnouncementsDualButtonWithIcon
icon={<ComplexAlert theme="red" />} icon={<ComplexAlert theme="red" />}
subject="There was a problem with that action" subject={subject}
body="Lorem ipsum dolor sit amet consectetur adipisicing elit. Aliquid pariatur, ipsum dolor." body={body}
esc="Dismiss" esc={esc}
primary="Learn more" primary={primary}
closeToast={closeToast} closeToast={closeToast}
/> />
), ),
@@ -29,4 +42,11 @@ const ToastComponent = () => {
); );
}; };
ToastComponent.propTypes = {
subject: PropTypes.string.isRequired,
body: PropTypes.string.isRequired,
esc: PropTypes.string.isRequired,
primary: PropTypes.string.isRequired,
};
export default ToastComponent; export default ToastComponent;