diff --git a/Frontend/src/pages/UserPanel/Farm/CropTable.jsx b/Frontend/src/pages/UserPanel/Farm/CropTable.jsx new file mode 100644 index 0000000..a9fc8f8 --- /dev/null +++ b/Frontend/src/pages/UserPanel/Farm/CropTable.jsx @@ -0,0 +1,152 @@ +import React, { useState, useEffect } from "react"; + +const CropTable = ({ farmId }) => { + const [crops, setCrops] = useState([]); + const [loading, setLoading] = useState(true); + const [error, setError] = useState(null); + useEffect(() => { + const fetchCrops = async () => { + try { + const response = await fetch( + `http://localhost:8000/api/v1/crop/farm/${farmId}`, + { + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + } + ); + + if (!response.ok) { + throw new Error("Failed to fetch crops"); + } + + const data = await response.json(); + setCrops(data || []); + } catch (err) { + setError(err.message); + } finally { + setLoading(false); + } + }; + + fetchCrops(); + }, [farmId]); + + if (loading) { + return ( +
Error: {error}
++ Start by adding some crops to your farm +
+| + Image + | ++ Name + | ++ Growth Stage + | ++ Health Status + | ++ Harvest Date + | +
|---|---|---|---|---|
|
+
+ {crop.image ? (
+
+
+ No image
+
+ )}
+ |
+
+
+ {crop.name}
+
+ |
+ + + {crop.growthStage} + + | +
+
+ {crop.healthStatus}
+
+ |
+
+
+ {new Date(crop.harvestDate).toLocaleDateString()}
+
+ |
+