diff --git a/client/src/components/Farmer/FDashboard.jsx b/client/src/components/Farmer/FDashboard.jsx index 4e57597..0a73955 100644 --- a/client/src/components/Farmer/FDashboard.jsx +++ b/client/src/components/Farmer/FDashboard.jsx @@ -42,19 +42,19 @@ function Box({ data, showSecondaryBox }) { return (
-

Name: {data.name}

-

Crop: {data.crop}

-

Quantity required: {data.quantity}

-

Mobile No: {data.mobile}

-

State: {data.state}

+

Name: {data.profile?.displayName || 'N/A'} {data.profile?.lname || ''}

+

Contact Name: {data.displayName || 'N/A'}

+

Phone: {data.profile?.phone || 'N/A'}

+

State: {data.address?.state || 'N/A'}

- ) + ); } + function Secondarybox({ data, hideSecondaryBox }) { return (
@@ -63,25 +63,26 @@ function Secondarybox({ data, hideSecondaryBox }) {
-

Name: {data.name}

-

Crop: {data.crop}

-

Quantity: {data.quantity}

-

Language Known: {data.languages}

-

Mobile: {data.mobile}

-

E-mail: {data.email}

-

Address: {data.address}

-

City: {data.city}

-

District: {data.district}

-

State: {data.state}

-

Pincode: {data.pincode}

-
-
- +

Name : {data.profile?.displayName || 'N/A'} {data.profile?.lname || ''}

+

Company Name : {data.address?.companyName || 'N/A'}

+

Phone : {data.profile?.phone || 'N/A'}

+

Email : {data.profile?.email || 'N/A'}

+

Address 1 : {data.address?.addr1}

+

Address 2 : {data.address?.addr2}

+

State : {data.address?.state}

+

Country : {data.address?.country}

+

Bank: {data.bank?.bank_name || 'N/A'}

+ + {/*

IFSC Code: {data.ifsc || 'N/A'}

+

Branch: {data.branch_name || 'N/A'}

+

Bank: {data.bank_name || 'N/A'}

+

Signature: Signature

*/}
- ) + ); } + function MainBox() { const [showBox, setShowBox] = useState(false); const [selectedData, setSelectedData] = useState(null); @@ -89,13 +90,18 @@ function MainBox() { useEffect(() => { const fetchDealers = async () => { - const dealersCollection = collection(db, ''); // enter ur collection name inside the quotes' - const dealersSnapshot = await getDocs(farmerdataCollection);//here too - const dealersList = dealersSnapshot.docs.map(doc => doc.data()); - setDealers(dealersList); + try { + // Reference to the 'buyers' collection in Firestore + const dealersCollection = collection(db, 'buyers'); + const dealersSnapshot = await getDocs(dealersCollection); + const dealersList = dealersSnapshot.docs.map(doc => doc.data()); + setDealers(dealersList); // Store fetched data in state + } catch (error) { + console.error("Error fetching buyers data: ", error); + } }; - fetchDealers(); + fetchDealers(); // Fetch the data when the component mounts }, []); const showSecondaryBox = (data) => { @@ -103,7 +109,6 @@ function MainBox() { setShowBox(true); }; - const hideSecondaryBox = () => setShowBox(false); return ( @@ -120,7 +125,7 @@ function MainBox() { )} - ) + ); } function FDashboard() { diff --git a/client/src/components/Farmer/FarmSell.jsx b/client/src/components/Farmer/FarmSell.jsx index b59c86d..dab0b2f 100644 --- a/client/src/components/Farmer/FarmSell.jsx +++ b/client/src/components/Farmer/FarmSell.jsx @@ -1,80 +1,11 @@ import styles from './FarmSell.module.css'; import cropData from './cropsData.json'; import { useState } from 'react'; -import { collection,addDoc } from 'firebase/firestore'; +import { collection, addDoc, doc,setDoc} from 'firebase/firestore'; import { db } from '../../../firebase'; import { useAuth } from '../context/AuthContext'; import Navbar from './FarmNav'; -// function Searchsvg() { -// return ( -// -// -// -// -// ); -// } - -// function ProfileIcon() { -// return ( -//
-// -// -// -// -//
Profile▾
-//
-// ); -// } - -// function Searchsvg() { -// return ( -// -// -// -// -// ); -// } - -// function ProfileIcon() { -// return ( -//
-// -// -// -// -//
Profile▾
-//
-// ); -// } - -// function Navbar() { -// return ( -//
-//
-//
-//

Agri

-//

Connect

-//
-//
-// -// -// Search -//
-// -//
-//
-// -//
-//
-// ); -// } - function Box({ crop }) { return (
@@ -82,7 +13,7 @@ function Box({ crop }) {
@@ -94,12 +25,21 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
{crops.map((crop, index) => ( -
setSelectedCrop(crop)}> +
setSelectedCrop(crop)} + > {crop.name}
@@ -110,42 +50,98 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
- +
- +
- +
- +
- +
- +
- +
- +
@@ -153,7 +149,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) { ); } - function Search({ searchQuery, setSearchQuery, handleSearch }) { return (
@@ -169,9 +164,27 @@ function Search({ searchQuery, setSearchQuery, handleSearch }) { onChange={(e) => setSearchQuery(e.target.value)} />
@@ -193,7 +206,7 @@ function FarmSell() { location: '', district: '', state: '', - pincode: '' + pincode: '', }); const { currentUser } = useAuth(); // Get the current user from AuthContext @@ -202,8 +215,8 @@ function FarmSell() { const filtered = cropData.crops.filter((crop) => crop.name.toLowerCase().includes(searchQuery.toLowerCase()) ); - const rest = cropData.crops.filter((crop) => - !crop.name.toLowerCase().includes(searchQuery.toLowerCase()) + const rest = cropData.crops.filter( + (crop) => !crop.name.toLowerCase().includes(searchQuery.toLowerCase()) ); setFilteredCrops([...filtered, ...rest]); }; @@ -212,37 +225,69 @@ function FarmSell() { setFormData({ ...formData, [e.target.name]: e.target.value }); }; + + const submitDetails = async () => { + // Check if the user is logged in if (!currentUser) { alert('No user is logged in. Please log in to submit details.'); return; } - + + // Ensure a crop is selected if (!selectedCrop) { alert('Please select a crop.'); return; } - - const dataToSubmit = { + + // Structure the data to be submitted as part of a map + const cropData = { cropName: selectedCrop.name, - ...formData, + quantity: formData.quantity, + price: formData.price, + landArea: formData.landArea, + items: formData.items, + location: formData.location, + district: formData.district, + state: formData.state, + pincode: formData.pincode, }; - + try { - const docRef = await addDoc(collection(db, 'farmers', currentUser.uid, 'cropProduce'), dataToSubmit); + // Reference to the farmer's document + const farmerDocRef = doc(db, 'farmers', currentUser.uid); + + // Use setDoc to update the farmer's document by merging cropProduce as a map + await setDoc( + farmerDocRef, + { + cropProduce: cropData, // Use the crop name as a key and store the data + + }, + { merge: true } // Merge to avoid overwriting existing data + ); + alert('Details submitted successfully!'); - console.log('Document written with ID: ', docRef.id); } catch (e) { console.error('Error adding document: ', e); alert('Failed to submit details. Please try again.'); } }; + return ( <> - -
+ +