import { PlusIcon } from 'lucide-react' import { useState } from 'react' import { toast } from 'sonner' import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle, Button, Card, CardContent, cn, } from 'ui' import { PageSection, PageSectionContent, PageSectionDescription, PageSectionMeta, PageSectionSummary, PageSectionTitle, } from 'ui-patterns/PageSection' import { IntegrationSectionIcon } from '../IntegrationsSettings' import { getConnectionTitle } from './AWSPrivateLink.utils' import { AWSPrivateLinkAccountItem } from './AWSPrivateLinkAccountItem' import { AWSPrivateLinkAttentionAdmonition } from './AWSPrivateLinkAttentionAdmonition' import { AWSPrivateLinkForm } from './AWSPrivateLinkForm' import { ResourceList } from '@/components/ui/Resource/ResourceList' import { UpgradeToPro } from '@/components/ui/UpgradeToPro' import { useAWSAccountDeleteMutation } from '@/data/aws-accounts/aws-account-delete-mutation' import type { AWSAccount } from '@/data/aws-accounts/aws-accounts-query' import { useAWSAccountsQuery } from '@/data/aws-accounts/aws-accounts-query' import { formatDatabaseID } from '@/data/read-replicas/replicas.utils' import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements' import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject' import { IS_PLATFORM } from '@/lib/constants' export const AWSPrivateLinkSection = () => { const { data: project } = useSelectedProjectQuery() const { data: accounts } = useAWSAccountsQuery({ projectRef: project?.ref }) const [selectedAccount, setSelectedAccount] = useState() const [showForm, setShowForm] = useState(false) const [showDeleteModal, setShowDeleteModal] = useState(false) const { mutateAsync: deleteAccount, isPending: isDeleting } = useAWSAccountDeleteMutation({ onSuccess: () => { toast.success('Connection will be deleted shortly') setShowDeleteModal(false) setShowForm(false) setSelectedAccount(undefined) }, }) const { hasAccess: hasPrivateLinkAccess } = useCheckEntitlements('security.private_link') const promptPlanUpgrade = IS_PLATFORM && !hasPrivateLinkAccess const onAddAccount = () => { setSelectedAccount(undefined) setShowForm(true) } const onEditAccount = (account: AWSAccount) => { setSelectedAccount(account) setShowForm(true) } const onConfirmDelete = async () => { if (!selectedAccount || !project) return await deleteAccount({ projectRef: project.ref, awsAccountId: selectedAccount.aws_account_id, databaseIdentifier: selectedAccount.database_type === 'READ_REPLICA' ? selectedAccount.database_identifier : undefined, }) } let deleteDatabaseCopy = 'the primary database' if (selectedAccount?.database_type === 'READ_REPLICA') { deleteDatabaseCopy = selectedAccount.database_identifier ? `the read replica (ID: ${formatDatabaseID(selectedAccount.database_identifier)})` : 'the read replica (ID: Unknown identifier)' } const deleteConnectionTitle = selectedAccount ? getConnectionTitle({ account_name: selectedAccount.account_name, aws_account_id: selectedAccount.aws_account_id, }) : '' const showDeleteConnectionId = !!selectedAccount && deleteConnectionTitle === selectedAccount.aws_account_id return ( <>
AWS PrivateLink Private connectivity from a connected AWS VPC, without the public internet.
{promptPlanUpgrade && ( )}

Connections

{(accounts?.length ?? 0) > 0 ? ( {accounts?.map((account) => ( onEditAccount(account)} /> ))} ) : (

No connections yet

)}
setShowDeleteModal(true)} /> { if (!open && !isDeleting) setShowDeleteModal(false) }} > Delete connection This removes the PrivateLink connection for{' '} {showDeleteConnectionId ? ( {deleteConnectionTitle} ) : ( deleteConnectionTitle )}{' '} on {deleteDatabaseCopy} . Applications using this private path will lose access. Cancel Delete ) }