import { useState, type FormEvent } from 'react' import { useNavigate } from 'react-router-dom' import { Loader2 } from 'lucide-react' import { useAuthStore } from '@/store/authStore' import { onboardingApi, type RoleAtSignup, type TeamSizeBucket, } from '@/api/onboarding' import { cn } from '@/lib/utils' const TEAM_SIZE_OPTIONS: { value: TeamSizeBucket; label: string }[] = [ { value: '1-2', label: '1–2' }, { value: '3-5', label: '3–5' }, { value: '6-10', label: '6–10' }, { value: '11-25', label: '11–25' }, { value: '26+', label: '26+' }, ] const ROLE_OPTIONS: { value: RoleAtSignup; label: string }[] = [ { value: 'owner', label: 'Owner' }, { value: 'lead_tech', label: 'Lead Tech' }, { value: 'tech', label: 'Tech' }, { value: 'other', label: 'Other' }, ] /** * `/welcome/step-1` — first step of the welcome wizard. Captures shop context * (company name, team size, role). Persists server-side before navigating. */ export function WelcomeStep1() { const navigate = useNavigate() const account = useAuthStore((s) => s.account) const fetchUser = useAuthStore((s) => s.fetchUser) const [companyName, setCompanyName] = useState(account?.name ?? '') const [teamSize, setTeamSize] = useState('') const [role, setRole] = useState('') const [submitting, setSubmitting] = useState<'continue' | 'skip' | 'dismiss' | null>(null) const [error, setError] = useState(null) const isBusy = submitting !== null const handleContinue = async (e: FormEvent) => { e.preventDefault() if (isBusy) return setError(null) setSubmitting('continue') try { await onboardingApi.updateStep({ step: 1, action: 'complete', data: { company_name: companyName.trim() || undefined, team_size_bucket: teamSize || undefined, role_at_signup: role || undefined, }, }) await fetchUser() navigate('/welcome/step-2') } catch { setError('Could not save. Please try again.') setSubmitting(null) } } const handleSkipStep = async () => { if (isBusy) return setError(null) setSubmitting('skip') try { await onboardingApi.updateStep({ step: 1, action: 'skip' }) await fetchUser() navigate('/welcome/step-2') } catch { setError('Could not save. Please try again.') setSubmitting(null) } } const handleDismissRest = async () => { if (isBusy) return setError(null) setSubmitting('dismiss') try { await onboardingApi.dismissRest() await fetchUser() navigate('/') } catch { setError('Could not save. Please try again.') setSubmitting(null) } } const inputClass = cn( 'mt-1 block w-full rounded-xl border border-border bg-card px-3 py-2', 'text-foreground placeholder:text-muted-foreground', 'focus:border-primary focus:outline-hidden focus:ring-1 focus:ring-primary/20', ) return (

Step 1 of 3

Your shop

A couple of quick questions so we can tailor ResolutionFlow to your team.

setCompanyName(e.target.value)} className={inputClass} placeholder="Acme MSP" data-testid="welcome-step-1-company-name" />
{error && (

{error}

)}
) } export default WelcomeStep1