import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { Check, X, ChevronRight } from 'lucide-react' import { cn } from '@/lib/utils' import { getOnboardingStatus, dismissOnboarding } from '@/api/onboarding' import type { OnboardingStatus } from '@/api/onboarding' interface ChecklistItem { key: keyof OnboardingStatus label: string path: string } const SOLO_ITEMS: ChecklistItem[] = [ { key: 'ran_session', label: 'Try troubleshooting a ticket', path: '/' }, { key: 'exported_session', label: 'Review your session notes', path: '/sessions' }, { key: 'created_flow', label: 'Explore guided flows', path: '/trees' }, { key: 'tried_ai_assistant', label: 'Check out the Script Builder', path: '/script-builder' }, ] const TEAM_ITEMS: ChecklistItem[] = [ { key: 'ran_session', label: 'Try troubleshooting a ticket', path: '/' }, { key: 'exported_session', label: 'Review your session notes', path: '/sessions' }, { key: 'invited_teammate', label: 'Invite a team member', path: '/account' }, { key: 'created_flow', label: 'Explore guided flows', path: '/trees' }, { key: 'connected_psa', label: 'Connect your PSA', path: '/account/integrations' }, ] export function OnboardingChecklist() { const navigate = useNavigate() const [status, setStatus] = useState(null) const [dismissed, setDismissed] = useState(false) const [allComplete, setAllComplete] = useState(false) useEffect(() => { getOnboardingStatus() .then(setStatus) .catch(() => { // Silently fail — don't show checklist if endpoint unavailable }) }, []) const items = status?.is_team_user ? TEAM_ITEMS : SOLO_ITEMS const completedCount = status ? items.filter((item) => status[item.key]).length : 0 const totalCount = items.length const isAllDone = completedCount === totalCount && status !== null useEffect(() => { if (isAllDone) { const timer = setTimeout(() => setAllComplete(true), 2000) return () => clearTimeout(timer) } }, [isAllDone]) // Don't render if dismissed, fully complete, or not loaded yet if (!status || status.dismissed || dismissed || allComplete) return null const progressPercent = totalCount > 0 ? (completedCount / totalCount) * 100 : 0 const handleDismiss = async () => { setDismissed(true) try { await dismissOnboarding() } catch { // Already hidden locally } } return (
{/* Progress bar */}
{/* Header */}

Getting Started

{isAllDone ? ( You're all set! ) : ( {completedCount} {' '}of {totalCount} complete )}

{/* Checklist items */}
    {items.map((item) => { const done = status[item.key] return (
  • ) })}
) }