import { useState } from 'react'; import { useForm } from 'react-hook-form'; import { zodResolver } from '@hookform/resolvers/zod'; import { z } from 'zod'; import { useOnboarding } from '@/hooks/useDashboard'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { useNavigate } from '@tanstack/react-router'; const onboardingSchema = z.object({ businessName: z.string().min(2, 'Business name must be at least 2 characters'), industry: z.string().min(2, 'Industry is required'), website: z.string().url().optional().or(z.literal('')), }); type OnboardingFormData = z.infer; export function OnboardingPage() { const [step, setStep] = useState(1); const [selectedGoals, setSelectedGoals] = useState([]); const [selectedServices, setSelectedServices] = useState([]); const navigate = useNavigate(); const { mutate: submitOnboarding, isPending } = useOnboarding(); const { register, handleSubmit, formState: { errors }, } = useForm({ resolver: zodResolver(onboardingSchema), }); const goals = [ 'Increase website traffic', 'Improve SEO ranking', 'Generate more leads', 'Manage online reputation', 'Grow social media presence', 'Streamline bookings', ]; const services = [ 'Website Creation', 'SEO Tracking', 'Online Booking', 'Social Media Content', 'Review Management', 'Customer Feedback', ]; const toggleSelection = (item: string, list: string[], setter: (val: string[]) => void) => { if (list.includes(item)) { setter(list.filter((i) => i !== item)); } else { setter([...list, item]); } }; const onSubmit = (data: OnboardingFormData) => { submitOnboarding( { ...data, goals: selectedGoals, services: selectedServices, }, { onSuccess: () => { navigate({ to: '/dashboard' }); }, } ); }; return (
Welcome to Nitrokite! 🚀 Let's get your business set up in just a few steps
{[1, 2, 3].map((s) => (
))}
{step === 1 && (
setStep(2))} className="space-y-4">
{errors.businessName && (

{errors.businessName.message}

)}
{errors.industry && (

{errors.industry.message}

)}
{errors.website && (

{errors.website.message}

)}
)} {step === 2 && (

What are your goals?

{goals.map((goal) => ( ))}
)} {step === 3 && (

Which services are you interested in?

{services.map((service) => ( ))}
)}
); }