Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | 1x 1x 1x 1x 1x 1x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x | import { ExpandMore } from "@mui/icons-material";
import {
Accordion,
AccordionDetails,
AccordionSummary,
styled,
Typography,
} from "@mui/material";
import { NOTIFICATIONS } from "i18n/namespaces";
import { useTranslation } from "next-i18next";
import { useEffect, useState } from "react";
import { GroupAction, NotificationType } from "./EditNotificationSettingsPage";
import NotificationSettingsSubListItem from "./NotificationSettingsSubListItem";
import { mapNotificationSettingsTypeToIcon } from "./utils/constants";
interface NotificationSettingsListItemProps {
items: GroupAction[];
type: NotificationType;
isExpanded?: boolean;
}
const StyledAccordion = styled(Accordion)(({ theme }) => ({
"&:not(:first-of-type)": {
borderTop: `1px solid ${theme.palette.divider}`,
},
"&:before": {
display: "none",
},
boxShadow: "none",
}));
const StyledAccordionSummary = styled(AccordionSummary)(({ theme }) => ({
"& .MuiAccordionSummary-content": {
alignItems: "center",
},
}));
export default function NotificationSettingsListItem({
items,
type,
isExpanded = false,
}: NotificationSettingsListItemProps) {
const notificationType =
type as `notifications:notification_settings.edit_preferences.list_items.${NotificationType}`;
const { t } = useTranslation([NOTIFICATIONS], {
keyPrefix: "notification_settings.edit_preferences.list_items",
});
const [isCollapseOpen, setIsCollapseOpen] = useState<boolean>(false);
// Update local state when global state changes
useEffect(() => {
setIsCollapseOpen(isExpanded);
}, [isExpanded]);
const handleCollapseClick = () => {
setIsCollapseOpen(!isCollapseOpen);
};
const renderItems = () =>
items
.filter((item) => item.userEditable)
.map((item) => (
<NotificationSettingsSubListItem
key={`${item.topic}:${item.action}`}
topic={item.topic}
action={item.action}
push={item.push}
email={item.email}
/>
));
return (
<StyledAccordion expanded={isCollapseOpen} onChange={handleCollapseClick}>
<StyledAccordionSummary expandIcon={<ExpandMore />}>
<div style={{ display: "flex", alignItems: "center", gap: "16px" }}>
{mapNotificationSettingsTypeToIcon[type]}
<Typography variant="h3">{t(notificationType)}</Typography>
</div>
</StyledAccordionSummary>
<AccordionDetails>{renderItems()}</AccordionDetails>
</StyledAccordion>
);
}
|