'use client'; import { useState } from 'react'; import { Box, Stepper, Step, StepLabel, Button, Typography, Paper, TextField, Avatar, IconButton, Alert, CircularProgress, MenuItem, Card, CardActionArea, CardContent, Radio, RadioGroup, FormControlLabel, FormControl, Grid, } from '@mui/material'; import { ArrowBack, ArrowForward, Check, Language, Straighten } from '@mui/icons-material'; import { motion, AnimatePresence } from 'framer-motion'; import { useRouter } from 'next/navigation'; import { useAuth } from '@/lib/auth/AuthContext'; import { childrenApi } from '@/lib/api/children'; import { useLocale, MeasurementSystem } from '@/hooks/useLocale'; import { useTranslation } from '@/hooks/useTranslation'; import { supportedLanguages } from '@/lib/i18n/config'; import { usersApi } from '@/lib/api/users'; const steps = ['Welcome', 'Language', 'Measurements', 'Add Child', 'Complete']; export default function OnboardingPage() { const [activeStep, setActiveStep] = useState(0); const [childName, setChildName] = useState(''); const [childBirthDate, setChildBirthDate] = useState(''); const [childGender, setChildGender] = useState<'male' | 'female' | 'other'>('other'); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const router = useRouter(); const { user } = useAuth(); const handleNext = async () => { // Validate and save child data on step 1 (Add Child) if (activeStep === 1) { if (!childName.trim() || !childBirthDate) { setError('Please enter child name and birth date'); return; } const familyId = user?.families?.[0]?.familyId; if (!familyId) { setError('No family found. Please try logging out and back in.'); return; } try { setLoading(true); setError(''); await childrenApi.createChild(familyId, { name: childName.trim(), birthDate: childBirthDate, gender: childGender, }); setActiveStep((prevActiveStep) => prevActiveStep + 1); } catch (err: any) { console.error('Failed to create child:', err); setError(err.response?.data?.message || 'Failed to save child. Please try again.'); } finally { setLoading(false); } return; } if (activeStep === steps.length - 1) { // Complete onboarding router.push('/'); } else { setActiveStep((prevActiveStep) => prevActiveStep + 1); } }; const handleBack = () => { setActiveStep((prevActiveStep) => prevActiveStep - 1); }; const handleSkip = () => { router.push('/'); }; return ( {steps.map((label) => ( {label} ))} {activeStep === 0 && ( Welcome to Maternal! 🎉 We're excited to help you track and understand your child's development, sleep patterns, feeding schedules, and more. 📊 Track Activities 🤖 AI Insights 👨‍👩‍👧 Family Sharing )} {activeStep === 1 && ( Add Your First Child Let's start by adding some basic information about your child. {error && ( {error} )} setChildName(e.target.value)} margin="normal" required disabled={loading} InputProps={{ sx: { borderRadius: 3 }, }} /> setChildBirthDate(e.target.value)} margin="normal" required disabled={loading} InputLabelProps={{ shrink: true, }} InputProps={{ sx: { borderRadius: 3 }, }} /> setChildGender(e.target.value as 'male' | 'female' | 'other')} margin="normal" disabled={loading} InputProps={{ sx: { borderRadius: 3 }, }} > Male Female Prefer not to say You can add more children and details later from settings. )} {activeStep === 2 && ( Invite Family Members Share your child's progress with family members. They can view activities and add their own entries. You can skip this step and invite family members later. )} {activeStep === 3 && ( You're All Set! 🎉 Start tracking your child's activities and get personalized insights. Next Steps: • Track your first feeding, sleep, or diaper change
• Chat with our AI assistant for parenting tips
• Explore insights and predictions based on your data
)}
{activeStep < steps.length - 1 && activeStep > 0 && ( )}
); }