import { useState } from 'react' import { toast } from 'sonner' import { Button, Card, CardContent, cn } from 'ui' import { ConfirmationModal } from 'ui-patterns/Dialogs/ConfirmationModal' import { IntegrationImageHandler } from '../IntegrationsSettings' import { AWSPrivateLinkAccountItem } from './AWSPrivateLinkAccountItem' import { AWSPrivateLinkForm } from './AWSPrivateLinkForm' import { ScaffoldContainer, ScaffoldSection, ScaffoldSectionContent, ScaffoldSectionDetail, } from '@/components/layouts/Scaffold' 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 { 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 { mutate: deleteAccount, isPending: isDeleting } = useAWSAccountDeleteMutation({ onSuccess: () => { toast.success('Account will be deleted shortly') setShowDeleteModal(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 onDeleteAccount = (account: AWSAccount) => { setSelectedAccount(account) setShowDeleteModal(true) } const onConfirmDelete = () => { if (selectedAccount && project) { deleteAccount({ projectRef: project.ref, awsAccountId: selectedAccount.aws_account_id }) } } return ( <>

Connect to your Briven project from your AWS VPC using AWS PrivateLink.

How does the AWS PrivateLink integration work?

Connecting to AWS PrivateLink allows you to create a private connection between your AWS VPC and your Briven project.

{promptPlanUpgrade && ( )}

AWS Accounts

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

No accounts connected

)}
setShowDeleteModal(false)} onConfirm={onConfirmDelete} >

Are you sure you want to delete the AWS account connection for{' '} {selectedAccount?.aws_account_id}?

) }