"use client" import type React from "react" 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, IconBell, IconFileExport, IconFileImport, IconUser } 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 { useGetCurrentUserQuery } from "../../dashboard/user-management/_queries/queries" 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 { data: user, isPending } = useGetCurrentUserQuery() const [selectedTab, setSelectedTab] = useState(defaultTab) if (!user || !user.profile) return
User not found
// 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}
)}
) }