import Link from 'next/link'
import { useState } from 'react'
import Panel from 'components/ui/Panel'
import type { ProjectApiResponse } from 'data/config/project-api-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 {
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
Alert_Shadcn_,
Button,
IconAlertCircle,
IconExternalLink,
IconHelpCircle,
IconRefreshCw,
} from 'ui'
import { WarningIcon } from 'ui-patterns/Icons/StatusIcons'
import DNSRecord from './DNSRecord'
export type CustomDomainVerifyProps = {
projectRef?: string
customDomain: CustomDomainResponse
settings?: ProjectApiResponse
}
const CustomDomainVerify = ({ projectRef, customDomain, settings }: CustomDomainVerifyProps) => {
const [isNotVerifiedYet, setIsNotVerifiedYet] = useState(false)
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 onReverifyCustomDomain = () => {
if (!projectRef) return console.error('Project ref is required')
reverifyCustomDomain({ projectRef })
}
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`.
You may also visit{' '}
here
{' '}
to check if your DNS has been propagated successfully before clicking verify.
Type
SSL certificate is being deployed. Please wait a few minutes and try again.
One of the records requires you to{' '}
replace the CNAME record set up in the
first step with a TXT record.
You'll be able to restore it back to the CNAME after the verification process has been
completed.
Configure TXT verification for your custom domain{' '}
{customDomain.hostname}
{customDomain.hostname}. For example:{' '}
0 issue "digicert.com"