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>
238 lines
7.5 KiB
TypeScript
238 lines
7.5 KiB
TypeScript
import { createFileRoute, Link } from '@tanstack/react-router'
|
|
import { useParams } from 'common'
|
|
import { useCallback, useEffect, useState } from 'react'
|
|
import { Button } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { isVercelUrl } from '@/components/interfaces/Integrations/Vercel/VercelIntegration.utils'
|
|
import {
|
|
VercelIntegrationFooter,
|
|
VercelIntegrationLogo,
|
|
} from '@/components/interfaces/Integrations/Vercel/VercelIntegrationInterstitial'
|
|
import { ProjectCreationForm } from '@/components/interfaces/ProjectCreation/ProjectCreationForm'
|
|
import { InterstitialLayout } from '@/components/layouts/InterstitialLayout'
|
|
import { useProjectSettingsV2Query } from '@/data/config/project-settings-v2-query'
|
|
import { useIntegrationsQuery } from '@/data/integrations/integrations-query'
|
|
import { useIntegrationVercelConnectionsCreateMutation } from '@/data/integrations/integrations-vercel-connections-create-mutation'
|
|
import { useVercelProjectsQuery } from '@/data/integrations/integrations-vercel-projects-query'
|
|
import { withAuth } from '@/hooks/misc/withAuth'
|
|
import { buildStudioPageTitle } from '@/lib/page-title'
|
|
import { useIntegrationInstallationSnapshot } from '@/state/integration-installation'
|
|
|
|
export const Route = createFileRoute('/integrations/vercel/$slug/deploy-button/new-project')({
|
|
component: VercelDeployButtonNewProjectRoute,
|
|
})
|
|
|
|
function VercelDeployButtonNewProjectRoute() {
|
|
return <VercelIntegrationWithAuth />
|
|
}
|
|
|
|
const PAGE_TITLE = buildStudioPageTitle({
|
|
section: 'Create Vercel Project',
|
|
brand: 'Supabase',
|
|
})
|
|
|
|
function VercelIntegration() {
|
|
const { slug, next, currentProjectId: foreignProjectId } = useParams()
|
|
const snapshot = useIntegrationInstallationSnapshot()
|
|
|
|
const [newProjectRef, setNewProjectRef] = useState<string>()
|
|
const [connectionError, setConnectionError] = useState<string>()
|
|
const [isConnecting, setIsConnecting] = useState(false)
|
|
const [isConnectionComplete, setIsConnectionComplete] = useState(false)
|
|
|
|
const { data: integrationData } = useIntegrationsQuery()
|
|
const organizationIntegration = integrationData?.find((x) => x.organization.slug === slug)
|
|
|
|
const { data: vercelProjects } = useVercelProjectsQuery(
|
|
{ organization_integration_id: organizationIntegration?.id },
|
|
{ enabled: organizationIntegration !== undefined }
|
|
)
|
|
|
|
// Wait for the new project to be created before creating the connection
|
|
const {
|
|
data,
|
|
isSuccess,
|
|
isError: isProjectSettingsError,
|
|
error: projectSettingsError,
|
|
refetch: refetchProjectSettings,
|
|
} = useProjectSettingsV2Query(
|
|
{ projectRef: newProjectRef },
|
|
{
|
|
enabled: newProjectRef !== undefined,
|
|
// refetch until the project is created
|
|
refetchInterval: (query) => {
|
|
const data = query.state.data
|
|
return ((data?.service_api_keys ?? []).length ?? 0) > 0 ? false : 1000
|
|
},
|
|
}
|
|
)
|
|
|
|
const { mutateAsync: createConnections } = useIntegrationVercelConnectionsCreateMutation()
|
|
|
|
const connectProject = useCallback(async () => {
|
|
const isReady = (data?.service_api_keys ?? []).length > 0
|
|
|
|
if (!isReady || !organizationIntegration || !foreignProjectId || !newProjectRef) {
|
|
return
|
|
}
|
|
|
|
const projectDetails = vercelProjects?.find((x) => x.id === foreignProjectId)
|
|
setConnectionError(undefined)
|
|
setIsConnecting(true)
|
|
|
|
try {
|
|
await createConnections({
|
|
organizationIntegrationId: organizationIntegration.id,
|
|
connection: {
|
|
foreign_project_id: foreignProjectId,
|
|
supabase_project_ref: newProjectRef,
|
|
integration_id: '0',
|
|
metadata: {
|
|
...projectDetails,
|
|
supabaseConfig: {
|
|
projectEnvVars: {
|
|
write: true,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
orgSlug: slug,
|
|
})
|
|
snapshot.setLoading(false)
|
|
setIsConnectionComplete(true)
|
|
if (next && isVercelUrl(next)) window.location.href = next
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : 'An unknown error occurred'
|
|
setConnectionError(message)
|
|
} finally {
|
|
setIsConnecting(false)
|
|
}
|
|
}, [
|
|
createConnections,
|
|
data?.service_api_keys,
|
|
foreignProjectId,
|
|
newProjectRef,
|
|
next,
|
|
organizationIntegration,
|
|
snapshot,
|
|
slug,
|
|
vercelProjects,
|
|
])
|
|
|
|
useEffect(() => {
|
|
if (isSuccess && !connectionError && !isConnecting && !isConnectionComplete) {
|
|
void connectProject()
|
|
}
|
|
}, [connectProject, connectionError, isConnecting, isConnectionComplete, isSuccess])
|
|
|
|
const renderContent = () => {
|
|
if (newProjectRef === undefined) {
|
|
return <ProjectCreationForm isVercelIntegrationFlow onCreateSuccess={setNewProjectRef} />
|
|
}
|
|
|
|
if (isProjectSettingsError) {
|
|
return (
|
|
<VercelConnectionError
|
|
projectRef={newProjectRef}
|
|
message={projectSettingsError?.message ?? 'Unable to check whether the project is ready.'}
|
|
onRetry={() => void refetchProjectSettings()}
|
|
/>
|
|
)
|
|
}
|
|
|
|
if (connectionError) {
|
|
return (
|
|
<VercelConnectionError
|
|
projectRef={newProjectRef}
|
|
message={connectionError}
|
|
onRetry={() => void connectProject()}
|
|
/>
|
|
)
|
|
}
|
|
|
|
if (isConnectionComplete) {
|
|
return (
|
|
<div className="px-6 pb-6">
|
|
<div className="flex flex-col gap-3">
|
|
<Admonition
|
|
type="success"
|
|
title="Project connected"
|
|
description="Your Supabase project is connected to Vercel."
|
|
/>
|
|
<Button asChild variant="primary" block>
|
|
<Link to="/project/$ref" params={{ ref: newProjectRef }}>
|
|
Open project
|
|
</Link>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<div className="px-6 pb-6">
|
|
<div className="space-y-3" role="status">
|
|
<p className="text-sm text-foreground-light">
|
|
{isConnecting
|
|
? 'Connecting your project to Vercel'
|
|
: 'Waiting for your project to be ready'}
|
|
</p>
|
|
<ShimmeringLoader className="h-2 w-full rounded-full py-0" />
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<title>{PAGE_TITLE}</title>
|
|
|
|
<InterstitialLayout
|
|
logo={<VercelIntegrationLogo />}
|
|
title="Create a new project"
|
|
description="Your project will have its own dedicated instance and full Postgres database. An API will be set up so you can easily interact with your new database."
|
|
footer={<VercelIntegrationFooter />}
|
|
widthClassName="max-w-2xl"
|
|
>
|
|
{renderContent()}
|
|
</InterstitialLayout>
|
|
</>
|
|
)
|
|
}
|
|
|
|
function VercelConnectionError({
|
|
projectRef,
|
|
message,
|
|
onRetry,
|
|
}: {
|
|
projectRef: string
|
|
message: string
|
|
onRetry: () => void
|
|
}) {
|
|
return (
|
|
<div>
|
|
<div className="px-6 pb-6">
|
|
<Admonition
|
|
type="danger"
|
|
title="Unable to connect to Vercel"
|
|
description={`Your Supabase project was still created. Error: ${message}`}
|
|
/>
|
|
</div>
|
|
<div className="flex h-12 items-center justify-end gap-x-2 border-t border-default bg-surface-100 px-card">
|
|
<Button asChild>
|
|
<Link to="/project/$ref" params={{ ref: projectRef }}>
|
|
Open project
|
|
</Link>
|
|
</Button>
|
|
<Button variant="primary" onClick={onRetry}>
|
|
Retry connection
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
const VercelIntegrationWithAuth = withAuth(VercelIntegration)
|