import { AlertCircle } from 'lucide-react' import { useState } from 'react' import { toast } from 'sonner' import { DocsButton } from 'components/ui/DocsButton' import Panel from 'components/ui/Panel' import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query' import { useCheckCNAMERecordMutation } from 'data/custom-domains/check-cname-mutation' import { useCustomDomainActivateMutation } from 'data/custom-domains/custom-domains-activate-mutation' import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation' import type { CustomDomainResponse } from 'data/custom-domains/custom-domains-query' import { DOCS_URL } from 'lib/constants' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button } from 'ui' import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal' export type CustomDomainActivateProps = { projectRef?: string customDomain: CustomDomainResponse } const CustomDomainActivate = ({ projectRef, customDomain }: CustomDomainActivateProps) => { const [isActivateConfirmModalVisible, setIsActivateConfirmModalVisible] = useState(false) const { data: settings } = useProjectSettingsV2Query({ projectRef }) const { mutate: checkCNAMERecord, isPending: isCheckingRecord } = useCheckCNAMERecordMutation() const { mutate: activateCustomDomain, isPending: isActivating } = useCustomDomainActivateMutation( { onSuccess: () => { toast.success(`Successfully activated custom domain`) setIsActivateConfirmModalVisible(false) }, } ) const { mutate: deleteCustomDomain, isPending: isDeleting } = useCustomDomainDeleteMutation({ onSuccess: () => { toast.success( 'Custom domain setup cancelled successfully. It may take a few seconds before your custom domain is fully removed, so you may need to refresh your browser.' ) }, }) const endpoint = settings?.app_config?.endpoint const onActivateCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') checkCNAMERecord( { domain: customDomain.hostname }, { onSuccess: () => activateCustomDomain({ projectRef }) } ) } const onCancelCustomDomain = async () => { if (!projectRef) return console.error('Project ref is required') deleteCustomDomain({ projectRef }) } return ( <>
{customDomain.hostname} for this project.
Your custom domain CNAME record for{' '}
{customDomain.hostname} should resolve
to{' '}
{endpoint ? (
{endpoint}
) : (
"your project's API URL"
)}
. If you're using Cloudflare as your DNS provider, disable the proxy option.
{customDomain.hostname} for the project?
>
}
confirmLabel="Activate"
confirmLabelLoading="Activating"
onCancel={() => setIsActivateConfirmModalVisible(false)}
onConfirm={onActivateCustomDomain}
>
This will activate the custom domain {customDomain.hostname}. Your project's
Supabase domain will also remain active.