mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
Part 4 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 ← this PR** | **Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, Compute** | | 5 | #54308 | 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 `components/interfaces/{Integrations,Settings,Observability,LogDrains,Issues,Linter,Reports,QueryPerformance,QuerySources,ConfigDrift,DiskManagement,Compute}/` off `next/link`. **Changed:** - Replaced `next/link` across all 72 files in Integrations, Settings, Observability, LogDrains, Issues, Linter, Reports, QueryPerformance, QuerySources, ConfigDrift, DiskManagement, and Compute interfaces - Updated legacy permanent-redirect hrefs (`/settings/database` → `/database/settings`, `/settings/vault/secrets` → `/integrations/vault/secrets`, `/reports/database#database-size-report` → `/observability/database#database-size-report`) to canonical routes - Flattened legacy nested `<Link><a>...</a></Link>` markup in `DatabaseReadOnlyAlert.tsx` and dropped `passHref` in `Integrations/Queues/QueueTab.tsx` - Standardized external `target="_blank"` anchors with `rel="noreferrer noopener"`, switched `ObservabilityOverviewFooter.tsx` to `InlineLink` + `DOCS_URL`, and applied `InlineLinkClassName` to the typed billing links in `DatabaseReadOnlyAlert.tsx` per review feedback - Removed `vi.mock('next/link', ...)` from `Settings/General/Project.test.tsx` and `MobileIssuesNavigation.platform.test.tsx` Addresses [FE-5108](https://linear.app/supabase/issue/FE-5108/replace-the-nextlink-shim-with-tanstack-link) ## To test - [ ] Navigate across Integrations (marketplace, cron, queues, wrappers, Vercel/GitHub), Settings (database, infrastructure, read replicas, logs), Observability, Issues, and Compute pages - [ ] Verify Logs Preview → Logs Explorer links preserve multi-line SQL queries in search params - [ ] Verify billing and database-size links preserve query parameters and hash fragments --------- Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
389 lines
14 KiB
TypeScript
389 lines
14 KiB
TypeScript
import { zodResolver } from '@hookform/resolvers/zod'
|
|
import { ExternalLinkIcon } from 'lucide-react'
|
|
import { useCallback, useEffect, useRef, useState } from 'react'
|
|
import { useForm } from 'react-hook-form'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
Sheet,
|
|
SheetContent,
|
|
SheetFooter,
|
|
SheetHeader,
|
|
SheetSection,
|
|
SheetTitle,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { Input } from 'ui-patterns/DataInputs/Input'
|
|
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
|
|
import * as z from 'zod'
|
|
|
|
import { RequiredExtensionsSection } from '../../Integration/RequiredExtensionsSection'
|
|
import { InstallationError } from './InstallationError'
|
|
import { IntegrationInstalledActions, IntegrationNotInstalledActions } from './IntegrationActions'
|
|
import {
|
|
hasInstallError,
|
|
hasUninstallError,
|
|
isInstallDone,
|
|
isInstalled,
|
|
isInstalling,
|
|
isUninstallDone,
|
|
isUninstalling,
|
|
} from './stripe-sync-status'
|
|
import { StripeSyncChangesCard } from './StripeSyncChangesCard'
|
|
import { useStripeSyncStatus } from '@/components/interfaces/Integrations/templates/StripeSyncEngine/useStripeSyncStatus'
|
|
import { useStripeSyncInstallMutation } from '@/data/database-integrations/stripe/stripe-sync-install-mutation'
|
|
import { useStripeSyncUninstallMutation } from '@/data/database-integrations/stripe/stripe-sync-uninstall-mutation'
|
|
import { useSchemasQuery } from '@/data/database/schemas-query'
|
|
import { FGA_PERMISSIONS, useAsyncCheckPermissionsV2 } from '@/hooks/misc/useCheckPermissionsV2'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
const installFormSchema = z.object({
|
|
stripeSecretKey: z.string().min(1, 'Stripe API key is required'),
|
|
})
|
|
|
|
const StripeSyncContent = () => {
|
|
const track = useTrack()
|
|
const hasTrackedInstallFailed = useRef(false)
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const [showUninstallModal, setShowUninstallModal] = useState(false)
|
|
const [shouldShowInstallSheet, setShouldShowInstallSheet] = useState(false)
|
|
// These flags bridge the gap between mutation success and schema update
|
|
const [isInstallInitiated, setIsInstallInitiated] = useState(false)
|
|
const [isUninstallInitiated, setIsUninstallInitiated] = useState(false)
|
|
|
|
const formId = 'stripe-sync-install-form'
|
|
const form = useForm<z.infer<typeof installFormSchema>>({
|
|
resolver: zodResolver(installFormSchema),
|
|
defaultValues: { stripeSecretKey: '' },
|
|
mode: 'onSubmit',
|
|
})
|
|
|
|
const {
|
|
schemaComment,
|
|
schemaComment: { status: installationStatus },
|
|
latestAvailableVersion,
|
|
timedOut,
|
|
} = useStripeSyncStatus()
|
|
|
|
// Check permissions for managing function secrets
|
|
const { can: canManageSecrets } = useAsyncCheckPermissionsV2(
|
|
FGA_PERMISSIONS.PROJECT.EDGE_FUNCTIONS_SECRETS_WRITE
|
|
)
|
|
|
|
const installed = isInstalled(installationStatus)
|
|
const installError = hasInstallError(installationStatus)
|
|
const uninstallError = hasUninstallError(installationStatus)
|
|
const installInProgress = isInstalling(installationStatus)
|
|
const uninstallInProgress = isUninstalling(installationStatus)
|
|
const installDone = isInstallDone(installationStatus)
|
|
const uninstallDone = isUninstallDone(installationStatus)
|
|
|
|
// Detect if this is an upgrade (both old and new versions present)
|
|
let oldVersion
|
|
let newVersion
|
|
if (installed) {
|
|
// when installed we compare the installed version against the latest available
|
|
oldVersion = schemaComment?.newVersion
|
|
newVersion = latestAvailableVersion
|
|
} else {
|
|
// otherwise compare the old and new versions from the schema
|
|
oldVersion = schemaComment?.oldVersion
|
|
newVersion = schemaComment?.newVersion
|
|
}
|
|
|
|
const upgradeAvailable = !!(oldVersion && newVersion && oldVersion !== newVersion)
|
|
const upgradeDone = latestAvailableVersion == schemaComment?.newVersion
|
|
|
|
const {
|
|
mutate: installStripeSync,
|
|
isPending: isInstallRequested,
|
|
error: installRequestError,
|
|
reset: resetInstallError,
|
|
} = useStripeSyncInstallMutation({
|
|
onSuccess: () => {
|
|
toast.success(
|
|
upgradeAvailable ? 'Stripe Sync upgrade started' : 'Stripe Sync installation started'
|
|
)
|
|
setShouldShowInstallSheet(false)
|
|
form.reset()
|
|
setIsInstallInitiated(true)
|
|
},
|
|
})
|
|
|
|
const { mutate: uninstallStripeSync, isPending: isUninstallRequested } =
|
|
useStripeSyncUninstallMutation({
|
|
onSuccess: () => {
|
|
toast.success('Stripe Sync uninstallation started')
|
|
setShowUninstallModal(false)
|
|
setIsUninstallInitiated(true)
|
|
},
|
|
})
|
|
|
|
// Combine schema status with mutation/initiated states for UI
|
|
const installing = (installInProgress || isInstallRequested || isInstallInitiated) && !timedOut
|
|
const uninstalling =
|
|
(uninstallInProgress || isUninstallRequested || isUninstallInitiated) && !timedOut
|
|
|
|
const hasError = (uninstallError || installError) && ((!uninstalling && !installing) || timedOut)
|
|
|
|
// Poll for schema changes during transitions
|
|
useSchemasQuery(
|
|
{ projectRef: project?.ref, connectionString: project?.connectionString },
|
|
{ refetchInterval: installing || uninstalling ? 5000 : false }
|
|
)
|
|
|
|
const handleUninstall = useCallback(() => {
|
|
if (!project?.ref) return
|
|
|
|
uninstallStripeSync({
|
|
projectRef: project.ref,
|
|
startTime: Date.now(),
|
|
})
|
|
}, [project?.ref, uninstallStripeSync])
|
|
|
|
const handleOpenInstallSheet = useCallback(() => {
|
|
resetInstallError()
|
|
setShouldShowInstallSheet(true)
|
|
}, [resetInstallError])
|
|
|
|
const handleCloseInstallSheet = (isOpen: boolean) => {
|
|
if (isInstallRequested) return
|
|
|
|
setShouldShowInstallSheet(isOpen)
|
|
if (!isOpen) {
|
|
form.reset()
|
|
resetInstallError()
|
|
}
|
|
}
|
|
|
|
// Track install failures
|
|
useEffect(() => {
|
|
if (!installError) {
|
|
hasTrackedInstallFailed.current = false
|
|
return
|
|
}
|
|
|
|
if (!hasTrackedInstallFailed.current) {
|
|
hasTrackedInstallFailed.current = true
|
|
track('integration_install_failed', {
|
|
integrationName: 'stripe_sync_engine',
|
|
})
|
|
}
|
|
}, [installError, track])
|
|
|
|
// Clear install initiated flag once schema reflects successful completion
|
|
// For errors, the flag is cleared when user manually retries (handleOpenInstallSheet)
|
|
useEffect(() => {
|
|
if (isInstallInitiated && installDone && upgradeDone && !installError) {
|
|
setIsInstallInitiated(false)
|
|
}
|
|
}, [isInstallInitiated, installDone, upgradeDone, installError])
|
|
|
|
// Clear uninstall initiated flag once schema is removed or error
|
|
useEffect(() => {
|
|
if (isUninstallInitiated && uninstallDone) {
|
|
setIsUninstallInitiated(false)
|
|
}
|
|
}, [isUninstallInitiated, uninstallDone])
|
|
|
|
return (
|
|
<>
|
|
{hasError && (
|
|
<InstallationError
|
|
error={uninstallError ? 'uninstall' : 'install'}
|
|
handleUninstall={handleUninstall}
|
|
handleOpenInstallSheet={handleOpenInstallSheet}
|
|
isUpgrade={upgradeAvailable}
|
|
installing={installing}
|
|
uninstalling={uninstalling}
|
|
/>
|
|
)}
|
|
|
|
{!installed && !uninstalling && !uninstallError ? (
|
|
<>
|
|
<StripeSyncChangesCard
|
|
installationStatus={installationStatus}
|
|
isUpgrade={upgradeAvailable}
|
|
/>
|
|
<IntegrationNotInstalledActions
|
|
isUninstallRequested={isUninstallRequested}
|
|
handleUninstall={handleUninstall}
|
|
/>
|
|
</>
|
|
) : (
|
|
(installed || uninstalling || uninstallError) && (
|
|
<>
|
|
<StripeSyncChangesCard
|
|
installationStatus={installationStatus}
|
|
isUpgrade={upgradeAvailable}
|
|
/>
|
|
<IntegrationInstalledActions
|
|
disabled={installing || uninstalling || !canManageSecrets}
|
|
upgradeAvailable={upgradeAvailable}
|
|
installing={installing}
|
|
uninstalling={uninstalling}
|
|
isUninstallRequested={isUninstallRequested}
|
|
setShouldShowInstallSheet={setShouldShowInstallSheet}
|
|
setShowUninstallModal={setShowUninstallModal}
|
|
/>
|
|
</>
|
|
)
|
|
)}
|
|
|
|
<Sheet open={!!shouldShowInstallSheet} onOpenChange={handleCloseInstallSheet}>
|
|
<SheetContent size="lg" className="flex flex-col gap-0">
|
|
<Form {...form}>
|
|
<form
|
|
id={formId}
|
|
onSubmit={form.handleSubmit(({ stripeSecretKey }) => {
|
|
if (!project?.ref) return
|
|
installStripeSync({
|
|
projectRef: project.ref,
|
|
stripeSecretKey,
|
|
startTime: Date.now(),
|
|
})
|
|
})}
|
|
className="overflow-auto grow px-0 flex flex-col"
|
|
>
|
|
<SheetHeader>
|
|
<SheetTitle>
|
|
{upgradeAvailable ? <span>Upgrade</span> : <span>Install</span>}{' '}
|
|
<span>Stripe Sync Engine</span>
|
|
</SheetTitle>
|
|
</SheetHeader>
|
|
<SheetSection className="flex-1 flex flex-col gap-y-6">
|
|
<StripeSyncChangesCard
|
|
installationStatus={installationStatus}
|
|
isUpgrade={upgradeAvailable}
|
|
/>
|
|
|
|
<h3 className="heading-default">Configuration</h3>
|
|
|
|
<div className="flex flex-col gap-y-2">
|
|
<FormField
|
|
control={form.control}
|
|
name="stripeSecretKey"
|
|
render={({ field }) => (
|
|
<FormItemLayout
|
|
layout="flex-row-reverse"
|
|
label="Stripe API secret key"
|
|
description="Your Stripe secret key. Requires write access to Webhook Endpoints and read-only access to all other categories."
|
|
>
|
|
<FormControl className="col-span-8">
|
|
<Input
|
|
id="stripe_api_key"
|
|
name="stripe_api_key"
|
|
placeholder="Enter your Stripe API key"
|
|
autoComplete="stripe-api-key"
|
|
reveal={false}
|
|
disabled={isInstallRequested}
|
|
type="password"
|
|
value={field.value}
|
|
onChange={(e) => field.onChange(e.target.value)}
|
|
/>
|
|
</FormControl>
|
|
</FormItemLayout>
|
|
)}
|
|
/>
|
|
|
|
<div className="flex items-center gap-x-2">
|
|
<Button asChild icon={<ExternalLinkIcon />}>
|
|
<a
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
href="https://dashboard.stripe.com/apikeys"
|
|
>
|
|
Get Stripe API key
|
|
</a>
|
|
</Button>
|
|
<Button asChild icon={<ExternalLinkIcon />}>
|
|
<a
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
href="https://support.stripe.com/questions/what-are-stripe-api-keys-and-how-to-find-them"
|
|
>
|
|
What are Stripe API keys?
|
|
</a>
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
|
|
{installRequestError && (
|
|
<Admonition
|
|
type="destructive"
|
|
title="Installation failed"
|
|
description={installRequestError.message}
|
|
/>
|
|
)}
|
|
</SheetSection>
|
|
|
|
<SheetFooter>
|
|
<Button
|
|
disabled={isInstallRequested}
|
|
onClick={() => handleCloseInstallSheet(false)}
|
|
>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
form={formId}
|
|
type="submit"
|
|
variant="primary"
|
|
loading={isInstallRequested}
|
|
disabled={!form.formState.isValid || isInstallRequested}
|
|
>
|
|
{isInstallRequested
|
|
? upgradeAvailable
|
|
? 'Upgrading'
|
|
: 'Installing'
|
|
: upgradeAvailable
|
|
? 'Upgrade integration'
|
|
: 'Install integration'}
|
|
</Button>
|
|
</SheetFooter>
|
|
</form>
|
|
</Form>
|
|
</SheetContent>
|
|
</Sheet>
|
|
|
|
<ConfirmationModal
|
|
visible={showUninstallModal}
|
|
title="Uninstall Stripe Sync Engine"
|
|
confirmLabel="Uninstall"
|
|
confirmLabelLoading="Uninstalling..."
|
|
variant="destructive"
|
|
loading={isUninstallRequested}
|
|
onCancel={() => setShowUninstallModal(false)}
|
|
onConfirm={handleUninstall}
|
|
>
|
|
<p className="text-sm text-foreground-light">
|
|
Are you sure you want to uninstall the Stripe Sync Engine? This will:
|
|
</p>
|
|
<ul className="list-disc pl-5 mt-2 text-sm text-foreground-light space-y-1">
|
|
<li>
|
|
Remove the <code>stripe</code> schema and all tables
|
|
</li>
|
|
<li>Delete all synced Stripe data</li>
|
|
<li>Remove the associated Edge Functions</li>
|
|
<li>Remove the scheduled sync jobs</li>
|
|
</ul>
|
|
<p className="mt-4 text-sm text-foreground-light font-medium">
|
|
This action cannot be undone.
|
|
</p>
|
|
</ConfirmationModal>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const StripeSyncEngineOverviewTab = () => (
|
|
<>
|
|
<RequiredExtensionsSection />
|
|
<StripeSyncContent />
|
|
</>
|
|
)
|