// 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, //FieldWrapper's props gap, labelMb, labelFontWeight, labelVariant, labelSx = {}, sx = {}, }) => { // 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); }} labelMb={labelMb} labelVariant={labelVariant} labelFontWeight={labelFontWeight} labelSx={labelSx} gap={gap} sx={{ ...sx, }} /> {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;