From 21a21303f83b8fcb3a7bac9401aa145bf405e620 Mon Sep 17 00:00:00 2001 From: Atharva Date: Sun, 23 Feb 2025 02:54:27 +0530 Subject: [PATCH] Fix:Added Padding the select --- .../src/pages/UserPanel/Farm/CropsList.jsx | 298 ++++++++++++++---- 1 file changed, 240 insertions(+), 58 deletions(-) diff --git a/Frontend/src/pages/UserPanel/Farm/CropsList.jsx b/Frontend/src/pages/UserPanel/Farm/CropsList.jsx index b5ca7c2..ecaff84 100644 --- a/Frontend/src/pages/UserPanel/Farm/CropsList.jsx +++ b/Frontend/src/pages/UserPanel/Farm/CropsList.jsx @@ -1,61 +1,243 @@ -const CropsList = ({ farmData }) => { - return ( -
-

{farmData.name}

+import React, { useState } from "react"; - - - - - - - - - - - - - - {/* Clicking on the name cell can navigate to a more detailed view if needed */} - - - - - - - - -
- Farm Name - - Location - - Type - - Size (acres) - - Water Content - - Action -
{ - // Navigate to a detailed view for this farm if desired - navigate(`farmpage/${farmData._id}`); - }} - > - {farmData.name} - {farmData.location}{farmData.soilType}{farmData.size}{farmData.waterContent} - -
-
+const AddCrop = ({ farmId }) => { + const [isModalOpen, setIsModalOpen] = useState(false); + const [name, setName] = useState(""); + const [farm, setFarm] = useState(farmId); + const [harvestDate, setHarvestDate] = useState(""); + const [growthStage, setGrowthStage] = useState("Planted"); + const [healthStatus, setHealthStatus] = useState(""); + const [image, setImage] = useState(null); + const [uploading, setUploading] = useState(false); + const [error, setError] = useState(""); + const [success, setSuccess] = useState(""); + + const handleSubmit = async (e) => { + e.preventDefault(); + setUploading(true); + setError(""); + setSuccess(""); + + const formData = new FormData(); + formData.append("name", name); + formData.append("farm", farm); + formData.append("harvestDate", harvestDate); + formData.append("growthStage", growthStage); + formData.append("healthStatus", healthStatus); + if (image) { + formData.append("image", image); + } + + try { + const response = await fetch(`http://localhost:8000/api/v1/crop`, { + method: "POST", + credentials: "include", + body: formData, + }); + if (!response.ok) { + throw new Error("Failed to create crop"); + } + setSuccess("Crop created successfully!"); + setName(""); + setFarm(""); + setHarvestDate(""); + setGrowthStage(""); + setHealthStatus(""); + setImage(null); + } catch (err) { + setError(err.message); + } finally { + setUploading(false); + } + }; + + return ( + <> + + + {isModalOpen && ( +
+
setIsModalOpen(false)} + >
+
+
+ {/* Decorative SVG Elements - Moved further right */} +
+ + + + + + + + + + + + +
+ + {/* Modal Header */} +
+

+ Add New Crop +

+ +
+ + {/* Modal Body */} +
+
+
+ + setName(e.target.value)} + placeholder="Rice" + className="block w-full px-4 py-3 rounded-lg border border-gray-300 shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" + required + /> +
+ +
+ + setHarvestDate(e.target.value)} + className="block w-full px-4 py-3 rounded-lg border border-gray-300 shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" + required + /> +
+ +
+ + +
+ +
+ + setHealthStatus(e.target.value)} + placeholder="Healthy" + className="block w-full px-4 py-3 rounded-lg border border-gray-300 shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" + required + /> +
+ +
+ + setImage(e.target.files[0])} + className="block w-full px-4 py-3 rounded-lg border border-gray-300 shadow-sm focus:ring-2 focus:ring-blue-500 focus:border-blue-500" + required + /> +
+ +
+ +
+ + {error &&

{error}

} + {success &&

{success}

} +
+
+
+
+
+ )} + ); }; -export default CropsList; + +export default AddCrop;