import { useParams } from 'common' import { useRouter } from 'next/router' import { Menu, Separator } from 'ui' import { GenericSkeletonLoader } from 'ui-patterns' import { getCategoryParamFromAsPath, getIntegrationsPageFromPathname } from './Integrations.utils' import { generateIntegrationsMenu } from './IntegrationsMenu.utils' import { useInstalledIntegrations } from '@/components/interfaces/Integrations/Landing/useInstalledIntegrations' import AlertError from '@/components/ui/AlertError' import { ProductMenu } from '@/components/ui/ProductMenu' import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { getPathnameWithoutQuery } from '@/lib/pathname.utils' export function IntegrationsProductMenu() { const router = useRouter() const { ref: projectRef } = useParams() const { data: project } = useSelectedProjectQuery() const { integrationsWrappers: showWrappers } = useIsFeatureEnabled(['integrations:wrappers']) const resolvedProjectRef = projectRef ?? project?.ref const pathname = getPathnameWithoutQuery(router.asPath, router.pathname) const page = getIntegrationsPageFromPathname(pathname) const categoryParam = getCategoryParamFromAsPath(router.asPath) const { installedIntegrations: integrations, error, isLoading, isSuccess, isError, } = useInstalledIntegrations() const resolvedPage = page === 'integrations' ? categoryParam ? `integrations-${categoryParam}` : 'integrations' : page return ( <> {isSuccess && resolvedProjectRef ? ( ({ name: integration.name, label: integration.status, key: `integrations/${integration.id}`, url: `/project/${resolvedProjectRef}/integrations/${integration.id}/overview`, icon: (
{integration.icon({ className: 'p-1' })}
), items: [], })), }, ]} /> ) : (
Installed
} /> {isLoading && } {isError && ( )} )} ) }