import { AlertCircle } from 'lucide-react' import Link from 'next/link' import { useParams } from 'common' import { FormHeader } from 'components/ui/Forms/FormHeader' import Panel from 'components/ui/Panel' import UpgradeToPro from 'components/ui/UpgradeToPro' import { useProjectSettingsV2Query } from 'data/config/project-settings-v2-query' import { useCustomDomainsQuery } from 'data/custom-domains/custom-domains-query' import { useOrgSubscriptionQuery } from 'data/subscriptions/org-subscription-query' import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization' import { useFlag } from 'hooks/ui/useFlag' import CustomDomainActivate from './CustomDomainActivate' import CustomDomainDelete from './CustomDomainDelete' import CustomDomainVerify from './CustomDomainVerify' import CustomDomainsConfigureHostname from './CustomDomainsConfigureHostname' import CustomDomainsShimmerLoader from './CustomDomainsShimmerLoader' const CustomDomainConfig = () => { const { ref } = useParams() const organization = useSelectedOrganization() const customDomainsDisabledDueToQuota = useFlag('customDomainsDisabledDueToQuota') const { data: subscription } = useOrgSubscriptionQuery({ orgSlug: organization?.slug }) const plan = subscription?.plan?.id const { isLoading: isSettingsLoading } = useProjectSettingsV2Query({ projectRef: ref }) const { isLoading: isCustomDomainsLoading, isError, isSuccess, data, } = useCustomDomainsQuery( { projectRef: ref }, { refetchInterval(data) { // while setting up the ssl certificate, we want to poll every 5 seconds if (data?.customDomain?.ssl.status) { return 5000 } return false }, } ) const isLoading = isSettingsLoading || isCustomDomainsLoading return (
{isLoading ? ( ) : isError ? (

Failed to retrieve custom domain configuration. Please try again later or{' '} contact support .

) : data?.status === '0_no_hostname_configured' ? ( ) : data?.status === '0_not_allowed' ? ( } primaryText={ customDomainsDisabledDueToQuota ? 'New custom domains are temporarily disabled' : 'Custom domains are a Pro Plan add-on' } secondaryText={ customDomainsDisabledDueToQuota ? 'We are working with our upstream DNS provider before we are able to sign up new custom domains. Please check back in a few hours.' : plan === 'free' ? 'To configure a custom domain for your project, please upgrade to the Pro Plan with the custom domains add-on selected' : 'To configure a custom domain for your project, please enable the add-on' } addon="customDomain" source="customDomain" disabled={customDomainsDisabledDueToQuota} /> ) : ( {isSuccess && (
{(data.status === '1_not_started' || data.status === '2_initiated' || data.status === '3_challenge_verified') && ( )} {data.status === '4_origin_setup_completed' && ( )} {data.status === '5_services_reconfigured' && ( )}
)}
)}
) } export default CustomDomainConfig