mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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>
216 lines
8.8 KiB
TypeScript
216 lines
8.8 KiB
TypeScript
import { SupportCategories } from '@supabase/shared-types/out/constants'
|
|
import { Link } from '@tanstack/react-router'
|
|
import { useFlag, useParams } from 'common'
|
|
import { ExternalLinkIcon } from 'lucide-react'
|
|
import { Button } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import {
|
|
PageSection,
|
|
PageSectionContent,
|
|
PageSectionDescription,
|
|
PageSectionMeta,
|
|
PageSectionSummary,
|
|
PageSectionTitle,
|
|
} from 'ui-patterns/PageSection'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { Restriction } from '../Restriction'
|
|
import { useOrgSettingsPanel } from '../useOrgSettingsPanel'
|
|
import { InitiateCancellationFlowButton } from './CancellationFlow'
|
|
import { PlanUpdateSidePanel } from './PlanUpdateSidePanel'
|
|
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import { InlineLinkClassName } from '@/components/ui/InlineLink'
|
|
import { NoPermission } from '@/components/ui/NoPermission'
|
|
import { useOrgSubscriptionQuery } from '@/data/subscriptions/org-subscription-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
|
|
import { MANAGED_BY } from '@/lib/constants/infrastructure'
|
|
|
|
const COMPARE_PLANS_URL = 'https://supabase.com/pricing#compare-plans'
|
|
const AWS_MARKETPLACE_URL = 'https://supabase.com/aws-marketplace'
|
|
|
|
const Subscription = () => {
|
|
const { slug } = useParams()
|
|
const { setPanel } = useOrgSettingsPanel()
|
|
const projectUpdateDisabled = useFlag('disableProjectCreationAndUpdate')
|
|
const { data: selectedOrganization } = useSelectedOrganizationQuery()
|
|
|
|
const { isSuccess: isPermissionsLoaded, can: canReadSubscriptions } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.ORGANIZATION.BILLING_READ
|
|
)
|
|
|
|
const {
|
|
data: subscription,
|
|
error,
|
|
isPending: isLoading,
|
|
isError,
|
|
isSuccess,
|
|
} = useOrgSubscriptionQuery({ orgSlug: slug }, { enabled: canReadSubscriptions })
|
|
|
|
const currentPlan = subscription?.plan
|
|
const planName = currentPlan?.name ?? 'Unknown'
|
|
|
|
const canChangeTier =
|
|
!projectUpdateDisabled && !['enterprise', 'platform'].includes(currentPlan?.id ?? '')
|
|
const isDirectlyManaged = selectedOrganization?.managed_by === MANAGED_BY.SUPABASE
|
|
// Fail closed until subscription succeeds: unresolved plans look like Free and
|
|
// `billing_via_partner !== true` is true when the field is still undefined.
|
|
// Also require billing-read: disabled queries can keep a cached isSuccess.
|
|
const canPurchaseThroughAws =
|
|
canReadSubscriptions &&
|
|
isSuccess &&
|
|
canChangeTier &&
|
|
isDirectlyManaged &&
|
|
subscription.billing_via_partner === false
|
|
|
|
return (
|
|
<>
|
|
<PageSection orientation="horizontal">
|
|
<div className="col-span-full">
|
|
<Restriction />
|
|
</div>
|
|
<PageSectionMeta>
|
|
<PageSectionSummary className="gap-6">
|
|
<div className="flex flex-col gap-1">
|
|
<PageSectionTitle>Subscription Plan</PageSectionTitle>
|
|
<PageSectionDescription>
|
|
Each organization has it's own subscription plan, billing cycle, payment methods and
|
|
usage quotas.
|
|
</PageSectionDescription>
|
|
</div>
|
|
<div className="flex flex-col gap-y-2">
|
|
<p className="text-sm text-foreground-light m-0">More information</p>
|
|
<div className="flex flex-col gap-y-1">
|
|
<a
|
|
href={COMPARE_PLANS_URL}
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
className="flex items-center space-x-2 opacity-50 transition hover:opacity-100"
|
|
>
|
|
<span className="text-sm">Compare plans</span>
|
|
<ExternalLinkIcon size={16} strokeWidth={1.5} />
|
|
</a>
|
|
{canPurchaseThroughAws && (
|
|
<a
|
|
href={AWS_MARKETPLACE_URL}
|
|
target="_blank"
|
|
rel="noreferrer noopener"
|
|
className="flex items-center space-x-2 opacity-50 transition hover:opacity-100"
|
|
>
|
|
<span className="text-sm">AWS Marketplace</span>
|
|
<ExternalLinkIcon size={16} strokeWidth={1.5} />
|
|
</a>
|
|
)}
|
|
</div>
|
|
</div>
|
|
</PageSectionSummary>
|
|
</PageSectionMeta>
|
|
<PageSectionContent className="flex flex-col gap-6">
|
|
{isPermissionsLoaded && !canReadSubscriptions ? (
|
|
<NoPermission resourceText="view this organization's subscription" />
|
|
) : (
|
|
<>
|
|
{isLoading && (
|
|
<div className="space-y-2">
|
|
<ShimmeringLoader />
|
|
<ShimmeringLoader className="w-3/4" />
|
|
<ShimmeringLoader className="w-1/2" />
|
|
</div>
|
|
)}
|
|
|
|
{isError && <AlertError subject="Failed to retrieve subscription" error={error} />}
|
|
|
|
{isSuccess && (
|
|
<div className="space-y-6 w-full">
|
|
<div className="flex justify-between items-center">
|
|
<p className="text-2xl text-primary leading-none">
|
|
{currentPlan?.name ?? <span>Unknown</span>} <span>Plan</span>
|
|
</p>
|
|
|
|
{canChangeTier && (
|
|
<div className="flex space-x-2">
|
|
<Button
|
|
className="pointer-events-auto"
|
|
onClick={() => setPanel('subscriptionPlan')}
|
|
>
|
|
Change subscription plan
|
|
</Button>
|
|
{currentPlan && currentPlan.id !== 'free' && (
|
|
<InitiateCancellationFlowButton variant="danger">
|
|
Cancel subscription
|
|
</InitiateCancellationFlowButton>
|
|
)}
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
{!canChangeTier && (
|
|
<div>
|
|
{projectUpdateDisabled ? (
|
|
<Admonition
|
|
type="default"
|
|
layout="horizontal"
|
|
title={`Unable to update plan from ${planName}`}
|
|
description="We have temporarily disabled project and subscription changes - our
|
|
engineers are working on a fix."
|
|
/>
|
|
) : (
|
|
<Admonition
|
|
type="default"
|
|
layout="horizontal"
|
|
title={`Unable to update plan from ${planName}`}
|
|
description="Please contact us if you'd like to change your plan."
|
|
actions={
|
|
<Button asChild key="contact-support">
|
|
<SupportLink
|
|
queryParams={{
|
|
category: SupportCategories.SALES_ENQUIRY,
|
|
subject: `Change plan away from ${planName}`,
|
|
}}
|
|
>
|
|
Contact support
|
|
</SupportLink>
|
|
</Button>
|
|
}
|
|
/>
|
|
)}
|
|
</div>
|
|
)}
|
|
|
|
{!subscription?.usage_billing_enabled && (
|
|
<Admonition
|
|
type="default"
|
|
title="This organization is limited by the included usage"
|
|
>
|
|
<div className="[&>p]:leading-normal! prose text-sm">
|
|
Projects may become unresponsive when this organization exceeds its{' '}
|
|
<Link
|
|
to="/org/$slug/usage"
|
|
params={{ slug: slug ?? '_' }}
|
|
className={InlineLinkClassName}
|
|
>
|
|
included usage quota
|
|
</Link>
|
|
. To scale seamlessly,{' '}
|
|
{currentPlan?.id === 'free' ? (
|
|
<span>upgrade to a paid plan.</span>
|
|
) : (
|
|
<span>disable Spend Cap under the Cost Control settings.</span>
|
|
)}
|
|
</div>
|
|
</Admonition>
|
|
)}
|
|
</div>
|
|
)}
|
|
</>
|
|
)}
|
|
</PageSectionContent>
|
|
</PageSection>
|
|
<PlanUpdateSidePanel />
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default Subscription
|