Skip to content

Commit

Permalink
buyer dashboard phase 2 done + linting left
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinichiShi committed Sep 13, 2024
1 parent b2dd492 commit 1042d99
Show file tree
Hide file tree
Showing 40 changed files with 2,444 additions and 1,402 deletions.
5 changes: 2 additions & 3 deletions client/firebase.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

import { initializeApp } from 'firebase/app';
import { getAuth, GoogleAuthProvider} from 'firebase/auth';
import { getAuth, GoogleAuthProvider } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
import { getStorage } from 'firebase/storage';

Expand All @@ -20,4 +19,4 @@ const db = getFirestore(app);
const googleProvider = new GoogleAuthProvider();
const storage = getStorage(app);

export { auth, app, googleProvider, db, storage};
export { auth, app, googleProvider, db, storage };
2 changes: 1 addition & 1 deletion client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<!-- <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Teko:[email protected]&display=swap" rel="stylesheet"> -->
<link rel="stylesheet" href="./src/output.css">
<link rel="stylesheet" href="./src/output.css" />
</head>
<body>
<div id="root"></div>
Expand Down
6 changes: 1 addition & 5 deletions client/src/Landing.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import './App.css';
import AgriConnect from './components/LandingPage/AgriConnect';
function Landing() {
return (
<>
{<AgriConnect />},
</>
);
return <>{<AgriConnect />},</>;
}

export default Landing;
44 changes: 17 additions & 27 deletions client/src/components/Buyer/BHeader.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { FaSearch } from 'react-icons/fa';
import { MdOutlineTranslate } from 'react-icons/md';
import { IoIosArrowDropdown ,IoIosArrowDropup } from "react-icons/io";
import { IoIosArrowDropdown, IoIosArrowDropup } from 'react-icons/io';
import { useState, useEffect, useRef } from 'react';
import { signOut } from 'firebase/auth';
import { auth } from '../../../firebase'
import {useNavigate} from 'react-router-dom'
import { signOut } from 'firebase/auth';
import { auth } from '../../../firebase';
import { useNavigate } from 'react-router-dom';
import { toast, ToastContainer } from 'react-toastify';

function BHeader() {
Expand All @@ -21,16 +20,16 @@ function BHeader() {
document.addEventListener('mousedown', handleClickOutside);
return () => {
document.removeEventListener('mousedown', handleClickOutside);
};
};
}, [dropdownRef]);

const handleLogout = async () => {
console.log("enter")
console.log('enter');
try {
await signOut(auth);
console.log('hello')
toast.success("Logged Out")
navigate('/login');
console.log('hello');
toast.success('Logged Out');
navigate('/login');
} catch (error) {
toast.error('Error signing out:', error);
}
Expand All @@ -40,19 +39,7 @@ function BHeader() {
<div className="bg-white h-full shadow flex w-full">
<div className=" w-full flex justify-between items-center px-4">
<div className="text-green-500 text-2xl font-bold">AgriConnect</div>
<div className="flex-grow items-center justify-center mx-8">
<div className="flex items-center justify-center ">
<input
type="text"
placeholder="Search"
className="w-full px-4 border border-gray-300 rounded-l"
/>
<button className="px-6 py-2 bg-green-500 hover:bg-green-600 text-white rounded-r flex items-center justify-center gap-4">
<FaSearch />
Search
</button>
</div>
</div>

<div>
<div className="flex items-center justify-center gap-4">
<div ref={dropdownRef} className="relative">
Expand All @@ -64,7 +51,7 @@ function BHeader() {
Eng
{dropdownOpen ? <IoIosArrowDropdown /> : <IoIosArrowDropup />}
</div>
{dropdownOpen && (
{dropdownOpen && (
<div className="absolute left-0 mt-2 w-24 bg-white border rounded shadow-md">
<ul className="py-1">
<li className="px-4 py-2 hover:bg-slate-100 cursor-pointer">
Expand All @@ -80,16 +67,19 @@ function BHeader() {
</div>
)}
</div>
<button className="py-2 border rounded-lg flex items-center justify-center bg-green-500 hover:bg-green-600 text-white" onClick={handleLogout}>
<button
className="py-2 px-2 border rounded-lg flex items-center justify-center bg-green-500 hover:bg-green-600 text-white"
onClick={handleLogout}
>
Logout
</button>
</div>
</div>
</div>
<ToastContainer/>
<ToastContainer />
</div>
</div>
);
}

export default BHeader;
export default BHeader;
46 changes: 38 additions & 8 deletions client/src/components/Buyer/BNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,49 @@ export default function BNavbar({ handleNavigate, navigate }) {
<nav className="bg-white border-t">
<div className=" mx-auto flex justify-between items-center px-4 py-3">
<ul className="flex space-x-5">
<li className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'deals' ? "bg-green-300" : ""} hover:bg-green-200`} onClick={() => handleNavigate('deals')}>Deals</li>
<li className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'contract' ? "bg-green-300" : ""} hover:bg-green-200`} onClick={() => handleNavigate('contract')}>Contracts</li>
<li className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'transactions' ? "bg-green-300" : ""} hover:bg-green-200`} onClick={() => handleNavigate('transactions')}>Transactions</li>
<li className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'notifications' ? "bg-green-300" : ""} hover:bg-green-200`} onClick={() => handleNavigate('notifications')}>Notifications</li>
<li className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'settings' ? "bg-green-300" : ""} hover:bg-green-200`} onClick={() => handleNavigate('settings')}>Settings</li>
<li className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'faqs' ? "bg-green-300" : ""} hover:bg-green-200`} onClick={() => handleNavigate('faqs')}>FAQs</li>
<li
className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'deals' ? 'bg-green-300' : ''} hover:bg-green-200`}
onClick={() => handleNavigate('deals')}
>
Deals
</li>
<li
className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'contract' ? 'bg-green-300' : ''} hover:bg-green-200`}
onClick={() => handleNavigate('contract')}
>
Contracts
</li>
<li
className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'transactions' ? 'bg-green-300' : ''} hover:bg-green-200`}
onClick={() => handleNavigate('transactions')}
>
Transactions
</li>
<li
className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'notifications' ? 'bg-green-300' : ''} hover:bg-green-200`}
onClick={() => handleNavigate('notifications')}
>
Notifications
</li>
<li
className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'settings' ? 'bg-green-300' : ''} hover:bg-green-200`}
onClick={() => handleNavigate('settings')}
>
Settings
</li>
<li
className={`cursor-pointer py-1 px-2 rounded-lg ${navigate === 'chat' ? 'bg-green-300' : ''} hover:bg-green-200`}
onClick={() => handleNavigate('chats')}
>
Chats
</li>
</ul>
</div>
</nav>
);
}

BNavbar.propTypes = {
handleNavigate: PropTypes.func.isRequired,
navigate: PropTypes.string.isRequired,
handleNavigate: PropTypes.func.isRequired,
navigate: PropTypes.string.isRequired,
};
60 changes: 6 additions & 54 deletions client/src/components/Buyer/Contract/BContract.jsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,8 @@
import { useContext, useEffect, useState } from 'react';
import { AuthContext } from '../../context/AuthContext';
import { db } from '../../../../firebase';
import { getDoc, doc } from 'firebase/firestore';
import ContractStatus from './ContractStatus';
import GenerateContract from './GenerateContract'
import { useState } from 'react';
import GenerateContract from './GenerateContract';
import ContractList from './ContractList';
export default function BContract() {
const { currentUser } = useContext(AuthContext);
const [contracts, setContracts] = useState([]); // Initialize state to store contracts
const [choice, setChoice] = useState('generate');

useEffect(() => {
const fetchDetails = async () => {
if (currentUser) {
const buyerRef = doc(db, 'buyers', currentUser.uid);
const docSnap = await getDoc(buyerRef);

if (docSnap.exists()) {
const data = docSnap.data();
const contractsData = data.contracts
? Object.values(data.contracts)
: []; // Convert map to array
setContracts(contractsData); // Update state with contracts
}
}
};

fetchDetails(); // Fetch details on component mount
}, [currentUser]);

return (
<div className="w-full flex self-start gap-4 p-4">
<div className="w-1/5 bg-white rounded-4 shadow p-4">
Expand All @@ -50,32 +25,9 @@ export default function BContract() {
</div>
</div>
</div>

{choice==='generate' && (<GenerateContract />)}
{choice === 'status' && (
<div className="w-3/4 p-4 h-full shadow rounded-4 flex flex-col self-start items-start justify-start gap-2">
<div className="font-bold text-xl self-start mb-2">
Contract History :
</div>
<div className="w-full h-8 bg-slate-400 flex flex-row items-center justify-between px-4">
<div className="flex-1 text-center">Date</div>
<div className="flex-1 text-center">Total</div>
<div className="flex-1 text-center">Status</div>
<div className="flex-1 text-center">Details</div>
</div>
<div className="w-full flex flex-col items-start justify-start mt-2">
{contracts.length > 0 ? (
contracts.map((contract, index) => (
<ContractStatus key={index} contract={contract} />
))
) : (
<p className="flex-1 w-full flex text-center">
No contracts found
</p>
)}
</div>
</div>
)}

{choice === 'generate' && <GenerateContract />}
{choice === 'status' && <ContractList />}
</div>
);
}
Loading

0 comments on commit 1042d99

Please sign in to comment.