import React, { useEffect, useState } from "react"; import { Group, Text, ScrollArea, ActionIcon } from "@mantine/core"; import { IconUser, IconSettings, IconUsers, IconArrowLeft, IconUsersGroup, IconSpaces, IconBrush, IconWorld, IconSparkles, } from "@tabler/icons-react"; import { Link, useLocation } from "react-router-dom"; import classes from "./settings.module.css"; import { useTranslation } from "react-i18next"; import { prefetchGroups, prefetchShares, prefetchSpaces, prefetchWorkspaceMembers, } from "@/components/settings/settings-queries.tsx"; import AppVersion from "@/components/settings/app-version.tsx"; import { mobileSidebarAtom } from "@/components/layouts/global/hooks/atoms/sidebar-atom.ts"; import { useToggleSidebar } from "@/components/layouts/global/hooks/hooks/use-toggle-sidebar.ts"; import { useSettingsNavigation } from "@/hooks/use-settings-navigation"; import { useAtom } from "jotai"; type DataItem = { label: string; icon: React.ElementType; path: string; }; type DataGroup = { heading: string; items: DataItem[]; }; const groupedData: DataGroup[] = [ { heading: "Account", items: [ { label: "Profile", icon: IconUser, path: "/settings/account/profile" }, { label: "Preferences", icon: IconBrush, path: "/settings/account/preferences", }, ], }, { heading: "Workspace", items: [ { label: "General", icon: IconSettings, path: "/settings/workspace" }, { label: "AI", icon: IconSparkles, path: "/settings/ai" }, { label: "Members", icon: IconUsers, path: "/settings/members" }, { label: "Groups", icon: IconUsersGroup, path: "/settings/groups" }, { label: "Spaces", icon: IconSpaces, path: "/settings/spaces" }, { label: "Public sharing", icon: IconWorld, path: "/settings/sharing" }, ], }, ]; export default function SettingsSidebar() { const { t } = useTranslation(); const location = useLocation(); const [active, setActive] = useState(location.pathname); const { goBack } = useSettingsNavigation(); const [mobileSidebarOpened] = useAtom(mobileSidebarAtom); const toggleMobileSidebar = useToggleSidebar(mobileSidebarAtom); useEffect(() => { setActive(location.pathname); }, [location.pathname]); const menuItems = groupedData.map((group) => { return (
{t(group.heading)} {group.items.map((item) => { let prefetchHandler: any; switch (item.label) { case "Members": prefetchHandler = prefetchWorkspaceMembers; break; case "Spaces": prefetchHandler = prefetchSpaces; break; case "Groups": prefetchHandler = prefetchGroups; break; case "Public sharing": prefetchHandler = prefetchShares; break; default: break; } return ( { if (mobileSidebarOpened) { toggleMobileSidebar(); } }} > {t(item.label)} ); })}
); }); return (
{ goBack(); if (mobileSidebarOpened) { toggleMobileSidebar(); } }} variant="transparent" c="gray" aria-label={t("Back")} > {t("Settings")} {menuItems}
); }