import { useAppSelector } from "@/app/hooks"; import { Calendar } from "@/features/Calendars/CalendarTypes"; import { extractEventBaseUuid } from "@/utils/extractEventBaseUuid"; import { Box, TextField, ToggleButton, ToggleButtonGroup, Typography, useTheme, } from "@linagora/twake-mui"; import LockOutlineIcon from "@mui/icons-material/LockOutline"; import LayersOutlinedIcon from "@mui/icons-material/LayersOutlined"; import { alpha } from "@mui/material/styles"; import PublicIcon from "@mui/icons-material/Public"; import { useEffect, useMemo, useState } from "react"; import { useI18n } from "twake-i18n"; import { AddDescButton } from "../Event/AddDescButton"; import { ColorPicker } from "./CalendarColorPicker"; import { InfoRow } from "../Event/InfoRow"; export function SettingsTab({ name, setName, description, setDescription, color, setColor, visibility, setVisibility, calendar, }: { name: string; setName: (name: string) => void; description: string; setDescription: (d: string) => void; color: Record; setColor: (color: Record) => void; visibility: "public" | "private"; setVisibility: (visibility: "public" | "private") => void; calendar?: Calendar; }) { const { t } = useI18n(); const [toggleDesc, setToggleDesc] = useState(Boolean(description)); const userId = useAppSelector((state) => state.user.userData?.openpaasId) ?? ""; const isOwn = calendar ? extractEventBaseUuid(calendar.id) === userId : true; const theme = useTheme(); const infoIconColor = alpha(theme.palette.grey[900], 0.9); const infoIconSx = { minWidth: "25px", marginRight: 2, color: infoIconColor }; const isResource = useMemo( () => calendar?.owner?.resource, [calendar?.owner?.resource] ); useEffect(() => { if (description) setToggleDesc(true); }, [description]); return ( <> {/* Form group 1: Name field - first group, margin top 0 */} {t( isResource ? "calendarPopover.settings.resourceName" : "calendarPopover.settings.calendarName" )} {isResource ? ( } text={name} style={{ fontSize: "16px", fontFamily: "'Inter', sans-serif", }} /> ) : ( setName(e.target.value)} size="small" sx={{ "&.MuiFormControl-root": { marginTop: 0, marginBottom: 0, }, }} /> )} {/* Form group 2: Description */} {!isResource && ( )} {/* Form group 3: Color */} {t("calendar.color")} setColor(color)} selectedColor={color} /> {/* Form group 4: New events visibility */} {isOwn && ( {t("calendar.newEventsVisibility")} val && setVisibility(val)} size="medium" sx={{ borderRadius: "12px" }} > {t("common.all")} {t("common.you")} )} ); }