"use client" import { MenuIcon } from "lucide-react" import { useContext, useMemo } from "react" import { useAuthenticate } from "../../hooks/use-authenticate" import { AuthUIContext } from "../../lib/auth-ui-provider" import { cn, getViewByPath } from "../../lib/utils" import type { AuthLocalization } from "../../localization/auth-localization" import type { AccountViewPath } from "../../server" import { OrganizationsCard } from "../organization/organizations-card" import { UserInvitationsCard } from "../organization/user-invitations-card" import { AccountSettingsCards } from "../settings/account-settings-cards" import { ApiKeysCard } from "../settings/api-key/api-keys-card" import { SecuritySettingsCards } from "../settings/security-settings-cards" import type { SettingsCardClassNames } from "../settings/shared/settings-card" import { UserTeamsCard } from "../settings/teams/user-teams-card" import { Button } from "../ui/button" import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from "../ui/drawer" import { Label } from "../ui/label" export interface AccountViewProps { className?: string classNames?: { base?: string cards?: string drawer?: { menuItem?: string } sidebar?: { base?: string; button?: string; buttonActive?: string } card?: SettingsCardClassNames } localization?: AuthLocalization path?: string pathname?: string view?: AccountViewPath hideNav?: boolean showTeams?: boolean } export function AccountView({ className, classNames, localization: localizationProp, path: pathProp, pathname, view: viewProp, hideNav, showTeams }: AccountViewProps) { const { apiKey, teams: teamOptions, localization: contextLocalization, organization, account: accountOptions, Link } = useContext(AuthUIContext) if (!accountOptions) { return null } const { enabled: teamsEnabled } = teamOptions || {} useAuthenticate() const localization = useMemo( () => ({ ...contextLocalization, ...localizationProp }), [contextLocalization, localizationProp] ) const path = pathProp ?? pathname?.split("/").pop() const view = viewProp || getViewByPath(accountOptions.viewPaths, path!) || "SETTINGS" const navItems: { view: AccountViewPath label: string }[] = [ { view: "SETTINGS", label: localization.ACCOUNT }, { view: "SECURITY", label: localization.SECURITY } ] if (teamsEnabled && showTeams) { navItems.push({ view: "TEAMS", label: localization.TEAMS }) } if (apiKey) { navItems.push({ view: "API_KEYS", label: localization.API_KEYS }) } if (organization) { navItems.push({ view: "ORGANIZATIONS", label: localization.ORGANIZATIONS }) } return (
{!hideNav && (
{localization.SETTINGS}
{navItems.map((item) => ( ))}
)} {!hideNav && (
{navItems.map((item) => ( ))}
)} {view === "SETTINGS" && ( )} {view === "SECURITY" && ( )} {view === "TEAMS" && teamsEnabled && showTeams && ( )} {view === "API_KEYS" && ( )} {view === "ORGANIZATIONS" && organization && (
)}
) }