mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
Part 5 of a 6-PR stack migrating all `next/link` imports in `apps/studio` onto TanStack Router's `Link` (or plain `<a>` for known external URLs) and removing `compat/next/link.tsx`. | Part | PR | Scope | | --- | --- | --- | | 1 | #54304 | `data/prefetchers/PrefetchableLink.tsx` and `components/ui/**` | | 2 | #54305 | `components/layouts/**` and top-level shell components | | 3 | #54306 | Database, TableGridEditor, Storage, SQLEditor, BranchManagement, Branching, Functions, Realtime | | 4 | #54307 | Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute | | **5** | **#54308 ← this PR** | **Remaining `components/interfaces/**` (Org, Billing, Auth, Support, Home, SignIn, ConnectSheet, etc.)** | | 6 | #54309 | Remove `compat/next/link.tsx` shim, Vite alias, and update basePath tests/docs | Migrates the remaining `components/interfaces/**` directories off `next/link`, leaving zero `next/link` component imports in `apps/studio`. **Changed:** - Replaced `next/link` across all 73 remaining interface files (`Organization`, `OrganizationInvite`, `Billing`, `Auth`, `Support`, `ProjectHome`, `Home`, `Project`, `ProjectCreation`, `ProjectAPIDocs`, `ApiAuthorization`, `App`, `ConnectSheet`, `SignIn`, `APIKeys`, `Account`, `CliLogin`, `Docs`, `JwtSecrets`, `Platform`) - Converted the sole remaining `UrlObject` link (`<Link href={{ pathname: '/sign-in-sso', query }}>`) in `SignInSSOForm.tsx` to `<Link to="/sign-in-sso" search={query}>` - Migrated `SupportLink.tsx` onto `DynamicLink` (`createSupportFormUrl(...)`) - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `OverviewMetrics.tsx` observability link to typed `<Link to="/project/$ref/observability/auth">`, and adopted `InlineLink` / `InlineLinkClassName` on inline paragraph links per review feedback Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Check Organization (billing, usage, team, documents, AWS Marketplace), Auth (providers, templates, rate limits, users, OAuth apps), Support form/links, Project Home, Connect sheet, and Sign-In/SSO links - [ ] Verify `SignInWithSSOButton` preserves query params when navigating to `/sign-in-sso` - [ ] Verify `SupportLink` pre-populates support form query parameters cleanly --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
207 lines
6.0 KiB
TypeScript
207 lines
6.0 KiB
TypeScript
import { Link, useNavigate } from '@tanstack/react-router'
|
|
import { useIsLoggedIn, useParams } from 'common'
|
|
import { type ReactNode } from 'react'
|
|
import { Button, Card, CardContent } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import {
|
|
getOrganizationInviteContent,
|
|
getOrganizationInviteStatus,
|
|
} from './OrganizationInvite.utils'
|
|
import { OrganizationInviteError } from './OrganizationInviteError'
|
|
import {
|
|
InterstitialAccountRow,
|
|
InterstitialActionError,
|
|
InterstitialLayout,
|
|
SupabaseLogo,
|
|
} from '@/components/layouts/InterstitialLayout'
|
|
import { useOrganizationAcceptInvitationMutation } from '@/data/organization-members/organization-invitation-accept-mutation'
|
|
import { useOrganizationInvitationTokenQuery } from '@/data/organization-members/organization-invitation-token-query'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { useProfile, useProfileNameAndPicture } from '@/lib/profile'
|
|
|
|
export const OrganizationInvite = () => {
|
|
const navigate = useNavigate()
|
|
const isLoggedIn = useIsLoggedIn()
|
|
const { slug, token } = useParams()
|
|
const { profile, isLoading: isLoadingProfile } = useProfile()
|
|
const { username, avatarUrl, primaryEmail } = useProfileNameAndPicture()
|
|
|
|
const isSignUpEnabled = useIsFeatureEnabled('dashboard_auth:sign_up')
|
|
|
|
const {
|
|
data,
|
|
error,
|
|
isSuccess: isSuccessInvitation,
|
|
isError: isErrorInvitation,
|
|
isPending: isLoadingInvitation,
|
|
} = useOrganizationInvitationTokenQuery(
|
|
{ slug, token },
|
|
{
|
|
retry: false,
|
|
refetchOnWindowFocus: false,
|
|
enabled: !!profile && !!slug && !!token,
|
|
}
|
|
)
|
|
const inviteStatus = getOrganizationInviteStatus({
|
|
data,
|
|
error,
|
|
isErrorInvitation,
|
|
isLoadingInvitation,
|
|
isLoadingProfile,
|
|
isLoggedIn,
|
|
isSuccessInvitation,
|
|
profileExists: !!profile,
|
|
})
|
|
const isSignedOut = inviteStatus === 'signed-out'
|
|
const isInvitationLoading = inviteStatus === 'loading'
|
|
const inviteContent = getOrganizationInviteContent({
|
|
data,
|
|
error,
|
|
isSignUpEnabled,
|
|
status: inviteStatus,
|
|
})
|
|
const hasError = ['wrong-account', 'expired', 'invalid', 'error'].includes(inviteStatus)
|
|
const returnTo = `/join?token=${token}&slug=${slug}`
|
|
|
|
const mfaRequiredError = error?.message.includes('MFA required')
|
|
|
|
const {
|
|
mutate: joinOrganization,
|
|
isPending: isJoining,
|
|
error: joinError,
|
|
} = useOrganizationAcceptInvitationMutation({
|
|
onSuccess: () => {
|
|
navigate({ to: '/organizations' })
|
|
},
|
|
})
|
|
|
|
async function handleJoinOrganization() {
|
|
if (!slug) return console.error('Slug is required')
|
|
if (!token) return console.error('Token is required')
|
|
joinOrganization({ slug, token })
|
|
}
|
|
|
|
const withLayout = (children: ReactNode) => (
|
|
<InterstitialLayout
|
|
logo={<SupabaseLogo />}
|
|
titleClassName="text-xl"
|
|
title={
|
|
isInvitationLoading ? (
|
|
<ShimmeringLoader className="mx-auto h-7 w-36 max-w-full py-0" />
|
|
) : (
|
|
inviteContent.title
|
|
)
|
|
}
|
|
description={
|
|
isInvitationLoading ? (
|
|
<ShimmeringLoader className="mx-auto h-4 w-48 max-w-full py-0" />
|
|
) : (
|
|
inviteContent.description
|
|
)
|
|
}
|
|
>
|
|
<div className="px-6 pb-6">{children}</div>
|
|
</InterstitialLayout>
|
|
)
|
|
|
|
if (isSignedOut) {
|
|
return withLayout(
|
|
<div className="flex flex-col gap-2">
|
|
<Button asChild variant="primary" block>
|
|
<Link to="/sign-in" search={{ returnTo }}>
|
|
Sign in
|
|
</Link>
|
|
</Button>
|
|
{isSignUpEnabled && (
|
|
<Button asChild block>
|
|
<Link to="/sign-up" search={{ returnTo }}>
|
|
Sign up
|
|
</Link>
|
|
</Button>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (isInvitationLoading) {
|
|
return withLayout(
|
|
<div className="flex flex-col gap-6">
|
|
<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>
|
|
<div className="flex flex-col gap-2">
|
|
<ShimmeringLoader className="h-10 w-full py-0" />
|
|
<ShimmeringLoader className="h-10 w-full py-0" />
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (inviteStatus === 'no-longer-valid') {
|
|
return withLayout(
|
|
<div className="flex flex-col gap-3">
|
|
<Admonition
|
|
type="warning"
|
|
description="This invite has already been accepted or declined."
|
|
/>
|
|
<Button block asChild>
|
|
<Link to="/">Back to dashboard</Link>
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (mfaRequiredError) {
|
|
return withLayout(
|
|
<div className="flex flex-col gap-3">
|
|
<Button block asChild>
|
|
<Link to="/account/security">Go to account settings</Link>
|
|
</Button>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
if (hasError) {
|
|
return withLayout(
|
|
<OrganizationInviteError
|
|
data={data}
|
|
error={error}
|
|
isError={isErrorInvitation}
|
|
isInvalidInvite={inviteStatus === 'invalid'}
|
|
/>
|
|
)
|
|
}
|
|
|
|
return withLayout(
|
|
<div className="flex flex-col gap-6">
|
|
<InterstitialAccountRow avatarUrl={avatarUrl} displayName={primaryEmail ?? username ?? ''} />
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<Button
|
|
variant="primary"
|
|
block
|
|
loading={isJoining}
|
|
disabled={isJoining}
|
|
onClick={handleJoinOrganization}
|
|
>
|
|
Accept invite
|
|
</Button>
|
|
<Button asChild variant="text" block>
|
|
<Link to="/organizations">Decline</Link>
|
|
</Button>
|
|
<InterstitialActionError
|
|
error={joinError && `Failed to join organization: ${joinError.message}`}
|
|
/>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|