Skip to content

Commit

Permalink
sm more files
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinichiShi committed Sep 13, 2024
1 parent 1042d99 commit 5b77ff5
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 371 deletions.
70 changes: 70 additions & 0 deletions client/src/components/Buyer/Contract/ContractList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { useContext, useEffect, useState } from 'react';
import { AuthContext } from '../../context/Authcontext';
import { db } from '../../../../firebase';
import { doc, getDoc } from 'firebase/firestore';
import ContractStatus from './ContractStatus';

const ContractList = () => {
const [contracts, setContracts] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const { currentUser } = useContext(AuthContext);

useEffect(() => {
const fetchContracts = async () => {
if (!currentUser) {
setError('User not authenticated');
setLoading(false);
return;
}

try {
const buyerRef = doc(db, 'buyers', currentUser.uid);
const docSnap = await getDoc(buyerRef);

if (docSnap.exists()) {
const contractsData = docSnap.data().contracts || [];
setContracts(contractsData);
} else {
setError('No buyer profile found');
}
} catch (err) {
console.error('Error fetching contracts:', err);
setError('Failed to fetch contracts');
} finally {
setLoading(false);
}
};

fetchContracts();
}, [currentUser]);

if (loading) {
return <div className="text-center py-4">Loading contracts...</div>;
}

if (error) {
return <div className="text-center py-4 text-red-500">{error}</div>;
}

return (
<div className="w-full p-4 h-full shadow rounded-4 flex flex-col self-start items-start justify-start gap-2">
<div className="font-bold w-full text-xl flex self-start mb-2">
Your Contracts
</div>
{contracts.length === 0 ? (
<p>No contracts found.</p>
) : (
<div className="w-full flex gap-1 flex-col">
{contracts
.sort((a, b) => b.contractId - a.contractId) // Sort contracts by contractId in decreasing order
.map((contract) => (
<ContractStatus key={contract.contractId} contract={contract} />
))}
</div>
)}
</div>
);
};

export default ContractList;
69 changes: 0 additions & 69 deletions client/src/components/Farmer/FarmSell.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ function Box({ crop }) {
<label>
<input type="radio" name="crop" value={crop.name} />
{' ' + crop.name}
{' ' + crop.name}
</label>
</div>
</div>
Expand All @@ -27,11 +26,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
<div className={styles['details-box']}>
<div className={styles['image-box']}>
{crops.map((crop, index) => (
<div
key={index}
className={styles['box-crop']}
onClick={() => setSelectedCrop(crop)}
>
<div
key={index}
className={styles['box-crop']}
Expand All @@ -47,13 +41,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
onChange={() => setSelectedCrop(crop)}
/>
{' ' + crop.name}
<input
type="radio"
name="crop"
value={crop.name}
onChange={() => setSelectedCrop(crop)}
/>
{' ' + crop.name}
</label>
</div>
</div>
Expand Down Expand Up @@ -114,14 +101,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
onChange={handleInputChange}
required
/>
<input
type="text"
id="items"
name="items"
placeholder="Enter items"
onChange={handleInputChange}
required
/>
</div>

<div className={styles['form-group']}>
Expand All @@ -134,14 +113,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
onChange={handleInputChange}
required
/>
<input
type="text"
id="location"
name="location"
placeholder="Enter location"
onChange={handleInputChange}
required
/>
</div>

<div className={styles['form-group']}>
Expand All @@ -154,14 +125,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
onChange={handleInputChange}
required
/>
<input
type="text"
id="district"
name="district"
placeholder="Enter district"
onChange={handleInputChange}
required
/>
</div>

<div className={styles['form-group']}>
Expand All @@ -174,14 +137,6 @@ function Details({ crops, setSelectedCrop, handleInputChange }) {
onChange={handleInputChange}
required
/>
<input
type="text"
id="state"
name="state"
placeholder="Enter state"
onChange={handleInputChange}
required
/>
</div>

<div className={styles['form-group']}>
Expand Down Expand Up @@ -218,27 +173,6 @@ function Search({ searchQuery, setSearchQuery, handleSearch }) {
onChange={(e) => setSearchQuery(e.target.value)}
/>
<button onClick={handleSearch}>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
width={24}
height={24}
color={'#000000'}
fill={'none'}
>
<path
d="M17.5 17.5L22 22"
stroke="currentColor"
strokeWidth="1.5"
strokeLinecap="round"
strokeLinejoin="round"
/>
<path
d="M20 11C20 6.02944 15.9706 2 11 2C6.02944 2 2 6.02944 2 11C2 15.9706 6.02944 20 11 20C15.9706 20 20 15.9706 20 11Z"
stroke="currentColor"
strokeWidth="1.5"
strokeLinejoin="round"
/>
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
Expand Down Expand Up @@ -281,7 +215,6 @@ function FarmSell() {
district: '',
state: '',
pincode: '',
pincode: '',
});

const { currentUser } = useAuth(); // Get the current user from AuthContext
Expand All @@ -290,8 +223,6 @@ 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())
);
Expand Down
Loading

0 comments on commit 5b77ff5

Please sign in to comment.