import { IconChartBar, IconCheck, IconCopy, IconCreditCard, IconKey, IconMail, IconPalette, IconRocket, IconSparkles, } from '@tabler/icons-react'; import { type ComponentType, useState } from 'react'; import { Link } from 'react-router'; import { Badge } from '@/components/ui/badge'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group'; import { Skeleton } from '@/components/ui/skeleton'; import { useDocsVisibility } from '@/hooks/api'; import { useSetupStatus } from '@/hooks/api/useSetupStatus'; import { isDocsHrefVisible } from '@/lib/docs-links'; import { commandForStep, type SetupIcon, type SetupIntegration, type SetupStep, type SetupStepId, } from '@/lib/setup-progress'; import { cn } from '@/lib/utils'; const STEP_ICON: Record> = { sparkles: IconSparkles, paint: IconPalette, mail: IconMail, key: IconKey, chart: IconChartBar, card: IconCreditCard, rocket: IconRocket, }; const isExternal = (url: string) => /^https?:\/\//.test(url); function CopyCommand({ command, className }: { command: string; className?: string }) { const [copied, setCopied] = useState(false); return ( ); } /** * Geometry of one timeline row, all in spacing units so it scales with the root * font size (18px here; mixing rem-sized nodes with px columns pushed the node * 4.5px wider than its column and 2px right of the connector): * - the node is `size-9` in a `--spacing(9)` column, so its centre sits at * `4.5`; the connector is centred there with `-translate-x-1/2`; * - the title line is `5` tall (`text-sm`), so the node is pulled up by half the * difference (`-mt-2`) to put its centre on the title's centre; * - the connector runs from this node's bottom edge (`py-2.5 - 2 + 9 = 9.5`) to * the next node's top edge (`-bottom-0.5`), never behind the nodes, whose * fills are translucent. * Rows carry `px-2` of padding, hence `left-6.5`. */ const CONNECTOR = 'top-9.5 -bottom-0.5 left-6.5 w-0.5 -translate-x-1/2'; interface StepNodeProps { step: SetupStep; selected: boolean; } /** * The step's circle carries every interaction state, so the row itself stays * unhighlighted: * - current: primary border plus a soft 4px glow (unchanged); * - hovered: a faint primary ring set off from the circle by a 2px gap, a * cue that the step is clickable (pure CSS: hovering anywhere on the row * hovers the step button's overlay, and the button is the `group/step`); * - selected: the same ring at full strength, which wins over hover; * - keyboard focus: an outline outside the ring. * Ring, offset and glow are composed box-shadows; on a current step that is * also hovered or selected the glow widens to 8px so it shows past the ring. */ function StepNode({ step, selected }: StepNodeProps) { return ( {step.done ? ( ) : step.launch ? ( ) : step.current ? ( ) : ( )} ); } interface TimelineStepProps { step: SetupStep; isLast: boolean; selected: boolean; onSelect: (id: SetupStepId) => void; } function TimelineStep({ step, isLast, selected, onSelect }: TimelineStepProps) { const partner = step.integrations?.find((i) => i.isPartner); return ( // The step button is the row's only control. Its ::after overlay is // stretched over the whole row (`relative` here, `after:inset-0` there), // so the click area covers the title, description, command area and // circle, padding included. Only the copy button is lifted above the // overlay. The row has no background or pointer cursor of its own (the // normal arrow throughout); hover, selection and focus show on the circle. // Hover never changes the Spotlight panel; only a click or Enter/Space does.
{!isLast && (
); } /** Spotlight eyebrow: what this step is relative to the journey. */ function spotlightEyebrow(step: SetupStep, total: number): string { const position = `Step ${step.index} of ${total}`; if (step.current) return `◆ Next up · ${position}`; if (step.optedOut) return `Skipped · ${position}`; if (step.done) return `✓ Done · ${position}`; return position; } // Rendered with `key={step.id}`, so the provider choice starts fresh for every // step the operator selects. function Spotlight({ step, total, onSkipBilling, busy, }: { step: SetupStep; total: number; onSkipBilling: () => void; busy: boolean; }) { const Icon = STEP_ICON[step.icon]; const integrations = step.integrations; const [provider, setProvider] = useState(integrations?.[0]?.id ?? ''); const selected: SetupIntegration | undefined = integrations?.find((i) => i.id === provider); const command = commandForStep(step, integrations ? provider : undefined); const docsVisibility = useDocsVisibility(); // Integrations without a hosted signup page (e.g. "Any SMTP") point their CTA // at an internal guide instead. With that documentation turned off the button // would lead nowhere, so it is dropped — the option itself stays, because the // configure command above is what actually does the work. const showCta = selected ? isDocsHrefVisible(selected.url, docsVisibility) : false; return ( ); } export function SetupProgress() { const { progress, isLoading, isError, setBillingOptOut } = useSetupStatus(); // `null` follows the current step, so the panel advances as steps complete // until the operator picks one explicitly. const [selectedId, setSelectedId] = useState(null); if (isLoading) { return ( ); } if (isError || !progress) return null; // With every step complete there is no current step: default to the deploy // finale so the panel, and step browsing, stay available. const defaultId = progress.current?.id ?? 'deploy'; const activeId = selectedId ?? defaultId; const spotlightStep = progress.steps.find((s) => s.id === activeId) ?? progress.steps[0]; return (
Setup progress {progress.complete ? ( <>You’re all set. Ready for production 🚀 ) : ( <> You’re{' '} {progress.doneCount} steps in,{' '} {progress.remaining} to launch 🚀 )}
{progress.percent}%
{progress.doneCount} / {progress.total} complete
{progress.steps.map((step, i) => ( ))}
{spotlightStep && ( setBillingOptOut.mutate(true)} /> )}
); }