mirror of
https://github.com/supabase/supabase.git
synced 2026-10-07 02:15:05 +03:00
Follow-up to #48344: collapses the two resolution paths for the Admonition module into one. `src/admonition.tsx` was a back-compat shim re-exporting `src/Admonition/`. Two ways to resolve one module is exactly what produced the macOS self-import bug fixed in #48344, and the local typecheck errors that #48374 worked around. This removes the shim and standardizes on the PascalCase subpath, matching every other export in the package. **Changed:** - Codemodded all 246 `ui-patterns/admonition` imports to `ui-patterns/Admonition` (240 `.tsx`, 5 `.mdx`, 1 `.ts` across studio, docs, www, design-system, and lite-studio) - Pointed the 5 internal `'../admonition'` imports back at the `'../Admonition'` directory **Removed:** - `packages/ui-patterns/src/admonition.tsx`, and its `./admonition` entry in the exports map (regenerated with `pnpm gen:exports`) ## To test - `grep -r "ui-patterns/admonition" --include='*.ts*'` → no hits - `pnpm test:case-hazards` → passes - `pnpm typecheck` → all 15 tasks green - `pnpm --filter studio run lint:ratchet` → passes - `pnpm --filter ui-patterns vitest run src/Admonition` → 11 tests pass <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Standardized Admonition component imports across the application and documentation. * Improved compatibility with case-sensitive environments by using the canonical component path. * Removed the legacy Admonition import entry point. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
208 lines
6.9 KiB
TypeScript
208 lines
6.9 KiB
TypeScript
import { FeatureFlagContext } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { ReactNode, useContext, useEffect, useRef, useState } from 'react'
|
|
import { Button, Card, CardContent } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { OrganizationSelector } from '../Connect/OrganizationSelector'
|
|
import { CreditCodeRedemption } from '@/components/interfaces/Organization/BillingSettings/CreditCodeRedemption'
|
|
import {
|
|
InterstitialAccountRow,
|
|
InterstitialLayout,
|
|
SupabaseLogo,
|
|
} from '@/components/layouts/InterstitialLayout'
|
|
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
|
|
import { useProfile } from '@/lib/profile'
|
|
import { EMPTY_ARR } from '@/lib/void'
|
|
|
|
const RETURN_TO_SELECTED_ORG_PARAM = 'selected_org'
|
|
|
|
const RedeemCreditsInterstitial = ({
|
|
title,
|
|
description,
|
|
children,
|
|
}: {
|
|
title: ReactNode
|
|
description?: ReactNode
|
|
children: ReactNode
|
|
}) => (
|
|
<InterstitialLayout logo={<SupabaseLogo />} title={title} description={description}>
|
|
<div className="px-6 pb-6">{children}</div>
|
|
</InterstitialLayout>
|
|
)
|
|
|
|
export const RedeemCreditsScreen = () => {
|
|
const router = useRouter()
|
|
const { profile, isLoading: isLoadingProfile } = useProfile()
|
|
const { hasLoaded } = useContext(FeatureFlagContext)
|
|
|
|
const [selectedOrgSlug, setSelectedOrgSlug] = useState<string | null>(null)
|
|
const [redemptionModalOrgSlug, setRedemptionModalOrgSlug] = useState<string | null>(null)
|
|
const appliedReturnSelectedOrgRef = useRef<string | null>(null)
|
|
|
|
const {
|
|
data: organizationOptions = EMPTY_ARR,
|
|
error: organizationsError,
|
|
isLoading: isLoadingOrganizations,
|
|
isError: isOrganizationsError,
|
|
} = useOrganizationsQuery()
|
|
|
|
const returnSelectedOrgSlug =
|
|
router.isReady && typeof router.query[RETURN_TO_SELECTED_ORG_PARAM] === 'string'
|
|
? router.query[RETURN_TO_SELECTED_ORG_PARAM]
|
|
: null
|
|
|
|
const displayName = profile?.primary_email ?? profile?.username
|
|
|
|
const isLoading = isLoadingProfile || isLoadingOrganizations || !hasLoaded
|
|
|
|
useEffect(() => {
|
|
if (!returnSelectedOrgSlug) return
|
|
if (appliedReturnSelectedOrgRef.current === returnSelectedOrgSlug) return
|
|
|
|
const hasReturnedOrganization = (organizationOptions ?? []).some(
|
|
(organization) => organization.slug === returnSelectedOrgSlug
|
|
)
|
|
|
|
if (hasReturnedOrganization) {
|
|
setSelectedOrgSlug(returnSelectedOrgSlug)
|
|
appliedReturnSelectedOrgRef.current = returnSelectedOrgSlug
|
|
}
|
|
}, [organizationOptions, returnSelectedOrgSlug])
|
|
|
|
if (isLoading) {
|
|
return (
|
|
<RedeemCreditsInterstitial
|
|
title={<ShimmeringLoader className="mx-auto h-7 w-32 max-w-full py-0" />}
|
|
description={<ShimmeringLoader className="mx-auto h-4 w-56 max-w-full py-0" />}
|
|
>
|
|
<ConnectLoadingCards />
|
|
</RedeemCreditsInterstitial>
|
|
)
|
|
}
|
|
|
|
if (isOrganizationsError) {
|
|
return (
|
|
<RedeemCreditsInterstitial
|
|
title="Unable to load credit redemption"
|
|
description="Please try again before redeeming this code"
|
|
>
|
|
<div className="flex flex-col gap-3">
|
|
<Admonition
|
|
type="warning"
|
|
description={
|
|
<>
|
|
We could not load your organizations.
|
|
{organizationsError && (
|
|
<span className="mt-1 block text-foreground-lighter">
|
|
Error: {organizationsError.message}
|
|
</span>
|
|
)}
|
|
</>
|
|
}
|
|
/>
|
|
</div>
|
|
</RedeemCreditsInterstitial>
|
|
)
|
|
}
|
|
|
|
const createOrganizationParams = {
|
|
returnTo: router.asPath || '/redeem',
|
|
returnToOrgParam: RETURN_TO_SELECTED_ORG_PARAM,
|
|
}
|
|
|
|
const openRedemption = () => {
|
|
if (!selectedOrgSlug) return
|
|
setRedemptionModalOrgSlug(selectedOrgSlug)
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<RedeemCreditsInterstitial
|
|
title="Redeem credits"
|
|
description="Choose an organization to redeem this code"
|
|
>
|
|
<div className="flex flex-col gap-5">
|
|
<InterstitialAccountRow displayName={displayName} />
|
|
|
|
<OrganizationSelector
|
|
organizations={organizationOptions}
|
|
selectedSlug={selectedOrgSlug}
|
|
onSelect={setSelectedOrgSlug}
|
|
getOrganizationDescription={(organization) => `${organization.plan.name} Plan`}
|
|
createLabel={
|
|
organizationOptions.length === 0
|
|
? 'Create your first organization'
|
|
: 'Create new organization'
|
|
}
|
|
createHrefParams={createOrganizationParams}
|
|
/>
|
|
|
|
{organizationOptions.length === 0 && (
|
|
<Admonition
|
|
type="warning"
|
|
description="Create an organization before redeeming this credit code."
|
|
/>
|
|
)}
|
|
|
|
<div className="flex flex-col gap-2">
|
|
<Button
|
|
block
|
|
variant="primary"
|
|
disabled={!selectedOrgSlug || organizationOptions.length === 0}
|
|
onClick={openRedemption}
|
|
>
|
|
Redeem credits
|
|
</Button>
|
|
<p className="text-center text-xs text-foreground-lighter text-balance">
|
|
Credits apply to one organization and are used toward future invoices before your
|
|
payment method is charged.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</RedeemCreditsInterstitial>
|
|
|
|
{redemptionModalOrgSlug && (
|
|
<CreditCodeRedemption
|
|
modalVisible
|
|
slug={redemptionModalOrgSlug}
|
|
onClose={() => setRedemptionModalOrgSlug(null)}
|
|
/>
|
|
)}
|
|
</>
|
|
)
|
|
}
|
|
|
|
const ConnectLoadingCards = () => (
|
|
<div className="flex flex-col gap-5">
|
|
<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>
|
|
<section className="space-y-2" aria-label="Organizations">
|
|
<ShimmeringLoader className="h-3 w-24 py-0" />
|
|
{Array.from({ length: 3 }).map((_, index) => (
|
|
<Card key={index} className="shadow-none">
|
|
<CardContent className="flex items-center gap-3 border-none px-4 py-3">
|
|
<ShimmeringLoader className="size-9 flex-shrink-0 rounded-lg py-0" />
|
|
<div className="min-w-0 flex-1 space-y-2">
|
|
<ShimmeringLoader className="h-4 w-32 py-0" />
|
|
<ShimmeringLoader className="h-3 w-20 py-0" />
|
|
</div>
|
|
</CardContent>
|
|
</Card>
|
|
))}
|
|
</section>
|
|
<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>
|
|
)
|