"use client" import { MenuIcon } from "lucide-react" import { useContext, useEffect, useMemo } from "react" import { useAuthenticate } from "../../hooks/use-authenticate" import { useCurrentOrganization } from "../../hooks/use-current-organization" import { AuthUIContext } from "../../lib/auth-ui-provider" import { cn, getViewByPath } from "../../lib/utils" import type { OrganizationViewPath } from "../../server" import type { AccountViewProps } from "../account/account-view" import { ApiKeysCard } from "../settings/api-key/api-keys-card" import { Button } from "../ui/button" import { Drawer, DrawerContent, DrawerHeader, DrawerTitle, DrawerTrigger } from "../ui/drawer" import { Label } from "../ui/label" import { OrganizationInvitationsCard } from "./organization-invitations-card" import { OrganizationMembersCard } from "./organization-members-card" import { OrganizationSettingsCards } from "./organization-settings-cards" import { TeamsCard } from "./teams-card" export type OrganizationViewPageProps = Omit & { slug?: string view?: OrganizationViewPath } export function OrganizationView({ className, classNames, localization: localizationProp, path: pathProp, pathname, view: viewProp, hideNav, slug: slugProp }: OrganizationViewPageProps) { const { teams: teamOptions, organization: organizationOptions, localization: contextLocalization, account: accountOptions, Link, replace } = useContext(AuthUIContext) const { slug: contextSlug, viewPaths, apiKey } = organizationOptions || {} const { enabled: teamsEnabled } = teamOptions || {} useAuthenticate() const localization = useMemo( () => ({ ...contextLocalization, ...localizationProp }), [contextLocalization, localizationProp] ) const path = pathProp ?? pathname?.split("/").pop() const view = viewProp || getViewByPath(viewPaths!, path) || "SETTINGS" const slug = slugProp || contextSlug const { data: organization, isPending: organizationPending, isRefetching: organizationRefetching } = useCurrentOrganization({ slug }) const navItems: { view: OrganizationViewPath label: string }[] = [ { view: "SETTINGS", label: localization.SETTINGS }, { view: "MEMBERS", label: localization.MEMBERS } ] if (teamsEnabled) { navItems.push({ view: "TEAMS", label: localization.TEAMS }) } if (apiKey) { navItems.push({ view: "API_KEYS", label: localization.API_KEYS }) } useEffect(() => { if (organization || organizationPending || organizationRefetching) return replace( `${accountOptions?.basePath}/${accountOptions?.viewPaths?.ORGANIZATIONS}` ) }, [ organization, organizationPending, organizationRefetching, accountOptions?.basePath, accountOptions?.viewPaths?.ORGANIZATIONS, replace ]) return (
{!hideNav && (
{localization.ORGANIZATION}
{navItems.map((item) => ( ))}
)} {!hideNav && (
{navItems.map((item) => ( ))}
)} {view === "MEMBERS" && (
)} {view === "TEAMS" && organization?.id && teamsEnabled && ( )} {view === "API_KEYS" && ( )} {view === "SETTINGS" && ( )}
) }