import Link from 'next/link' import { useRouter } from 'next/router' import { forwardRef, useCallback, useState } from 'react' import toast from 'react-hot-toast' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger, IconChevronDown, IconLoader, IconRefreshCw, IconTrash, Modal, } from 'ui' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' import { IntegrationConnection, IntegrationConnectionProps, } from 'components/interfaces/Integrations/IntegrationPanels' import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation' import type { IntegrationProjectConnection } from 'data/integrations/integrations.types' import { useProjectsQuery } from 'data/projects/projects-query' import { WarningIcon } from 'ui-patterns/Icons/StatusIcons' interface IntegrationConnectionItemProps extends IntegrationConnectionProps { disabled?: boolean onDeleteConnection: (connection: IntegrationProjectConnection) => void | Promise } const IntegrationConnectionItem = forwardRef( ({ disabled, onDeleteConnection, ...props }, ref) => { const router = useRouter() const { type, connection } = props const { data: projects } = useProjectsQuery() const project = projects?.find((project) => project.ref === connection.supabase_project_ref) const isBranchingEnabled = project?.is_branch_enabled === true const [isOpen, setIsOpen] = useState(false) const [dropdownVisible, setDropdownVisible] = useState(false) const onConfirm = useCallback(async () => { try { await onDeleteConnection(connection) } finally { setIsOpen(false) } }, [connection, onDeleteConnection]) const onCancel = useCallback(() => { setIsOpen(false) }, []) const { mutate: syncEnvs, isLoading: isSyncEnvLoading } = useIntegrationsVercelConnectionSyncEnvsMutation({ onSuccess: () => { toast.success('Successfully synced environment variables') setDropdownVisible(false) }, }) const onReSyncEnvVars = useCallback(async () => { syncEnvs({ connectionId: connection.id }) }, [connection, syncEnvs]) const projectIntegrationUrl = `/project/[ref]/settings/integrations` return ( <> } type="default"> Manage ) : ( setDropdownVisible(!dropdownVisible)} modal={false} > {router.pathname !== projectIntegrationUrl && ( Configure connection )} {type === 'Vercel' && ( { event.preventDefault() onReSyncEnvVars() }} disabled={isSyncEnvLoading} > {isSyncEnvLoading ? ( ) : ( )}

Resync environment variables

)} {(type === 'Vercel' || router.pathname !== projectIntegrationUrl) && ( )} setIsOpen(true)}>

Delete connection

) } {...props} /> {type === 'GitHub' && isBranchingEnabled && ( Branching will be disabled for this project Deleting this GitHub connection will remove all preview branches on this project, and also disable branching for {project.name} )}

This action cannot be undone. Are you sure you want to delete this {type} connection?

) } ) IntegrationConnectionItem.displayName = 'IntegrationConnectionItem' export { IntegrationConnectionItem }