'use client';
import { useState } from 'react';
import {
ArchiveIcon,
ChevronRightIcon,
CircleCheckIcon,
CircleDashedIcon,
EllipsisIcon,
MailIcon,
} from 'lucide-react';
import { Button, buttonVariants } from '@/components/ui/button';
import { Collapsible, CollapsibleContent } from '@/components/ui/collapsible';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import { cn } from '@/lib/utils';
interface OnboardingStep {
id: string;
title: string;
description: string;
completed: boolean;
actionLabel: string;
actionHref: string;
}
const steps: OnboardingStep[] = [
{
id: 'show',
title: 'Create your first show',
description:
'Give your podcast a name, cover art and a short tagline so listeners know what to expect.',
completed: true,
actionLabel: 'Edit show',
actionHref: '#',
},
{
id: 'room',
title: 'Set up a recording room',
description:
'Pick your default microphone, sample rate and whether guests join from the browser or the app.',
completed: false,
actionLabel: 'Configure room',
actionHref: '#',
},
{
id: 'cohosts',
title: 'Invite your co-hosts',
description:
'Add the people who record with you so they can join sessions and review edits.',
completed: false,
actionLabel: 'Send invites',
actionHref: '#',
},
{
id: 'distribution',
title: 'Connect distribution',
description:
'Link your RSS feed to Spotify, Apple Podcasts and YouTube so every episode publishes everywhere at once.',
completed: false,
actionLabel: 'Connect platforms',
actionHref: '#',
},
{
id: 'episode',
title: 'Publish a trailer episode',
description:
'Record a two-minute trailer and schedule it so directories can index your show before launch day.',
completed: false,
actionLabel: 'Record trailer',
actionHref: '#',
},
{
id: 'alerts',
title: 'Choose your alerts',
description:
'Decide when Soundstage should ping you about new reviews, download milestones and sponsor replies.',
completed: false,
actionLabel: 'Manage alerts',
actionHref: '#',
},
];
function CircularProgress({
completed,
total,
}: {
completed: number;
total: number;
}) {
const progress = total > 0 ? ((total - completed) / total) * 100 : 0;
const strokeDashoffset = 100 - progress;
return (
<svg className="-rotate-90" height="14" viewBox="0 0 14 14" width="14">
<circle
className="stroke-muted"
cx="7"
cy="7"
fill="none"
pathLength="100"
r="6"
strokeWidth="2"
/>
<circle
className="stroke-primary"
cx="7"
cy="7"
fill="none"
pathLength="100"
r="6"
strokeDasharray="100"
strokeLinecap="round"
strokeWidth="2"
style={{ strokeDashoffset }}
/>
</svg>
);
}
function StepIndicator({ completed }: { completed: boolean }) {
if (completed) {
return (
<CircleCheckIcon
aria-hidden="true"
className="mt-1 size-4.5 shrink-0 fill-primary text-primary-foreground"
/>
);
}
return (
<CircleDashedIcon
aria-hidden="true"
className="mt-1 size-5 shrink-0 text-muted-foreground/40"
strokeWidth={2}
/>
);
}
export default function Onboarding01() {
const [currentSteps, setCurrentSteps] = useState<OnboardingStep[]>(steps);
const [openStepId, setOpenStepId] = useState<string | null>(() => {
const firstIncomplete = steps.find((s) => !s.completed);
return firstIncomplete?.id ?? steps[0]?.id ?? null;
});
const [dismissed, setDismissed] = useState(false);
const completedCount = currentSteps.filter((s) => s.completed).length;
const remainingCount = currentSteps.length - completedCount;
const handleStepClick = (stepId: string) => {
setOpenStepId(openStepId === stepId ? null : stepId);
};
const handleStepAction = (step: OnboardingStep) => {
const updated = currentSteps.map((s) =>
s.id === step.id ? { ...s, completed: true } : s
);
setCurrentSteps(updated);
const nextIncomplete = updated.find((s) => !s.completed);
setOpenStepId(nextIncomplete?.id ?? null);
};
if (dismissed) {
return (
<div className="mx-auto w-full max-w-lg px-4 text-center">
<p className="text-pretty text-muted-foreground">Checklist hidden</p>
<button
className="mt-2 text-primary text-sm underline"
onClick={() => setDismissed(false)}
type="button"
>
Show again
</button>
</div>
);
}
return (
<div className="mx-auto w-full max-w-lg px-4">
<div className="w-full rounded-lg border bg-card p-4 text-card-foreground shadow-xs">
<div className="mr-2 mb-4 flex flex-col justify-between sm:flex-row sm:items-center">
<h3 className="ml-2 text-balance font-semibold text-foreground">
Launch your show on Soundstage
</h3>
<div className="mt-2 flex items-center justify-end sm:mt-0">
<CircularProgress
completed={remainingCount}
total={currentSteps.length}
/>
<div className="mr-3 ml-1.5 text-muted-foreground text-sm">
<span className="font-medium text-foreground">
{completedCount}
</span>
{' / '}
<span className="font-medium text-foreground">
{currentSteps.length}
</span>{' '}
completed
</div>
<DropdownMenu>
<DropdownMenuTrigger
render={<Button size="icon-xs" variant="ghost" />}
>
<EllipsisIcon
aria-hidden="true"
className="size-4 shrink-0"
/>
<span className="sr-only">Options</span>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-40">
<DropdownMenuItem onClick={() => setDismissed(true)}>
<ArchiveIcon aria-hidden="true" className="size-4 shrink-0" />
Hide checklist
</DropdownMenuItem>
<DropdownMenuItem>
<MailIcon aria-hidden="true" className="size-4 shrink-0" />
Share feedback
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</div>
</div>
<div className="space-y-0">
{currentSteps.map((step, index) => {
const isOpen = openStepId === step.id;
const isFirst = index === 0;
const prevStep = currentSteps[index - 1];
const isPrevOpen = prevStep && openStepId === prevStep.id;
const showBorderTop = !(isFirst || isOpen || isPrevOpen);
return (
<div
className={cn(
'group',
isOpen && 'rounded-lg',
showBorderTop && 'border-border border-t'
)}
key={step.id}
>
<div
className={cn(
'block w-full cursor-pointer text-left focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2',
isOpen && 'rounded-lg'
)}
onClick={() => handleStepClick(step.id)}
onKeyDown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handleStepClick(step.id);
}
}}
role="button"
tabIndex={0}
>
<div
className={cn(
'relative overflow-hidden rounded-lg transition-colors',
isOpen && 'border border-border bg-muted'
)}
>
<div className="relative flex items-center justify-between gap-3 py-3 pr-2 pl-4">
<div className="flex w-full gap-3">
<div className="shrink-0">
<StepIndicator completed={step.completed} />
</div>
<div className="mt-0.5 grow">
<h4
className={cn(
'font-semibold',
step.completed
? 'text-primary'
: 'text-foreground'
)}
>
{step.title}
</h4>
<Collapsible open={isOpen}>
<CollapsibleContent>
<p className="mt-2 text-pretty text-muted-foreground text-sm sm:max-w-64 md:max-w-xs">
{step.description}
</p>
<a
className={cn(
buttonVariants({ size: 'sm' }),
'mt-3'
)}
href={step.actionHref}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleStepAction(step);
}}
>
{step.actionLabel}
</a>
</CollapsibleContent>
</Collapsible>
</div>
</div>
{!isOpen && (
<ChevronRightIcon
aria-hidden="true"
className="size-4 shrink-0 text-muted-foreground"
/>
)}
</div>
</div>
</div>
</div>
);
})}
</div>
</div>
</div>
);
}