"use client"; import { useState } from "react"; import PlantingDetailsForm from "./planting-detail-form"; import HarvestDetailsForm from "./harvest-detail-form"; import GoogleMapWithDrawing from "@/components/google-map-with-drawing"; import { Separator } from "@/components/ui/separator"; import { plantingDetailsFormSchema, harvestDetailsFormSchema, } from "@/schemas/application.schema"; import { z } from "zod"; import { Button } from "@/components/ui/button"; import { toast } from "sonner"; type PlantingSchema = z.infer; type HarvestSchema = z.infer; const steps = [ { title: "Step 1", description: "Planting Details" }, { title: "Step 2", description: "Harvest Details" }, { title: "Step 3", description: "Select Map Area" }, ]; export default function SetupPage() { const [step, setStep] = useState(1); const [plantingDetails, setPlantingDetails] = useState( null ); const [harvestDetails, setHarvestDetails] = useState( null ); const [mapData, setMapData] = useState<{ lat: number; lng: number }[] | null>( null ); const handleNext = () => { if (step === 1 && !plantingDetails) { toast.warning( "Please complete the Planting Details before proceeding.", { action: { label: "Close", onClick: () => toast.dismiss(), }, } ); return; } if (step === 2 && !harvestDetails) { toast.warning( "Please complete the Harvest Details before proceeding.", { action: { label: "Close", onClick: () => toast.dismiss(), }, } ); return; } setStep((prev) => prev + 1); }; const handleBack = () => { setStep((prev) => prev - 1); }; const handleSubmit = () => { if (!mapData) { toast.warning("Please select an area on the map before submitting.", { action: { label: "Close", onClick: () => toast.dismiss(), }, }); return; } console.log("Submitting:", { plantingDetails, harvestDetails, mapData }); // send request to the server }; return (
{/* Stepper Navigation */}
{steps.map((item, index) => (
{index + 1}
{item.title} {item.description}
))}
{step === 1 && ( <>

Planting Details

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

Harvest Details

)} {step === 3 && ( <>

Select Area on Map

)}
{step < 3 ? ( ) : ( )}
); }