'use client' import { useState } from 'react' import { toast } from 'sonner' import { ListChecks } from 'lucide-react' import { createOnboardingStep, updateOnboardingStep, deleteOnboardingStep } from '@/lib/actions' import { Card } from './card' import { useConfirm } from '@/components/ui/confirm' import { Empty, EmptyHeader, EmptyMedia, EmptyTitle, EmptyDescription } from '@/components/ui/empty' import type { Step } from './types' export function OnboardingPanel({ isAdmin, steps: initial }: { isAdmin: boolean; steps: Step[] }) { const confirm = useConfirm() const [steps, setSteps] = useState(initial) return ( { const result = await createOnboardingStep({ step_type: 'content', title: 'New step', body: 'Edit this content in Customize, Onboarding.', sort_order: steps.reduce((m, s) => Math.max(m, s.sort_order), 0) + 1 }) if ('error' in result && result.error) { toast.error(result.error); return } toast.success('Step added') const id = (result as { id: string }).id setSteps(prev => [...prev, { id, step_key: `custom-${id.slice(0, 12)}`, step_type: 'content', title: 'New step', body: 'Edit this content in Customize, Onboarding.', config: {}, is_enabled: true, is_required: false, is_system: false, sort_order: prev.reduce((m, s) => Math.max(m, s.sort_order), 0) + 1 }]) }} className="font-mono text-[10px] border border-border px-3 py-1.5 rounded hover:border-primary hover:text-primary transition whitespace-nowrap" > + Custom step ) : undefined} > {steps.length === 0 && ( No steps yet Add steps that run, in order, the first time a new member opens the app. )}