import { useState } from 'react' import { toast } from 'sonner' import { DocsButton } from '@/components/ui/DocsButton' import { UpgradePlanButton } from '@/components/ui/UpgradePlanButton' import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization' import { DOCS_URL } from '@/lib/constants' import { useParams } from 'common' import { useCreateTenantSourceMutation } from 'data/replication/create-tenant-source-mutation' import { Button, cn, Dialog, DialogContent, DialogFooter, DialogHeader, DialogSection, DialogSectionSeparator, DialogTitle, DialogTrigger, } from 'ui' import { Admonition } from 'ui-patterns' const EnableReplicationModal = () => { const { ref: projectRef } = useParams() const [open, setOpen] = useState(false) const { mutate: createTenantSource, isPending: creatingTenantSource } = useCreateTenantSourceMutation({ onSuccess: () => { toast.success('Replication has been successfully enabled!') setOpen(false) }, onError: (error) => { toast.error(`Failed to enable replication: ${error.message}`) }, }) const onEnableReplication = async () => { if (!projectRef) return console.error('Project ref is required') createTenantSource({ projectRef }) } return ( ) } export const EnableReplicationCallout = ({ type, className, }: { type?: string className?: string }) => { const { data: organization, isSuccess } = useSelectedOrganizationQuery() const isPaidPlan = isSuccess && organization?.plan.id !== 'free' return (
{isPaidPlan ? 'Enable replication' : 'Upgrade to the Pro plan'} to start replicating your database changes to {type ?? 'data warehouses and analytics platforms'}