Files
supabase/apps/studio/routes/_app/new/index.tsx
Alaister YoungandAlaister Young d2eb58a0e7 [FE-3106] (part 3) – refactor(studio): move account and top-level page bodies (#53212)
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>
2026-11-17 14:46:37 +09:00

127 lines
3.6 KiB
TypeScript

import HCaptcha from '@hcaptcha/react-hcaptcha'
import { createFileRoute } from '@tanstack/react-router'
import { useCallback, useEffect, useState } from 'react'
import { NewOrgForm } from '@/components/interfaces/Organization/NewOrg/NewOrgForm'
import WizardLayout from '@/components/layouts/WizardLayout'
import { SetupIntentResponse, useSetupIntent } from '@/data/stripe/setup-intent-mutation'
import { useCustomContent } from '@/hooks/custom-content/useCustomContent'
import { buildStudioPageTitle } from '@/lib/page-title'
export const Route = createFileRoute('/_app/new/')({
component: NewOrgRoute,
staticData: {
hideMobileMenu: true,
defaultLayoutHeaderTitle: 'New organization',
},
})
// Inline WizardLayout here rather than via a `_app/new.tsx` sub-shell:
// `new/$slug.tsx` is not under _app (no AppLayout), and the only other
// potential leaf has a different inner wrapper, so a shared shell would not
// actually share anything.
function NewOrgRoute() {
return (
<WizardLayout>
<Wizard />
</WizardLayout>
)
}
/**
* No org selected yet, create a new one
*/
function Wizard() {
const [intent, setIntent] = useState<SetupIntentResponse>()
const { appTitle } = useCustomContent(['app:title'])
const pageTitle = buildStudioPageTitle({
section: 'New Organization',
brand: appTitle || 'Supabase',
})
const [captchaToken, setCaptchaToken] = useState<string | null>(null)
const [captchaRef, setCaptchaRef] = useState<HCaptcha | null>(null)
const [selectedPlan, setSelectedPlan] = useState<string | null>(null)
const { mutate: setupIntent } = useSetupIntent({ onSuccess: (res) => setIntent(res) })
const captchaRefCallback = useCallback((node: HCaptcha) => {
setCaptchaRef(node)
}, [])
const initSetupIntent = async (hcaptchaToken: string | undefined) => {
if (!hcaptchaToken) return console.error('Hcaptcha token is required')
// Force a reload of Elements, necessary for Stripe
// Also mitigates card testing to some extent as we generate a new captcha token
setIntent(undefined)
setupIntent({ hcaptchaToken })
}
const loadPaymentForm = async (force = false) => {
if (selectedPlan == null || selectedPlan === 'FREE') return
if (intent != null && !force) return
if (captchaRef) {
let token = captchaToken
try {
if (!token) {
const captchaResponse = await captchaRef.execute({ async: true })
token = captchaResponse?.response ?? null
}
} catch (error) {
return
}
await initSetupIntent(token ?? undefined)
resetCaptcha()
}
}
useEffect(() => {
loadPaymentForm()
}, [captchaRef, selectedPlan])
const resetSetupIntent = () => {
setIntent(undefined)
return loadPaymentForm(true)
}
const onLocalCancel = () => {
setIntent(undefined)
}
const resetCaptcha = () => {
setCaptchaToken(null)
captchaRef?.resetCaptcha()
}
return (
<>
{/* Wizard layouts set the visual header but not the browser tab title. */}
<title>{pageTitle}</title>
<meta name="description" content="Supabase Studio" />
<HCaptcha
ref={captchaRefCallback}
sitekey={process.env.NEXT_PUBLIC_HCAPTCHA_SITE_KEY!}
size="invisible"
onVerify={(token) => {
setCaptchaToken(token)
}}
onClose={onLocalCancel}
onExpire={() => {
setCaptchaToken(null)
}}
/>
<NewOrgForm
setupIntent={intent}
onPaymentMethodReset={() => resetSetupIntent()}
onPlanSelected={(plan) => setSelectedPlan(plan)}
/>
</>
)
}