mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +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>
144 lines
4.1 KiB
TypeScript
144 lines
4.1 KiB
TypeScript
import { Link } from '@tanstack/react-router'
|
|
import { useIsMFAEnabled } from 'common'
|
|
import { BoxesIcon, LockIcon, PlusIcon } from 'lucide-react'
|
|
import { Fragment, type ReactNode } from 'react'
|
|
import { cn, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
|
|
|
|
import { ActionCard } from '@/components/ui/ActionCard'
|
|
import { DynamicLink } from '@/components/ui/DynamicLink'
|
|
import PartnerIcon from '@/components/ui/PartnerIcon'
|
|
import { useOrgProjectsInfiniteQuery } from '@/data/projects/org-projects-infinite-query'
|
|
import type { Organization } from '@/types'
|
|
|
|
export const OrganizationCard = ({
|
|
organization,
|
|
href,
|
|
isLink = true,
|
|
className,
|
|
onClick,
|
|
description,
|
|
}: {
|
|
organization: Organization
|
|
href?: string
|
|
isLink?: boolean
|
|
className?: string
|
|
onClick?: () => void
|
|
description?: ReactNode
|
|
}) => {
|
|
const isUserMFAEnabled = useIsMFAEnabled()
|
|
const isPlatformOrg = organization.plan?.id === 'platform'
|
|
const shouldRenderDefaultDescription = description === undefined
|
|
const { data } = useOrgProjectsInfiniteQuery(
|
|
{ slug: organization.slug },
|
|
{ enabled: !isPlatformOrg && shouldRenderDefaultDescription }
|
|
)
|
|
const numProjects = data?.pages[0].pagination.count ?? 0
|
|
const isMfaRequired = organization.organization_requires_mfa
|
|
|
|
const card = (
|
|
<ActionCard
|
|
bgColor="bg border"
|
|
className={cn(
|
|
'flex items-center min-h-[70px] [&>div]:w-full [&>div]:items-center max-h-min',
|
|
className
|
|
)}
|
|
icon={<BoxesIcon size={18} strokeWidth={1} className="text-foreground" />}
|
|
title={organization.name}
|
|
onClick={onClick}
|
|
description={
|
|
shouldRenderDefaultDescription ? (
|
|
<div className="flex items-center justify-between text-xs text-foreground-light font-sans">
|
|
<div className="flex items-center gap-x-1">
|
|
<span>{organization.plan.name} Plan</span>
|
|
{numProjects > 0 && (
|
|
<>
|
|
<span className="text-foreground-lighter">·</span>
|
|
<span>
|
|
{numProjects} project{numProjects > 1 ? <span>s</span> : ''}
|
|
</span>
|
|
</>
|
|
)}
|
|
</div>
|
|
<div className="flex items-center gap-x-2">
|
|
<PartnerIcon organization={organization} />
|
|
{isMfaRequired && (
|
|
<Tooltip>
|
|
<TooltipTrigger className="cursor-default">
|
|
<LockIcon size={12} />
|
|
</TooltipTrigger>
|
|
<TooltipContent side="bottom" className={!isUserMFAEnabled ? 'w-80' : ''}>
|
|
MFA enforced
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)}
|
|
</div>
|
|
</div>
|
|
) : (
|
|
description
|
|
)
|
|
}
|
|
/>
|
|
)
|
|
|
|
if (isLink) {
|
|
return (
|
|
<DynamicLink href={href ?? `/org/${organization.slug}`} tabIndex={0}>
|
|
{card}
|
|
</DynamicLink>
|
|
)
|
|
} else {
|
|
return <Fragment>{card}</Fragment>
|
|
}
|
|
}
|
|
|
|
export const CreateOrganizationCard = ({
|
|
params = {},
|
|
label = 'Create new organization',
|
|
onClick,
|
|
disabled,
|
|
}: {
|
|
params?: { [key: string]: string }
|
|
label?: string
|
|
onClick?: () => void
|
|
disabled?: boolean
|
|
}) => {
|
|
const card = (
|
|
<ActionCard
|
|
bgColor="bg border"
|
|
className={cn(
|
|
'flex items-center min-h-[70px] [&>div]:w-full [&>div]:items-center max-h-min',
|
|
'border-dashed shadow-none transition-colors group-hover:border-default group-hover:bg-surface-200'
|
|
)}
|
|
icon={<PlusIcon size={18} strokeWidth={1} className="text-foreground" />}
|
|
title={label}
|
|
/>
|
|
)
|
|
|
|
if (onClick) {
|
|
return (
|
|
<button
|
|
type="button"
|
|
tabIndex={disabled ? -1 : 0}
|
|
disabled={disabled}
|
|
onClick={onClick}
|
|
className={cn(
|
|
'group block w-full cursor-pointer text-left disabled:cursor-not-allowed disabled:opacity-50',
|
|
disabled && 'pointer-events-none'
|
|
)}
|
|
>
|
|
{card}
|
|
</button>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Link
|
|
to="/new"
|
|
search={Object.keys(params).length > 0 ? params : undefined}
|
|
className="group block"
|
|
>
|
|
{card}
|
|
</Link>
|
|
)
|
|
}
|