"use client"; import { SetStateAction, useEffect, useState } from "react"; import PlantingDetailsForm from "./planting-detail-form"; import HarvestDetailsForm from "./harvest-detail-form"; import { Separator } from "@/components/ui/separator"; import GoogleMapWithDrawing from "@/components/google-map-with-drawing"; import { plantingDetailsFormSchema, harvestDetailsFormSchema, } from "@/schemas/application.schema"; import { z } from "zod"; type plantingSchema = z.infer; type harvestSchema = z.infer; export default function SetupPage() { const [plantingDetails, setPlantingDetails] = useState( null ); const [harvestDetails, setHarvestDetails] = useState( null ); const [mapData, setMapData] = useState(null); // handle planting details submission const handlePlantingDetailsChange = (data: plantingSchema) => { setPlantingDetails(data); }; // handle harvest details submission const handleHarvestDetailsChange = (data: harvestSchema) => { setHarvestDetails(data); }; // handle map area selection const handleMapDataChange = (data: SetStateAction) => { setMapData(data); }; // log the changes useEffect(() => { console.log(plantingDetails); console.log(harvestDetails); }, [plantingDetails, harvestDetails]); const handleSubmit = () => { if (!plantingDetails || !harvestDetails || !mapData) { alert("Please complete all sections before submitting."); return; } const formData = { plantingDetails, harvestDetails, mapData, }; console.log("Form data to be submitted:", formData); fetch("/api/submit", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify(formData), }) .then((response) => response.json()) .then((data) => { console.log("Response from backend:", data); }) .catch((error) => { console.error("Error submitting form:", error); }); }; return (
{/* Planting Details Section */}

Planting Details

{/* Harvest Details Section */}

Harvest Details

{/* Map Section */}

Map

{/* */}
{/* Submit Button */}
); }