mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
Moves the account and top-level app page bodies (`/account/*`, `/organizations`, `/new`, `/new/$slug`, `/join`, `/claim-project`, `/aws-marketplace-onboarding`, `/stripe-atlas-application`, `/support/new`, `/support/link`, `/integrations/github|vercel/*`) from `pages/**` into their TanStack route files and deletes the pages. Part of the final pass of the TanStack migration (FE-3106). Part 3 of the stack, and the first page-move PR. **Depends on:** #53202 **Changed:** - `routes/_app/account/**`, `routes/_app/{organizations,new/index,support/*}.tsx`, `routes/{new/$slug,join,claim-project,aws-marketplace-onboarding,stripe-atlas-application}.tsx`, `routes/integrations/**` – page bodies inlined. `next/router`/`next/link`/`next/head` → `useNavigate`, `Link`, `<Navigate>` and inline `<title>`. `getLayout` dropped; every old `getLayout` was checked against the route tree and matches - `routes/aws-marketplace-onboarding.tsx` – reads `buyer_id` through `validateSearch` + `Route.useSearch()` - `tests/lib/route-render.tsx` – new `renderRoute(Route, { routeId, url })` helper that mounts a file route in a memory router (with the app's search serializers) so route components can be tested; used by the moved tests - `tests/lib/route-mock.ts` – the `next/router` mock now derives its dynamic-route patterns from `routes/**` instead of globbing `pages/**`, so tests keep parsing params as pages disappear - `tests/routes/**` – page tests moved from `tests/pages/**` and rendered through the route - `.github/CODEOWNERS` – `pages/new/index.tsx` owner moved to `routes/_app/new/index.tsx` **Removed:** - 19 files under `pages/account/**`, `pages/new/**`, `pages/support/{new,link}.tsx`, `pages/integrations/**` and the top-level pages listed above Addresses [FE-3106](https://linear.app/supabase/issue/FE-3106/move-page-bodies-into-route-files-and-delete-pages). ## To test - Open `/account/me`, `/account/security`, `/account/tokens`, `/account/audit` – same Account layout, header title and sidebar as before - Open an old email-change link (`/account/me#message=...`) – lands on `/account/security` with the hash - `/account/tokens/scoped` – redirects to `/account/tokens` - `/organizations` and `/new/<org>` – render with the same layout; "New organization" links work - Vercel install/marketplace flows – navigation keeps `?…` params --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
403 lines
13 KiB
TypeScript
403 lines
13 KiB
TypeScript
import { createFileRoute, useNavigate } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { useEffect, useMemo, useState } from 'react'
|
|
import {
|
|
Badge,
|
|
Button,
|
|
Card,
|
|
CardContent,
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import {
|
|
VercelIntegrationFooter,
|
|
VercelIntegrationInterstitialErrorState,
|
|
VercelIntegrationLogo,
|
|
} from '@/components/interfaces/Integrations/Vercel/VercelIntegrationInterstitial'
|
|
import { getHasInstalledObject } from '@/components/layouts/IntegrationsLayout/Integrations.utils'
|
|
import {
|
|
InterstitialAccountRow,
|
|
InterstitialActionError,
|
|
InterstitialLayout,
|
|
} from '@/components/layouts/InterstitialLayout'
|
|
import { useIntegrationsQuery } from '@/data/integrations/integrations-query'
|
|
import { useVercelIntegrationCreateMutation } from '@/data/integrations/vercel-integration-create-mutation'
|
|
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
|
|
import { withAuth } from '@/hooks/misc/withAuth'
|
|
import {
|
|
buildVercelInstallRouteQuery,
|
|
getErrorMessage,
|
|
resolveVercelInstallSource,
|
|
} from '@/lib/integrations/vercel-install.utils'
|
|
import { buildStudioPageTitle } from '@/lib/page-title'
|
|
import { useProfileNameAndPicture } from '@/lib/profile'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useIntegrationInstallationSnapshot } from '@/state/integration-installation'
|
|
import type { Organization } from '@/types'
|
|
|
|
export const Route = createFileRoute('/integrations/vercel/install')({
|
|
component: VercelInstallRoute,
|
|
})
|
|
|
|
function VercelInstallRoute() {
|
|
return <VercelIntegrationWithAuth />
|
|
}
|
|
|
|
const PAGE_TITLE = buildStudioPageTitle({
|
|
section: 'Install Vercel Integration',
|
|
brand: 'Supabase',
|
|
})
|
|
|
|
function VercelIntegration() {
|
|
const track = useTrack()
|
|
const navigate = useNavigate()
|
|
const snapshot = useIntegrationInstallationSnapshot()
|
|
const { code, configurationId, currentProjectId, externalId, next, teamId, source } = useParams()
|
|
|
|
const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null)
|
|
const [validationError, setValidationError] = useState<string>()
|
|
|
|
const { username, primaryEmail, avatarUrl } = useProfileNameAndPicture()
|
|
const displayName = primaryEmail ?? username ?? ''
|
|
|
|
/**
|
|
* Fetch the list of organization based integration installations for Vercel.
|
|
*
|
|
* Array of integrations installed on all
|
|
*/
|
|
const {
|
|
data: integrationData,
|
|
isPending: isLoadingIntegrationsQuery,
|
|
isError: isIntegrationsError,
|
|
error: integrationsError,
|
|
} = useIntegrationsQuery()
|
|
|
|
const {
|
|
data: organizationsData,
|
|
isPending: isLoadingOrganizationsQuery,
|
|
isSuccess: isOrganizationsDataSuccess,
|
|
isError: isOrganizationsError,
|
|
error: organizationsError,
|
|
} = useOrganizationsQuery()
|
|
|
|
/**
|
|
* Organizations with extra `installationInstalled` attribute
|
|
*
|
|
* Used to show label/badge and allow/disallow installing
|
|
*
|
|
*/
|
|
const installed = useMemo(
|
|
() =>
|
|
integrationData && organizationsData
|
|
? getHasInstalledObject({
|
|
integrationName: 'Vercel',
|
|
integrationData,
|
|
organizationsData,
|
|
installationId: configurationId,
|
|
})
|
|
: {},
|
|
[configurationId, integrationData, organizationsData]
|
|
)
|
|
|
|
/**
|
|
* Handle the correct route change based on whether the vercel integration
|
|
* is following the 'marketplace/external' flow or 'deploy button' flow.
|
|
* See:
|
|
* - https://vercel.com/docs/integrations/create-integration/submit-integration#query-parameters-for-marketplace
|
|
* - https://vercel.com/docs/integrations/create-integration/submit-integration#query-parameters-for-external-flow
|
|
* - https://vercel.com/docs/integrations/create-integration/submit-integration#query-parameters-for-deploy-button
|
|
*/
|
|
function handleRouteChange(orgSlug: string) {
|
|
const vercelInstallSource = resolveVercelInstallSource({
|
|
source,
|
|
currentProjectId,
|
|
externalId,
|
|
})
|
|
const query = buildVercelInstallRouteQuery({
|
|
source: vercelInstallSource,
|
|
organizationSlug: orgSlug,
|
|
configurationId,
|
|
currentProjectId,
|
|
externalId,
|
|
next,
|
|
})
|
|
|
|
switch (vercelInstallSource) {
|
|
case 'deploy-button': {
|
|
void navigate({
|
|
to: '/integrations/vercel/$slug/deploy-button/new-project',
|
|
params: { slug: orgSlug },
|
|
search: query,
|
|
})
|
|
break
|
|
}
|
|
case 'marketplace':
|
|
case 'external': {
|
|
void navigate({
|
|
to: '/integrations/vercel/$slug/marketplace/choose-project',
|
|
params: { slug: orgSlug },
|
|
search: query,
|
|
})
|
|
break
|
|
}
|
|
default:
|
|
setValidationError(
|
|
`Unsupported Vercel installation source: ${source}. Please contact support if this error persists.`
|
|
)
|
|
}
|
|
}
|
|
|
|
const {
|
|
mutate,
|
|
isPending: isLoadingVercelIntegrationCreateMutation,
|
|
error: createIntegrationError,
|
|
reset: resetCreateIntegrationError,
|
|
} = useVercelIntegrationCreateMutation({
|
|
onMutate() {
|
|
snapshot.setLoading(true)
|
|
},
|
|
onSuccess(_data, variables) {
|
|
handleRouteChange(variables.orgSlug)
|
|
snapshot.setLoading(false)
|
|
},
|
|
onError() {
|
|
snapshot.setLoading(false)
|
|
},
|
|
})
|
|
const actionError =
|
|
validationError ??
|
|
(createIntegrationError
|
|
? `Creating Vercel integration failed: ${createIntegrationError.message}`
|
|
: undefined)
|
|
|
|
function onInstall() {
|
|
setValidationError(undefined)
|
|
resetCreateIntegrationError()
|
|
const orgSlug = selectedOrg?.slug
|
|
|
|
const isIntegrationInstalled = orgSlug ? installed[orgSlug] : false
|
|
|
|
if (!orgSlug) {
|
|
return setValidationError('Please select an organization')
|
|
}
|
|
|
|
if (!code) {
|
|
return setValidationError('Vercel code missing')
|
|
}
|
|
|
|
if (!configurationId) {
|
|
return setValidationError('Vercel configuration ID missing')
|
|
}
|
|
|
|
if (!source) {
|
|
return setValidationError('Vercel configuration source missing')
|
|
}
|
|
|
|
/**
|
|
* Only install if integration hasn't already been installed
|
|
*/
|
|
if (!isIntegrationInstalled) {
|
|
track(
|
|
'integration_install_submitted',
|
|
{ integrationName: 'Vercel', method: source },
|
|
{ organization: orgSlug }
|
|
)
|
|
mutate({
|
|
code,
|
|
configurationId,
|
|
orgSlug,
|
|
metadata: {},
|
|
source,
|
|
teamId: teamId,
|
|
})
|
|
} else {
|
|
handleRouteChange(orgSlug)
|
|
}
|
|
}
|
|
|
|
const dataLoading =
|
|
isLoadingVercelIntegrationCreateMutation ||
|
|
isLoadingOrganizationsQuery ||
|
|
isLoadingIntegrationsQuery
|
|
|
|
const noOrganizations = useMemo(() => {
|
|
return isOrganizationsDataSuccess && organizationsData?.length === 0 ? true : false
|
|
}, [isOrganizationsDataSuccess, organizationsData])
|
|
|
|
const missingParams = [
|
|
!code ? 'code' : undefined,
|
|
!configurationId ? 'configurationId' : undefined,
|
|
!source ? 'source' : undefined,
|
|
].filter(Boolean) as string[]
|
|
|
|
const isError = isOrganizationsError || isIntegrationsError
|
|
const errorMessage = getErrorMessage(organizationsError) ?? getErrorMessage(integrationsError)
|
|
const showLoadingState = isLoadingOrganizationsQuery || isLoadingIntegrationsQuery
|
|
|
|
const disableInstallationForm =
|
|
dataLoading || noOrganizations || !selectedOrg || missingParams.length > 0 || isError
|
|
|
|
useEffect(() => {
|
|
if (organizationsData !== undefined && integrationData !== undefined) {
|
|
const firstOrg = organizationsData[0]
|
|
|
|
if (firstOrg && selectedOrg === null) {
|
|
setSelectedOrg(firstOrg)
|
|
}
|
|
}
|
|
}, [organizationsData, integrationData, selectedOrg])
|
|
|
|
return (
|
|
<>
|
|
<title>{PAGE_TITLE}</title>
|
|
|
|
<InterstitialLayout
|
|
logo={<VercelIntegrationLogo />}
|
|
title="Install Vercel integration"
|
|
description="Choose the Supabase organization Vercel can connect to"
|
|
footer={<VercelIntegrationFooter />}
|
|
>
|
|
<div className="px-6 pb-6">
|
|
{showLoadingState ? (
|
|
<InstallationLoadingState />
|
|
) : isError ? (
|
|
<VercelIntegrationInterstitialErrorState
|
|
title="Unable to load installation"
|
|
errorMessage={errorMessage}
|
|
/>
|
|
) : (
|
|
<div className="flex flex-col gap-5">
|
|
<InterstitialAccountRow avatarUrl={avatarUrl} displayName={displayName} />
|
|
|
|
<OrganizationSelect
|
|
organizations={organizationsData ?? []}
|
|
selectedOrg={selectedOrg}
|
|
disabled={noOrganizations || dataLoading}
|
|
installed={installed}
|
|
onSelectedOrgChange={(organization) => {
|
|
setSelectedOrg(organization)
|
|
setValidationError(undefined)
|
|
resetCreateIntegrationError()
|
|
}}
|
|
/>
|
|
|
|
{missingParams.length > 0 && (
|
|
<Admonition
|
|
type="warning"
|
|
title="Missing Vercel installation details"
|
|
description={`Retry from Vercel. The installation URL is missing: ${missingParams.join(
|
|
', '
|
|
)}.`}
|
|
/>
|
|
)}
|
|
|
|
{noOrganizations && (
|
|
<Admonition
|
|
type="warning"
|
|
title="No Supabase organizations found"
|
|
description={
|
|
<>
|
|
Create a Supabase organization before installing the Vercel integration. You
|
|
can create a new organization{' '}
|
|
<a href="https://supabase.com/dashboard/new" target="_blank" rel="noreferrer">
|
|
here
|
|
</a>
|
|
.
|
|
</>
|
|
}
|
|
/>
|
|
)}
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<Button
|
|
block
|
|
variant="primary"
|
|
disabled={disableInstallationForm}
|
|
loading={dataLoading}
|
|
onClick={onInstall}
|
|
>
|
|
{selectedOrg && installed[selectedOrg.slug] ? 'Continue' : 'Install integration'}
|
|
</Button>
|
|
<InterstitialActionError error={actionError} />
|
|
</div>
|
|
</div>
|
|
)}
|
|
</div>
|
|
</InterstitialLayout>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const InstallationLoadingState = () => (
|
|
<div className="flex flex-col gap-5">
|
|
<Card className="shadow-none">
|
|
<CardContent className="flex items-center gap-3 border-none px-4 py-3">
|
|
<ShimmeringLoader className="size-8 flex-shrink-0 rounded-full py-0" />
|
|
<div className="min-w-0 flex-1 space-y-2">
|
|
<ShimmeringLoader className="h-3 w-20 py-0" />
|
|
<ShimmeringLoader className="h-4 w-40 max-w-full py-0" />
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
<section className="space-y-2" aria-label="Organization loading">
|
|
<ShimmeringLoader className="h-3 w-24 py-0" />
|
|
<ShimmeringLoader className="h-[34px] w-full rounded-md py-0" />
|
|
</section>
|
|
<ShimmeringLoader className="h-10 w-full rounded-md py-0" />
|
|
</div>
|
|
)
|
|
|
|
interface OrganizationSelectProps {
|
|
organizations: Organization[]
|
|
selectedOrg: Organization | null
|
|
disabled?: boolean
|
|
installed: Record<string, boolean>
|
|
onSelectedOrgChange: (organization: Organization) => void
|
|
}
|
|
|
|
function OrganizationSelect({
|
|
organizations,
|
|
selectedOrg,
|
|
disabled,
|
|
installed,
|
|
onSelectedOrgChange,
|
|
}: OrganizationSelectProps) {
|
|
return (
|
|
<section className="space-y-2" aria-label="Organization">
|
|
<p className="text-xs font-medium uppercase tracking-wider text-foreground-light">
|
|
Organization
|
|
</p>
|
|
<Select
|
|
value={selectedOrg?.slug ?? ''}
|
|
disabled={disabled}
|
|
onValueChange={(slug) => {
|
|
const org = organizations.find((org) => org.slug === slug)
|
|
if (org) onSelectedOrgChange(org)
|
|
}}
|
|
>
|
|
<SelectTrigger size="small" aria-label="Supabase organization to install Vercel into">
|
|
<SelectValue placeholder="Choose an organization" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{organizations.map((org) => (
|
|
<SelectItem key={org.slug} value={org.slug} className="text-xs">
|
|
<div className="flex items-center gap-2">
|
|
<span className="truncate">{org.name}</span>
|
|
{installed[org.slug] && <Badge className="flex-none!">Installed</Badge>}
|
|
</div>
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</section>
|
|
)
|
|
}
|
|
|
|
const VercelIntegrationWithAuth = withAuth(VercelIntegration)
|