"use client"; import { useEffect, useId, useRef, useState } from "react"; import Link from "@/components/routing/app-link"; import { Button } from "@kandev/ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuTrigger, } from "@kandev/ui/dropdown-menu"; import { Tooltip, TooltipContent, TooltipTrigger } from "@kandev/ui/tooltip"; import { IconChevronDown, IconChevronRight, IconPlugConnected } from "@tabler/icons-react"; import { DestinationRows } from "@/components/navigation/destination-rows"; import { useAppDestinations } from "@/hooks/use-app-destinations"; import { useAppStore } from "@/components/state-provider"; import { workspaceSettingsHref } from "@/lib/settings/workspace-settings-tabs"; import { useTranslation } from "react-i18next"; import { cn } from "@/lib/utils"; type MobileIntegrationsSectionProps = { onNavigate: () => void; showSetup?: boolean; collapsible?: boolean; includePlugins?: boolean; omitDestinations?: string[]; }; const HOVER_CLOSE_DELAY_MS = 180; const INTEGRATIONS_LABEL = "common:integrations"; /** * Configured integration destinations, in manifest order. Ids, labels, hrefs and * icons come from `lib/navigation/core-destinations.ts`; availability comes from * `useNavAvailability` through `useAppDestinations`. */ function useIntegrationDestinations() { return useAppDestinations("sidebar", "integrations"); } export function IntegrationsMenu() { const { t } = useTranslation(); const links = useIntegrationDestinations(); const [open, setOpen] = useState(false); const closeTimeoutRef = useRef | null>(null); useEffect(() => { return () => { if (closeTimeoutRef.current) clearTimeout(closeTimeoutRef.current); }; }, []); const clearCloseTimeout = () => { if (!closeTimeoutRef.current) return; clearTimeout(closeTimeoutRef.current); closeTimeoutRef.current = null; }; const openOnHover = () => { clearCloseTimeout(); setOpen((current) => (current ? current : true)); }; const closeAfterHover = () => { clearCloseTimeout(); closeTimeoutRef.current = setTimeout(() => setOpen(false), HOVER_CLOSE_DELAY_MS); }; const handleOpenChange = (nextOpen: boolean) => { clearCloseTimeout(); setOpen(nextOpen); }; if (links.length === 0) return null; return ( {t(INTEGRATIONS_LABEL)} {links.map((link) => { const Icon = link.icon; return ( {link.label} ); })} ); } export function IntegrationsTopbarLinks() { const links = useIntegrationDestinations(); if (links.length === 0) return null; return ( <> {links.map((link) => { const Icon = link.icon; return ( {link.label} ); })} ); } /** * Mobile counterpart to the desktop sidebar Integrations section: the * hamburger-sheet surface that exposes the first-party integration links plus * any plugin-registered nav items targeting this section * (`registerNavItem({ section: "integrations" })`), matching the desktop * `IntegrationsSection`. Both come from the navigation manifest, so the two * surfaces cannot drift apart. */ export function MobileIntegrationsSection({ onNavigate, showSetup = false, collapsible = false, includePlugins, omitDestinations, }: MobileIntegrationsSectionProps) { const { t } = useTranslation(); const destinations = useAppDestinations("mobileMenu", "integrations").filter( (destination) => (includePlugins !== false || destination.source !== "plugin") && !omitDestinations?.includes(destination.id), ); const [expanded, setExpanded] = useState(false); const bodyId = useId(); if (destinations.length === 0 && !showSetup) return null; return (
{collapsible ? ( ) : (
{t(INTEGRATIONS_LABEL)}
)} {(!collapsible || expanded) && (
{showSetup && ( )}
)}
); } function MobileIntegrationSettingsLink({ onNavigate, grouped, }: { onNavigate: () => void; grouped: boolean; }) { const { t } = useTranslation(); const workspaceId = useAppStore((state) => state.workspaces.activeId); return ( ); }