"use client"; import { AnimatePresence, motion } from "framer-motion"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { AddDataSource } from "@/components/pipeline/add-data-source"; import { PipelineAiAssistant } from "@/components/pipeline/ai-assistant"; import { PipelineDetails } from "@/components/pipeline/details"; import { ScheduleAndInformation } from "@/components/pipeline/schedule-and-information"; import { PipelineSummary } from "@/components/pipeline/summary"; import { Button } from "@/components/ui/button"; import { Card, CardContent } from "@/components/ui/card"; import { Form } from "@/components/ui/form"; import { cn } from "@/lib/utils"; import { pipelineSchema, PipelineFormValues } from "@/lib/validations/pipeline"; import { zodResolver } from "@hookform/resolvers/zod"; const TOTAL_STEPS = 5; const stepComponents = [ , , , , , , ]; const motionVariants = { enter: { opacity: 0, x: 50 }, center: { opacity: 1, x: 0 }, exit: { opacity: 0, x: -50 }, }; export default function CratePipelineForm() { const [step, setStep] = useState(0); const isFirstStep = step === 0; const isLastStep = step === TOTAL_STEPS - 1; const form = useForm({ resolver: zodResolver(pipelineSchema), }); const { handleSubmit, reset } = form; const onSubmit = async (formData: unknown) => { if (!isLastStep) return setStep((s) => s + 1); console.log(formData); reset(); setStep(0); toast.success("Form successfully submitted"); }; const handleBack = () => setStep((s) => (s > 0 ? s - 1 : s)); const StepForm = ( {stepComponents[step]} Back {isLastStep ? "Create Pipeline" : "Next"} ); return ( {/* stepper */} {Array.from({ length: TOTAL_STEPS }).map((_, index) => ( {index < TOTAL_STEPS - 1 && ( )} ))} {/* animated form */} {StepForm} ); }