From ff11a911903028d7ad660087d7c55a96390906c9 Mon Sep 17 00:00:00 2001 From: Alex Holliday Date: Mon, 9 Jun 2025 12:57:02 +0800 Subject: [PATCH] add notification config component --- .../Components/NotificationConfig/index.jsx | 106 ++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 client/src/Components/NotificationConfig/index.jsx diff --git a/client/src/Components/NotificationConfig/index.jsx b/client/src/Components/NotificationConfig/index.jsx new file mode 100644 index 000000000..d3707eae4 --- /dev/null +++ b/client/src/Components/NotificationConfig/index.jsx @@ -0,0 +1,106 @@ +// Components +import Stack from "@mui/material/Stack"; +import Typography from "@mui/material/Typography"; +import Divider from "@mui/material/Divider"; +import DeleteOutlineRoundedIcon from "@mui/icons-material/DeleteOutlineRounded"; +import Search from "../Inputs/Search"; + +// Utils +import { useState, useEffect } from "react"; +import { useTheme } from "@mui/material/styles"; +import PropTypes from "prop-types"; + +const NotificationConfig = ({ notifications, setMonitor, setNotifications }) => { + // Local state + const [notificationsSearch, setNotificationsSearch] = useState(""); + const [selectedNotifications, setSelectedNotifications] = useState([]); + + const handleSearch = (value) => { + setSelectedNotifications(value); + setMonitor((prev) => { + return { + ...prev, + notifications: value.map((notification) => notification._id), + }; + }); + }; + + // Handlers + const handleDelete = (id) => { + const updatedNotifications = selectedNotifications.filter( + (notification) => notification._id !== id + ); + + setSelectedNotifications(updatedNotifications); + setMonitor((prev) => { + return { + ...prev, + notifications: updatedNotifications.map((notification) => notification._id), + }; + }); + }; + + // Setup + const theme = useTheme(); + + useEffect(() => { + if (setNotifications) { + const toSet = setNotifications.map((notification) => { + return notifications.find((n) => n._id === notification); + }); + setSelectedNotifications(toSet); + } + }, [setNotifications, notifications]); + + return ( + + { + handleSearch(value); + }} + /> + + {selectedNotifications.map((notification, index) => ( + + + {notification.notificationName} + + { + handleDelete(notification._id); + }} + sx={{ cursor: "pointer" }} + /> + {index < selectedNotifications.length - 1 && } + + ))} + + + ); +}; + +NotificationConfig.propTypes = { + notifications: PropTypes.array, + setMonitor: PropTypes.func, + setNotifications: PropTypes.array, +}; + +export default NotificationConfig;