import React, { useState } from 'react'; import { ChevronLeft, ChevronRight } from 'lucide-react'; import { toast } from 'sonner'; import { api } from '@/api'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/card'; export default function OnboardingWizard({ onComplete }) { const [step, setStep] = useState(0); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); const [confirm, setConfirm] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleCreate = async (e) => { e.preventDefault(); setError(''); let validationError = ''; if (password !== confirm) { validationError = 'Passwords do not match.'; } else if (password.length < 8) { validationError = 'Password must be at least 8 characters.'; } if (validationError) { setError(validationError); toast.error(validationError); return; } setLoading(true); try { await api.createUser({ username, password }); toast.success('User created successfully.'); onComplete(); } catch (err) { const errorMessage = err.message || 'Failed to create user.'; setError(errorMessage); toast.error(errorMessage); } finally { setLoading(false); } }; return (
{[0, 1].map(i => ( ))}
{step === 0 && ( Welcome, Administrator

Before creating your first user, please understand what your admin account can and cannot do.

{[ { can: true, text: 'Create and manage user accounts' }, { can: true, text: 'Reset user passwords' }, { can: true, text: 'Configure email notifications' }, { can: true, text: 'Toggle single-user / multi-user mode' }, { can: false, text: 'Cannot view bills or financial data' }, { can: false, text: 'Cannot access user settings or history' }, ].map(({ can, text }) => (
{can ? '✓' : '✗'} {text}
))}
)} {step === 1 && ( Create first user

This account will be used to access the bill tracker.

setUsername(e.target.value)} required />
setPassword(e.target.value)} required />
setConfirm(e.target.value)} required />
{error && (
{error}
)}
)}
); }