import { useState, useCallback } from 'react'; import Joyride, { type CallBackProps, STATUS, ACTIONS, EVENTS } from 'react-joyride'; import { TOUR_STEPS } from '../../config/tourSteps'; import { useAuthStore } from '../../stores/authStore'; import api from '../../services/api'; interface AppTourProps { run: boolean; onComplete: () => void; } export function AppTour({ run, onComplete }: AppTourProps) { const [stepIndex, setStepIndex] = useState(0); const setUserIntroSeen = useAuthStore((s) => s.setUserIntroSeen); const handleCallback = useCallback( async (data: CallBackProps) => { const { status, action, type } = data; const finishedStatuses: string[] = [STATUS.FINISHED, STATUS.SKIPPED]; if (finishedStatuses.includes(status)) { // Mark intro as seen on backend (fire-and-forget) api.patch('/auth/intro-seen').catch(() => {}); setUserIntroSeen(); onComplete(); return; } // Handle step navigation if (type === EVENTS.STEP_AFTER) { setStepIndex((prev) => action === ACTIONS.PREV ? prev - 1 : prev + 1, ); } }, [onComplete, setUserIntroSeen], ); if (!run) return null; return ( ); }