|
| 1 | +'use client' |
| 2 | + |
| 3 | +import { useEffect, useState, useCallback } from 'react' |
| 4 | + |
| 5 | +type Step = { |
| 6 | + id: string |
| 7 | + title: string |
| 8 | + description: string |
| 9 | + selector?: string |
| 10 | + position: 'top' | 'bottom' | 'right' | 'left' |
| 11 | +} |
| 12 | + |
| 13 | +const STEPS: Step[] = [ |
| 14 | + { |
| 15 | + id: 'sidebar', |
| 16 | + title: 'Navigazione', |
| 17 | + description: 'Usa la sidebar per accedere a tutte le sezioni: agenti, sessioni, analytics e impostazioni.', |
| 18 | + selector: 'nav[aria-label="sidebar"]', |
| 19 | + position: 'right', |
| 20 | + }, |
| 21 | + { |
| 22 | + id: 'dashboard', |
| 23 | + title: 'Overview', |
| 24 | + description: 'La dashboard mostra lo stato del team in tempo reale — agenti attivi, token, costi e plugin.', |
| 25 | + selector: '[data-tour="overview"]', |
| 26 | + position: 'bottom', |
| 27 | + }, |
| 28 | + { |
| 29 | + id: 'search', |
| 30 | + title: 'Ricerca globale', |
| 31 | + description: 'Premi Cmd+K per cercare agenti, sessioni, task e pagine ovunque nella dashboard.', |
| 32 | + selector: '[data-tour="search"]', |
| 33 | + position: 'bottom', |
| 34 | + }, |
| 35 | + { |
| 36 | + id: 'settings', |
| 37 | + title: 'Impostazioni', |
| 38 | + description: 'Configura provider AI, API key, bot Telegram e cron job dalla pagina impostazioni.', |
| 39 | + selector: '[data-tour="settings"]', |
| 40 | + position: 'top', |
| 41 | + }, |
| 42 | +] |
| 43 | + |
| 44 | +type TooltipProps = { step: Step; index: number; total: number; onNext: () => void; onSkip: () => void } |
| 45 | + |
| 46 | +function Tooltip({ step, index, total, onNext, onSkip }: TooltipProps) { |
| 47 | + return ( |
| 48 | + <div |
| 49 | + className="fixed z-[9999] w-72 rounded-xl p-4 flex flex-col gap-3" |
| 50 | + style={{ |
| 51 | + bottom: step.position === 'bottom' ? 'auto' : '2rem', |
| 52 | + top: step.position === 'bottom' ? '4rem' : 'auto', |
| 53 | + right: step.position === 'right' ? 'auto' : '1.5rem', |
| 54 | + left: step.position === 'right' ? '14rem' : 'auto', |
| 55 | + background: 'var(--color-panel)', |
| 56 | + border: '1px solid var(--color-green)', |
| 57 | + boxShadow: '0 8px 32px rgba(0,0,0,0.5)', |
| 58 | + }} |
| 59 | + > |
| 60 | + <div className="flex items-center justify-between"> |
| 61 | + <p className="text-[9px] font-semibold tracking-[0.2em] uppercase" style={{ color: 'var(--color-green)' }}> |
| 62 | + {index + 1} / {total} |
| 63 | + </p> |
| 64 | + <button |
| 65 | + onClick={onSkip} |
| 66 | + className="text-[10px] cursor-pointer" |
| 67 | + style={{ color: 'var(--color-dim)', background: 'none', border: 'none' }} |
| 68 | + > |
| 69 | + salta |
| 70 | + </button> |
| 71 | + </div> |
| 72 | + <p className="text-[13px] font-bold" style={{ color: 'var(--color-white)' }}>{step.title}</p> |
| 73 | + <p className="text-[11px] leading-relaxed" style={{ color: 'var(--color-muted)' }}>{step.description}</p> |
| 74 | + <button |
| 75 | + onClick={onNext} |
| 76 | + className="py-2 rounded text-[11px] font-bold cursor-pointer" |
| 77 | + style={{ background: 'var(--color-green)', color: 'var(--color-bg)' }} |
| 78 | + > |
| 79 | + {index < STEPS.length - 1 ? 'Avanti →' : 'Fine'} |
| 80 | + </button> |
| 81 | + </div> |
| 82 | + ) |
| 83 | +} |
| 84 | + |
| 85 | +export default function OnboardingTour() { |
| 86 | + const [active, setActive] = useState(false) |
| 87 | + const [step, setStep] = useState(0) |
| 88 | + |
| 89 | + useEffect(() => { |
| 90 | + fetch('/api/onboarding') |
| 91 | + .then(r => r.json()) |
| 92 | + .then(s => { if (!s.completed) setActive(true) }) |
| 93 | + .catch(() => {}) |
| 94 | + }, []) |
| 95 | + |
| 96 | + const complete = useCallback(() => { |
| 97 | + fetch('/api/onboarding', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ complete: true }) }).catch(() => {}) |
| 98 | + setActive(false) |
| 99 | + }, []) |
| 100 | + |
| 101 | + const skip = useCallback(() => { |
| 102 | + fetch('/api/onboarding', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ skip: true }) }).catch(() => {}) |
| 103 | + setActive(false) |
| 104 | + }, []) |
| 105 | + |
| 106 | + const next = useCallback(() => { |
| 107 | + const s = STEPS[step] |
| 108 | + fetch('/api/onboarding', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ stepId: s.id }) }).catch(() => {}) |
| 109 | + if (step < STEPS.length - 1) setStep(i => i + 1) |
| 110 | + else complete() |
| 111 | + }, [step, complete]) |
| 112 | + |
| 113 | + if (!active) return null |
| 114 | + |
| 115 | + return ( |
| 116 | + <> |
| 117 | + <div className="fixed inset-0 z-[9998]" style={{ background: 'rgba(0,0,0,0.45)', pointerEvents: 'none' }} /> |
| 118 | + <Tooltip step={STEPS[step]} index={step} total={STEPS.length} onNext={next} onSkip={skip} /> |
| 119 | + </> |
| 120 | + ) |
| 121 | +} |
0 commit comments