Skip to content

Commit

Permalink
added blockchain and many things...codebase is distorted :|
Browse files Browse the repository at this point in the history
  • Loading branch information
ShinichiShi committed Sep 5, 2024
1 parent 428f7f0 commit 71cf83b
Show file tree
Hide file tree
Showing 28 changed files with 23,488 additions and 125 deletions.
1,498 changes: 1,483 additions & 15 deletions client/package-lock.json

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@
"format:check": "prettier --check ."
},
"dependencies": {
"@metamask/detect-provider": "^2.0.0",
"@react-pdf/renderer": "^3.4.4",
"@shadcn/ui": "^0.0.4",
"bootstrap": "^5.3.3",
"dotenv": "^16.4.5",
"ethers": "^6.13.2",
"express": "^4.19.2",
"firebase": "^10.13.0",
"jspdf": "^2.5.1",
"prop-types": "^15.8.1",
"react": "^18.3.1",
"react-bootstrap": "^2.10.4",
"react-dom": "^18.3.1",
"react-hook-form": "^7.53.0",
"react-icons": "^5.3.0",
"react-phone-number-input": "^3.4.5",
"react-router-dom": "^6.26.1",
Expand Down
14 changes: 6 additions & 8 deletions client/src/components/Buyer/BDashboard.jsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
import { useState,useContext, useEffect} from 'react';
import { useState, useContext, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import BHeader from './BHeader';
import BNavbar from './BNavbar';
import BSettings from './Settings/BSettings';
import BDeals from './Deals/BDeals';
import BContract from './Contract/BContract';
import { AuthContext } from '../context/Authcontext';
import { AuthContext } from '../context/AuthContext';
function Dashboard() {
const navigateRoute = useNavigate();
const [navigate, setNavigate] = useState('settings');
const { currentUser } = useContext(AuthContext);


useEffect(() => {
if (currentUser === null) {
navigateRoute('/signup');
}
}, [currentUser, navigateRoute]);
}
}, [currentUser, navigateRoute]);

const handleNavigate = (key) => {
setNavigate(key);
};
return (
<>
<BHeader />
<BNavbar handleNavigate={handleNavigate} navigate={navigate} />
<BHeader />
<BNavbar handleNavigate={handleNavigate} navigate={navigate} />

{navigate === 'settings' && <BSettings />}
{navigate === 'deals' && <BDeals />}
{navigate === 'contract' && <BContract />}

</>
);
}
Expand Down
4 changes: 2 additions & 2 deletions client/src/components/Buyer/BHeader.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function BHeader() {
}
};
return (
<header className="h-20 font-sans">
<div className="h-20 font-sans">
<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>
Expand Down Expand Up @@ -88,7 +88,7 @@ function BHeader() {
</div>
<ToastContainer/>
</div>
</header>
</div>
);
}

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/Buyer/BNavbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default function BNavbar({ handleNavigate, navigate }) {
<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')}>Contract Status</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>
Expand Down
70 changes: 50 additions & 20 deletions client/src/components/Buyer/Contract/BContract.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { useContext, useEffect, useState } from 'react';
import { AuthContext } from '../../context/Authcontext';
import { AuthContext } from '../../context/AuthContext';
import { db } from '../../../../firebase';
import { getDoc, doc } from 'firebase/firestore';
import ContractStatus from './ContractStatus';
import GenerateContract from './GenerateContract'
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 () => {
Expand All @@ -27,25 +29,53 @@ export default function BContract() {
}, [currentUser]);

return (
<div className="w-full h-[100vh] flex self-start justify-center">
<div className="w-3/4 p-4 h-full shadow 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 className="w-full flex self-start gap-4 p-4">
<div className="w-1/5 bg-white rounded-4 shadow p-4">
<div className="space-y-4 flex flex-col self-start items-start">
<div
className={`p-3 text-gray-700 rounded-lg flex items-center cursor-pointer space-x-2 ${choice === 'generate' ? 'bg-green-200 font-bold' : ''}`}
onClick={() => {
setChoice('generate');
}}
>
<span>Generate Contract</span>
</div>
<div
className={`p-3 text-gray-700 rounded-lg flex items-center cursor-pointer space-x-2 ${choice === 'status' ? 'bg-green-200 font-bold' : ''}`}
onClick={() => {
setChoice('status');
}}
>
<span>Contract Status</span>
</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>
)}
</div>
</div>
</div>
)
);
}
8 changes: 8 additions & 0 deletions client/src/components/Buyer/Contract/Download.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export default function Download() {
return (
<div>

</div>
)
}
105 changes: 105 additions & 0 deletions client/src/components/Buyer/Contract/GenerateContract.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import { useState } from "react";
import { MdDone } from "react-icons/md";
import PdfDetails from "./PdfDetails";
import Metamask from "./Metamask";
import Download from "./Download";
export default function GenerateContract() {

const steps = ["Fill Details", "Connect to Metamask", "Download Pdf"];
const [currentStep, setCurrentStep] = useState(1);
// const [complete, setComplete] = useState(false);

const handleNext = () => {
if (currentStep === steps.length) {
// setComplete(true);
} else {
setCurrentStep((prev) => prev + 1);
}
};

const handleBack = () => {
if (currentStep > 1) {
setCurrentStep((prev) => prev - 1);
}
};
return (
<>
<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="flex w-full justify-between">
{steps?.map((step, i) => (
<div
key={i}
className={`relative flex flex-col w-full justify-center items-center ${
currentStep === i + 1 ? "active" : ""
}`}
>
<div
className={`w-10 h-10 flex items-center justify-center z-10 relative rounded-full font-semibold text-white ${
currentStep === i + 1
? "bg-sky-600"
: i < currentStep
? "bg-green-600"
: "bg-slate-700"
}`}
>
{i + 1 < currentStep ? (
<MdDone size={24} />
) : (
i + 1
)}
</div>
<p
className={`mt-2 ${
i + 1 < currentStep ? "text-white" : "text-gray-500"
}`}
>
{step}
</p>
{i !== 0 && (
<div
className={`absolute w-full h-[3px] top-1/2 transform -translate-y-1/2 ${
i < currentStep ? "bg-green-600" : "bg-slate-200"
}`}
style={{ right: "50%" }}
/>
)}
</div>
))}
</div>
{steps[currentStep-1] === 'Fill Details' && (
<>
<PdfDetails />
</>
)}
{currentStep === 'Connect to Metamask' && (
<>
<Metamask/>
</>
)}
{currentStep === 'Download Pdf' && (
<>
<Download/>
</>
)}


<div className="mt-4 flex justify-around w-full space-x-2">
<button
className="px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
onClick={handleBack}
disabled={currentStep === 1}
>
Back
</button>
<button
className="px-4 py-2 bg-green-500 text-white rounded hover:bg-green-600"
onClick={handleNext}
>
{currentStep === steps.length ? "Generate Another" : "Next"}
</button>
</div>

</div>
</>
);
}
7 changes: 7 additions & 0 deletions client/src/components/Buyer/Contract/Metamask.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export default function Metamask() {
return (
<div>

</div>
)
}
81 changes: 81 additions & 0 deletions client/src/components/Buyer/Contract/Pdf.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import { useState } from 'react';
import jsPDF from 'jspdf';
// import 'jspdf-autotable'; // Optional: if you want to use table features

const Pdf = () => {
const [contractDetails, setContractDetails] = useState({
buyerName: '',
sellerName: '',
contractDate: '',
details: ''
});

const handleChange = (e) => {
const { name, value } = e.target;
setContractDetails({ ...contractDetails, [name]: value });
};

const generatePDF = () => {
const doc = new jsPDF();

doc.setFontSize(16);
doc.text('Contract Details', 20, 20);

doc.setFontSize(12);
doc.text(`Buyer Name: ${contractDetails.buyerName}`, 20, 30);
doc.text(`Seller Name: ${contractDetails.sellerName}`, 20, 40);
doc.text(`Contract Date: ${contractDetails.contractDate}`, 20, 50);
doc.text('Details:', 20, 60);
doc.text(contractDetails.details, 20, 70);

doc.save('contract.pdf');
};

return (
<div>
<h2>Contract Form</h2>
<form>
<div>
<label>Buyer Name:</label>
<input
type="text"
name="buyerName"
value={contractDetails.buyerName}
onChange={handleChange}
/>
</div>
<div>
<label>Seller Name:</label>
<input
type="text"
name="sellerName"
value={contractDetails.sellerName}
onChange={handleChange}
/>
</div>
<div>
<label>Contract Date:</label>
<input
type="date"
name="contractDate"
value={contractDetails.contractDate}
onChange={handleChange}
/>
</div>
<div>
<label>Details:</label>
<textarea
name="details"
value={contractDetails.details}
onChange={handleChange}
/>
</div>
<button type="button" onClick={generatePDF}>
Generate PDF
</button>
</form>
</div>
);
};

export default Pdf;
Loading

0 comments on commit 71cf83b

Please sign in to comment.