import dayjs from 'dayjs' import { ArrowRight, ExternalLink, Github } from 'lucide-react' import Image from 'next/legacy/image' import Link from 'next/link' import { forwardRef, HTMLAttributes, ReactNode, RefAttributes } from 'react' import { Badge, Button, cn } from 'ui' import { Markdown } from '@/components/interfaces/Markdown' import { ButtonTooltip } from '@/components/ui/ButtonTooltip' import type { Integration, IntegrationProjectConnection, } from '@/data/integrations/integrations.types' import { useProjectDetailQuery } from '@/data/projects/project-detail-query' import { BASE_PATH } from '@/lib/constants' import { getFrameworkIconUrl, getIntegrationConfigurationUrl } from '@/lib/integration-utils' const ICON_STROKE_WIDTH = 2 const ICON_SIZE = 14 interface IntegrationInstallationProps extends RefAttributes { title: string integration: Integration disabled?: boolean } type HandleIconType = Integration['integration']['name'] | 'Supabase' const HandleIcon = ({ type, className }: { type: HandleIconType; className?: string }) => { switch (type) { case 'GitHub': return break // case 'Netlify': // return // break case 'Vercel': return ( ) break case 'Supabase': return Supabase break default: return <> break } } const Avatar = ({ src }: { src: string | undefined }) => { return (
avatar
) } const IntegrationIconBlock = ({ integration }: { integration: Integration }) => { return (
) } export const IntegrationInstallation = forwardRef( ({ integration, disabled, ...props }, ref) => { return (
  • {integration.metadata?.account.name || (integration.metadata !== undefined && 'gitHubConnectionOwner' in integration.metadata && integration.metadata?.gitHubConnectionOwner)} {integration.metadata?.account.type}
    Created {dayjs(integration.inserted_at).fromNow()} Added by {integration?.added_by?.primary_email}
  • ) } ) export interface IntegrationConnectionProps extends HTMLAttributes { connection: IntegrationProjectConnection type: Integration['integration']['name'] actions?: ReactNode showNode?: boolean orientation?: 'horizontal' | 'vertical' } export const IntegrationConnection = forwardRef( ( { connection, type, actions, showNode = true, orientation = 'horizontal', className, ...props }, ref ) => { const { data: project } = useProjectDetailQuery({ ref: connection.supabase_project_ref }) const frameworkIconUrl = getFrameworkIconUrl(connection?.metadata?.framework) return (
  • {showNode && (
    )}
    {project?.name}
    {!frameworkIconUrl ? (
    ) : ( {`icon`} )} {type === 'GitHub' ? ( {connection.metadata?.name} ) : ( {connection.metadata?.name} )}
    Connected {dayjs(connection?.inserted_at).fromNow()} Added by {connection?.added_by?.primary_email}
    {actions}
  • ) } ) export const IntegrationConnectionOption = forwardRef( ({ connection, type, ...props }, ref) => { const { data: project } = useProjectDetailQuery({ ref: connection.supabase_project_ref }) return (
  • {project?.name} {connection.metadata.name}
    Connected {dayjs(connection.inserted_at).fromNow()}
  • ) } ) type EmptyIntegrationConnectionProps = HTMLAttributes & { showNode?: boolean disabled?: boolean icon?: ReactNode disabledTooltip?: string } & ({ onClick: () => void; href?: never } | { href: string; onClick?: never }) export const EmptyIntegrationConnection = forwardRef< HTMLDivElement, EmptyIntegrationConnectionProps >( ( { className, showNode = true, onClick, href, disabled, icon, disabledTooltip = 'Additional permissions required to add connection', children, ...props }, ref ) => { const label = children ?? 'Add connection' return (
    {showNode && (
    )}
    {href && !disabled ? ( ) : ( onClick() : undefined} tooltip={{ content: { side: 'bottom', text: disabled ? disabledTooltip : undefined, }, }} > {label} )}
    ) } ) interface IntegrationConnectionHeader extends React.HTMLAttributes { name?: string markdown?: string showNode?: boolean } export const IntegrationConnectionHeader = forwardRef( ({ className, markdown = '', showNode = true, ...props }, ref) => { return (
    {props.title &&
    {props.title}
    }
    ) } ) IntegrationInstallation.displayName = 'IntegrationInstallation' IntegrationConnection.displayName = 'IntegrationConnection' IntegrationConnectionHeader.displayName = 'IntegrationConnectionHeader' EmptyIntegrationConnection.displayName = 'EmptyIntegrationConnection' IntegrationConnectionOption.displayName = 'IntegrationConnectionOption'