"use client"; import { cn } from "@/app/_lib/utils"; import { Dialog, DialogContent, DialogTrigger, } from "@/app/_components/ui/dialog"; import { ScrollArea } from "@/app/_components/ui/scroll-area"; import { Separator } from "@/app/_components/ui/separator"; import { Avatar, AvatarFallback, AvatarImage, } from "@/app/_components/ui/avatar"; import { IconAdjustmentsHorizontal, IconBaselineDensityLarge, IconBell, IconFileExport, IconFileImport, IconFingerprint, IconLock, IconPlugConnected, IconSettings, IconUser, IconUsers, IconWorld, } from "@tabler/icons-react"; import { ProfileSettings } from "./profile-settings"; import { DialogTitle } from "@radix-ui/react-dialog"; import { useState } from "react"; import NotificationsSetting from "./notification-settings"; import PreferencesSettings from "./preference-settings"; import ImportData from "./import-data"; import { IUserSchema } from "@/src/entities/models/users/users.model"; import { useUserStore } from "@/app/_utils/zustand/stores/user"; interface SettingsDialogProps { trigger: React.ReactNode; defaultTab?: string; open?: boolean; onOpenChange?: (open: boolean) => void; } interface SettingsTab { id: string; icon: typeof IconUser; title: string; content: React.ReactNode; } interface SettingsSection { title: string; tabs: SettingsTab[]; } export function SettingsDialog({ trigger, defaultTab = "account", open, onOpenChange, }: SettingsDialogProps) { const { user, isPending } = useUserStore(); const [selectedTab, setSelectedTab] = useState(defaultTab); // Get user display name const preferredName = user?.profile?.username || ""; const userEmail = user?.email || ""; const displayName = preferredName || userEmail?.split("@")[0] || "User"; const userAvatar = user?.profile?.avatar || ""; const sections: SettingsSection[] = [ { title: "Account", tabs: [ { id: "account", icon: IconUser, title: "My Account", content: , }, { id: "preferences", icon: IconAdjustmentsHorizontal, title: "Preferences", content: , }, { id: "notifications", icon: IconBell, title: "Notifications", content: , }, ], }, { title: "Workspace", tabs: [ { id: "import", icon: IconFileImport, title: "Import", content: , }, { id: "export", icon: IconFileExport, title: "Export", content:
Export
, }, ], }, ]; const currentTab = sections .flatMap((section) => section.tabs) .find((tab) => tab.id === selectedTab); return ( {trigger}
{/* Sidebar */}
{isPending ? (
) : ( {displayName[0].toUpperCase()} )} {isPending ? (
) : ( displayName )}
{sections.map((section, index) => (

{section.title}

{section.tabs.map((tab) => ( ))}
{index < sections.length - 1 && ( )}
))}
{/* Content */}
{isPending ? (
) : ( currentTab?.content )}
); }