import { AlertCircle, HelpCircle, RefreshCw } from 'lucide-react'
import Link from 'next/link'
import { useState } from 'react'
import { useParams } from 'common'
import { DocsButton } from 'components/ui/DocsButton'
import Panel from 'components/ui/Panel'
import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { useCustomDomainDeleteMutation } from 'data/custom-domains/custom-domains-delete-mutation'
import type { CustomDomainResponse } from 'data/custom-domains/custom-domains-query'
import { useCustomDomainReverifyMutation } from 'data/custom-domains/custom-domains-reverify-mutation'
import { useInterval } from 'hooks/misc/useInterval'
import {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
WarningIcon,
} from 'ui'
import DNSRecord from './DNSRecord'
import { DNSTableHeaders } from './DNSTableHeaders'
export type CustomDomainVerifyProps = {
customDomain: CustomDomainResponse
}
const CustomDomainVerify = ({ customDomain }: CustomDomainVerifyProps) => {
const { ref: projectRef } = useParams()
const [isNotVerifiedYet, setIsNotVerifiedYet] = useState(false)
const { data: settings } = useProjectSettingsV2Query({ projectRef })
const { mutate: reverifyCustomDomain, isLoading: isReverifyLoading } =
useCustomDomainReverifyMutation({
onSuccess: (res) => {
if (res.status === '2_initiated') setIsNotVerifiedYet(true)
},
})
const { mutate: deleteCustomDomain, isLoading: isDeleting } = useCustomDomainDeleteMutation()
const hasCAAErrors = customDomain.ssl.validation_errors?.reduce(
(acc, error) => acc || error.message.includes('caa_error'),
false
)
const isValidating = (customDomain.ssl.txt_name ?? '') === ''
const onReverifyCustomDomain = () => {
if (!projectRef) return console.error('Project ref is required')
reverifyCustomDomain({ projectRef })
}
useInterval(
onReverifyCustomDomain,
// Poll every 5 seconds if the SSL certificate is being deployed
customDomain.ssl.status !== undefined && customDomain.ssl.txt_name === undefined ? 5000 : false
)
const onCancelCustomDomain = async () => {
if (!projectRef) return console.error('Project ref is required')
deleteCustomDomain({ projectRef })
}
return (
<>
Set the following TXT record(s) in your DNS provider, then click verify to confirm your
control over the domain.
Records which have been successfully verified will be removed from this list below.
Please check again soon. Note that it may take up to 24 hours for changes in
DNS records to propagate.
You may also visit{' '}
here
{' '}
to check if your DNS has been propagated successfully before clicking verify.
Some registrars will require you to remove the domain name when creating DNS
records. As an example, to create a record for `foo.app.example.com`, you
would need to create an entry for `foo.app`.
SSL certificate is being deployed. Please wait a few minutes and try again.
Configure TXT verification for your custom domain{' '}
{customDomain.hostname}
{customDomain.hostname}. For example:{' '}
0 issue "digicert.com"