import { useParams } from 'common' import { useState } from 'react' import { toast } from 'sonner' import { Button, cn, Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, DialogTrigger, } from 'ui' import { DestinationType } from './DestinationPanel/DestinationPanel.types' import { DocsButton } from '@/components/ui/DocsButton' import { InlineLink } from '@/components/ui/InlineLink' import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton' import { useCreateTenantSourceMutation } from '@/data/replication/create-tenant-source-mutation' import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements' import { DOCS_URL } from '@/lib/constants' type EnablePipelinesModalProps = | { open: boolean; onOpenChange: (open: boolean) => void } | { open?: never; onOpenChange?: never } export const EnablePipelinesModal = ({ open: extOpen, onOpenChange, }: EnablePipelinesModalProps) => { const { ref: projectRef } = useParams() const [_open, _setOpen] = useState(false) const open = extOpen ?? _open const setOpen = onOpenChange ?? _setOpen const hideTrigger = extOpen !== undefined && onOpenChange !== undefined const { hasAccess } = useCheckEntitlements('replication.etl') const { mutate: createTenantSource, isPending: creatingTenantSource } = useCreateTenantSourceMutation({ onSuccess: () => { toast.success('Pipelines has been successfully enabled!') setOpen(false) }, onError: (error) => { toast.error(`Failed to enable Pipelines: ${error.message}`) }, }) const onEnablePipelines = async () => { if (!projectRef) return console.error('Project ref is required') createTenantSource({ projectRef }) } return ( {!hideTrigger && ( )} Enable Pipelines {hasAccess ? 'Enabling creates Pipelines resources for this project.' : 'Upgrade to the Pro plan to replicate database changes to data warehouses and analytics platforms.'} {hasAccess && ( <>

Pipelines is in public alpha and may change as we refine it.

You’ll be billed for configured pipeline hours and for Postgres row data processed during initial sync and ongoing replication. Review{' '} Pipelines pricing {' '} before enabling.

)} {hasAccess ? ( ) : ( )}
) } export const EnablePipelinesCallout = ({ type, className, }: { type?: DestinationType | null className?: string }) => { const { hasAccess } = useCheckEntitlements('replication.etl') return (

Enable Pipelines

Supabase Pipelines replicates database changes to supported destination systems.{' '} {hasAccess ? 'Enable Pipelines for your project' : 'Upgrade to the Pro plan'} to replicate database changes to {type ?? 'data warehouses and analytics platforms'}.

{hasAccess ? ( ) : ( )}
) }