Files
supabase/apps/studio/components/interfaces/Settings/General/CustomDomainConfig/CustomDomainConfig.tsx
T
Joshen Lim 90d3b56db0 Joshen/fe 2621 show custom domain on dashboard and connect modal (#43233)
## Context

Main fix is to adjust the new home page + connect dialog (and connect
sheet) to render the project's custom domain if available

<img width="471" height="255" alt="image"
src="https://github.com/user-attachments/assets/3a208b2e-bdeb-43f5-a2e7-3495881dbaaa"
/>
<img width="1065" height="233" alt="image"
src="https://github.com/user-attachments/assets/2a7b8f81-8c0b-4803-bf0a-fc16a2f1e0e1"
/>

## Changes involved

- Created a `useProjectApiUrl` hook that will return the API URL
depending if custom domains is available, otherwise default to default
project API URL
- Refactored all the other places that were manually deriving the
project's endpoint
  - Storage Explorer -> copy URL
  - Edge Functions
  - Integrations -> Data API + API Docs
  - Auth Providers -> Callback URL
- Also updated the copy CTA for the addons page
  - Instead of just "Change xxx", make it a bit more actionable
  - For add ons with binary states (Custom domains, IPv4)
    - If not enabled yet, "Enable xxx", otherwise "Toggle xxx"
  - For PITR
- If not enabled yet, "Enable PITR", otherwise "Change recovery
duration"
  - Also added "Edit custom domain" CTA if enabled
<img width="1144" height="518" alt="image"
src="https://github.com/user-attachments/assets/4f152ea5-0cc7-412c-95e8-ad5bb37c19c3"
/>


## To test
- [ ] Verify that for a project with custom domain set up, all the
affected UI mentioned in the above section look correct
2026-03-03 11:37:08 +08:00

174 lines
6.2 KiB
TypeScript

import { SupportCategories } from '@supabase/shared-types/out/constants'
import { useFlag, useParams } from 'common'
import { SupportLink } from 'components/interfaces/Support/SupportLink'
import { InlineLinkClassName } from 'components/ui/InlineLink'
import { UpgradeToPro } from 'components/ui/UpgradeToPro'
import {
useCustomDomainsQuery,
type CustomDomainsData,
} from 'data/custom-domains/custom-domains-query'
import { useProjectAddonsQuery } from 'data/subscriptions/project-addons-query'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { AlertCircle } from 'lucide-react'
import { Card, CardContent } from 'ui'
import {
PageSection,
PageSectionContent,
PageSectionDescription,
PageSectionMeta,
PageSectionSummary,
PageSectionTitle,
} from 'ui-patterns/PageSection'
import { CustomDomainActivate } from './CustomDomainActivate'
import { CustomDomainDelete } from './CustomDomainDelete'
import { CustomDomainsConfigureHostname } from './CustomDomainsConfigureHostname'
import { CustomDomainsShimmerLoader } from './CustomDomainsShimmerLoader'
import { CustomDomainVerify } from './CustomDomainVerify'
export const CustomDomainConfig = () => {
const { ref } = useParams()
const { data: organization } = useSelectedOrganizationQuery()
const customDomainsDisabledDueToQuota = useFlag('customDomainsDisabledDueToQuota')
const plan = organization?.plan?.id
const { data: addons, isPending: isLoadingAddons } = useProjectAddonsQuery({ projectRef: ref })
const hasCustomDomainAddon = !!addons?.selected_addons.find((x) => x.type === 'custom_domain')
const {
data: customDomainData,
isPending: isCustomDomainsLoading,
isError,
isSuccess,
status: customDomainStatus,
} = useCustomDomainsQuery(
{ projectRef: ref },
{
refetchInterval: (query) => {
const data = query.state.data
// while setting up the ssl certificate, we want to poll every 5 seconds
if (data?.customDomain?.ssl.status) {
return 10000 // 10 seconds
}
return false
},
}
)
const { status } = customDomainData || {}
return (
<PageSection id="custom-domains">
<PageSectionMeta>
<PageSectionSummary>
<PageSectionTitle>Custom domains</PageSectionTitle>
<PageSectionDescription>
Present a branded experience to your users
</PageSectionDescription>
</PageSectionSummary>
</PageSectionMeta>
<PageSectionContent>
{isLoadingAddons ? (
<Card>
<CardContent className="space-y-6">
<CustomDomainsShimmerLoader />
</CardContent>
</Card>
) : !hasCustomDomainAddon ? (
<UpgradeToPro
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'
? 'Paid Plans come with free vanity subdomains or Custom Domains for an additional $10/month per domain.'
: 'To configure a custom domain for your project, please enable the add-on. Each Custom Domain costs $10 per month.'
}
addon="customDomain"
source="customDomain"
featureProposition="enable custom domains"
disabled={customDomainsDisabledDueToQuota}
/>
) : isCustomDomainsLoading ? (
<Card>
<CardContent className="space-y-6">
<CustomDomainsShimmerLoader />
</CardContent>
</Card>
) : isError ? (
<Card>
<CardContent className="space-y-6">
<div className="flex items-center justify-center space-x-2 py-8">
<AlertCircle size={16} strokeWidth={1.5} />
<p className="text-sm text-foreground-light">
Failed to retrieve custom domain configuration. Please try again later or{' '}
<SupportLink
queryParams={{ projectRef: ref, category: SupportCategories.SALES_ENQUIRY }}
className={InlineLinkClassName}
>
contact support
</SupportLink>
.
</p>
</div>
</CardContent>
</Card>
) : status === '0_no_hostname_configured' ? (
<CustomDomainsConfigureHostname />
) : (
<Card>
<CardContent className="p-0">
{isSuccess ? (
<div className="flex flex-col">
{(status === '1_not_started' ||
status === '2_initiated' ||
status === '3_challenge_verified') && <CustomDomainVerify />}
{customDomainData.status === '4_origin_setup_completed' && (
<CustomDomainActivate
projectRef={ref}
customDomain={customDomainData.customDomain}
/>
)}
{customDomainData.status === '5_services_reconfigured' && (
<CustomDomainDelete
projectRef={ref}
customDomain={customDomainData.customDomain}
/>
)}
</div>
) : (
<CustomDomainConfigFallthrough
fetchStatus={customDomainStatus}
data={customDomainData}
/>
)}
</CardContent>
</Card>
)}
</PageSectionContent>
</PageSection>
)
}
interface CustomDomainConfigFallthroughProps {
fetchStatus: 'error' | 'success' | 'pending'
data: CustomDomainsData | undefined
}
function CustomDomainConfigFallthrough({ fetchStatus, data }: CustomDomainConfigFallthroughProps) {
console.error(`Failing to display UI for custom domains:
Fetch status: ${fetchStatus}
Custom domain status: ${data?.status}`)
return null
}