Skip to content

Commit

Permalink
Transaction done
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenish-Dhanani committed May 11, 2022
1 parent 1ea99d0 commit 2ac1a2d
Show file tree
Hide file tree
Showing 14 changed files with 697 additions and 540 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous"/>


<script>var Alert = ReactBootstrap.Alert;</script>
<!-- <script>var Alert = ReactBootstrap.Alert;</script> -->
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Expand Down
2 changes: 1 addition & 1 deletion src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function App() {
</Route>

<Route element={<PrivateRouter/>}>
<Route path='/home' element={<Products countdownTimestampMs={1659983662000}/>} />
<Route path='/home' element={<Products notify={notify} countdownTimestampMs={1659983662000}/>} />
{/* <Route path='/product/:id' exact element={<BidPage />} /> */}
<Route path='/product/:id' exact element={<BidProduct notify={notify} />} />
<Route path='/createauction' element={<CreateAuction notify={notify}/>} />
Expand Down
8 changes: 5 additions & 3 deletions src/components/AdminDashboard/AdminDashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const AdminDashboard = () => {

const [userList, setUserList] = useState([])
const [user_count, setUserCount] = useState([])

const [productsList, setProductList] = useState([]);
const [auction_count, setAuctionCount] = useState([])
console.log("Product List",productsList)
Expand All @@ -19,7 +19,7 @@ const AdminDashboard = () => {
.then((json) => {
setUserList(json)
console.log("Total User="+user_count);
setUserCount(userList.length);
setUserCount(json.length);

});

Expand All @@ -29,7 +29,7 @@ const AdminDashboard = () => {
.then((json) => {
setProductList(json)
console.log("Total Auctions="+auction_count);
setAuctionCount(productsList.length);
setAuctionCount(json.length);
})
}

Expand All @@ -40,6 +40,7 @@ const AdminDashboard = () => {
return (
<>
<AdminNavbar />
<div className="container">
<div>AdminDashboard</div>
<div class="row">
<div class="col-sm-6">
Expand All @@ -59,6 +60,7 @@ const AdminDashboard = () => {
</div>
</div>
</div>
</div>
</>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/components/AdminDashboard/AdminNavbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const AdminNavbar = () => {
<>
<nav className="navbar navbar-expand-lg navbar-light bg-light">
<div className="container-fluid">
<Link className="navbar-brand" to="/">
<Link className="navbar-brand" to="/admin">
Admin Dashboard
</Link>
<button
Expand Down
8 changes: 5 additions & 3 deletions src/components/AdminDashboard/DropProduct.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ const DropProduct = () => {
<>
<AdminNavbar/>
<ToastContainer />
<div>DropProduct</div>
<h3 className='mt-4'>DropProduct</h3>
<table className="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col"> Product Name</th>
<th scope="col"> Product Description</th>
<th scope="col"> Product Price</th>
<th scope="col"> Status </th>
<th scope="col"> Start Date </th>
<th scope="col"> End Date </th>
<th scope="col"> Delete </th>
</tr>
</thead>
Expand All @@ -68,7 +69,8 @@ const DropProduct = () => {
<td>{row.productName}</td>
<td>{row.productDescription}</td>
<td>{row.productPrice}</td>
<td>{row.status}</td>
<td>{row.startDate.substr(0,10)}</td>
<td>{row.endDate.substr(0,10)}</td>
<td><FontAwesomeIcon icon={faTrash} onClick={(e) => handleDelete(row._id, e)}/></td>
</tr>
);
Expand Down
8 changes: 4 additions & 4 deletions src/components/AdminDashboard/DropUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import AdminNavbar from './AdminNavbar';

import { ToastContainer, toast } from 'react-toastify';
import 'react-toastify/dist/ReactToastify.css';


export const DropUser = () => {

Expand Down Expand Up @@ -44,7 +44,7 @@ export const DropUser = () => {
toast.success("User deleted successfully");
}
})

fetchData()
}

Expand Down Expand Up @@ -77,11 +77,11 @@ export const DropUser = () => {
<td>{row.lastName}</td>
<td>{row.aadharNumber}</td>
<td>{row.email}</td>
<td>{row.isVerified}</td>
<td>{row.isVerified?"👍":"😒"}</td>
<td><FontAwesomeIcon icon={faTrash} onClick={(e) => handleDelete(row._id, e)}/></td>
</tr>
);
})}
})}
</tbody>
</table>
</>
Expand Down
22 changes: 15 additions & 7 deletions src/components/BidProduct.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,19 +197,28 @@ const BidProduct = ({ notify }) => {
<div className="flex-grow-1 text-end">{seller}</div>
</li>
<li className="list-group-item d-flex flex-row">
<div className="fw-bold flex-grow-1">Time Left</div>
<div className="fw-bold flex-grow-1">Start Date</div>
<div className="flex-grow-1 text-end">
{new Date(bidProduct.startDate)
.toLocaleString()
.substring(0, 10)}
</div>
</li>
<li className="list-group-item d-flex flex-row">
<div className="fw-bold flex-grow-1">End Date</div>
<div className="flex-grow-1 text-end">
{new Date(bidProduct.endDate)
.toLocaleString()
.substring(0, 10) +
" " +
bidProduct.endTime}
.substring(0, 10)}
</div>
</li>
</ul>

{console.log(new Date(bidProduct.startDate) <= new Date())}
{sessionStorage.getItem("user") != bidProduct.userId &&
bidProduct.status != "upcoming" && (
// bidProduct.status != "upcoming" && (
// bidProduct.startDate <= new Date &&
new Date(bidProduct.startDate) <= new Date() && new Date(bidProduct.endDate) >= new Date() &&
(
<>
<br />
<br />
Expand Down Expand Up @@ -258,7 +267,6 @@ const BidProduct = ({ notify }) => {
</div>
</>
)}

<hr />
<div className="mt-4">
{/* <h1 className="fs-3">Recent Bids</h1> */}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CardGroup.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ProductCard } from './ProductCard';

const CardGroup=({products,role,handleOnDeleteBtnClick})=>{
const CardGroup=({products,role,handleOnDeleteBtnClick,notify})=>{
// console.log(products)
return (
<div className="container d-flex justify-content-center align-items-center flex-wrap p-3 mb-4" style={{gap:"40px"}}>
{products && products.map((product, index)=>{
return <ProductCard product={product} key={index} role={role} handleOnDeleteBtnClick={handleOnDeleteBtnClick} />
return <ProductCard product={product} key={index} notify={notify} role={role} handleOnDeleteBtnClick={handleOnDeleteBtnClick} />
})}
</div>
)
Expand Down
5 changes: 5 additions & 0 deletions src/components/CreateAuction.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ const CreateAuction = ({notify}) => {
err.description = "Description is required."
}

if(values.startdate === values.enddate){
err.startdate = "Start Date and End date can not be same."
err.enddate = "Start Date and End date can not be same."
}

if(values.startdate > values.enddate){
err.startdate = "start date should be less than end date"
err.enddate = "start date should be less than end date"
Expand Down
25 changes: 15 additions & 10 deletions src/components/Home.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Testimonials from './Testimonials/Testimonials';
const Home = () => {
const [isLoading, setIsLoading] = useState(true);
const [onGoingAuctions, setOngoingAuctions] = useState([]);
const [upcomingAuctions, setUpcomingAuctions] = useState([]);

// console.log("cardGroup",cardGroups)

Expand All @@ -28,20 +29,19 @@ const Home = () => {
}).then(productsArray=>{

let Ongoing = [];
let upComing =[];
productsArray.filter((obj) => {
if (
getNumberOfDays(
obj.endDate,
new Date().toISOString().substr(0, 10)
) < 0
) {
if ( new Date(obj.startDate) <= new Date() && new Date(obj.endDate) >= new Date()) {
Ongoing.push(obj);
}else if(new Date(obj.startDate) > new Date() && new Date(obj.endDate) >= new Date()){
upComing.push(obj)
}
});
console.log(new Date().toISOString().substr(0, 10));
// console.log(new Date().toISOString().substr(0, 10));

setOngoingAuctions(Ongoing);
console.log("Ongoing", Ongoing);
setOngoingAuctions(Ongoing)
setUpcomingAuctions(upComing)
// console.log("Ongoing", Ongoing);
setIsLoading(false)
});
}
Expand Down Expand Up @@ -75,7 +75,12 @@ const Home = () => {
On Going Auctions
</h1>
<ItemSlider products={onGoingAuctions} role="onGoingAuctions"/>
<CardGroup products={onGoingAuctions.length >5 ? onGoingAuctions.slice(5,onGoingAuctions.length):onGoingAuctions} role="onGoingAuctions" />

<h1 className="text-center my-4">
Upcoming Auctions
</h1>
<ItemSlider products={upcomingAuctions} role="upComingAuctions"/>
{/* <CardGroup products={onGoingAuctions.length >5 ? onGoingAuctions.slice(5,onGoingAuctions.length):onGoingAuctions} role="onGoingAuctions" /> */}
<Testimonials/>
<Footer/>
</div>
Expand Down
3 changes: 1 addition & 2 deletions src/components/ItemSlider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,10 @@ const ItemSlider = ({ products, role, handleOnDeleteBtnClick }) => {
autoPlay={true}
>

<div className="container d-flex justify-content-center align-items-center flex-wrap p-3 mb-4" style={{ gap: "40px" }}>

{products && products.slice(0, 5).map((product, index) => {
return <ProductCard product={product} key={index} role={role} handleOnDeleteBtnClick={handleOnDeleteBtnClick} />
})}
</div>
</Carousel>)
}

Expand Down
38 changes: 33 additions & 5 deletions src/components/ProductCard.jsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React,{useState, useEffect, useRef} from 'react'
import { useNavigate } from 'react-router-dom';

const ProductCard = ({product,role, handleOnDeleteBtnClick}) => {
const ProductCard = ({product,role, handleOnDeleteBtnClick,notify}) => {
// console.log(product)
const userId = sessionStorage.getItem('user')
const navigate = useNavigate()

const handleProductClick = (pid)=>{
Expand Down Expand Up @@ -35,6 +36,33 @@ const ProductCard = ({product,role, handleOnDeleteBtnClick}) => {
// }, 1000)
// }

const ProceedTransaction = async (auction)=>{
//bidderid //sellerid amount date auction id
const {_id:auctionId, highestBid:amount, userId:sellerId} = auction;
// const bid = auction.Bid.bidInfo[auction.Bid.bidInfo.length-1].Amount;
const bidderId = auction.Bid.bidInfo[auction.Bid.bidInfo.length-1].bidderId;

let data = {
bidderId,
sellerId,
date:new Date(),
auctionId,
amount
}

let result = await fetch("http://localhost:4000/transaction/add_transaction", {
method: 'POST',
headers: {
"Content-Type": "application/json",
"Accept": "application/json"
},
body: JSON.stringify(data)
});
result = await result.json();
notify("Transaction Done.")
window.location.reload()
}

return (
<div className='d-flex bg-light overflow-hidden justify-content-center align-items-center flex-column shadow bg-white' style={{ width: '20rem' }}>
{/* image */}
Expand Down Expand Up @@ -70,17 +98,17 @@ const ProductCard = ({product,role, handleOnDeleteBtnClick}) => {
</div>
</div>
{/* action */}
{role==="onGoingAuctions" && <div className="w-100 px-3 my-1 mb-3 d-flex flex-row justify-content-between align-items-center" >
<span className='btn btn-sm fs-4'>❤️</span>
{role==="onGoingAuctions" && <div className="w-100 px-3 my-1 mb-3 d-flex flex-row justify-content-end align-items-center" >
<button className='btn btn-primary w-50' onClick={()=>{handleProductClick(product._id)}}>Bid Now</button>
</div>}
{role==="myAuction" && <div className="w-100 px-3 my-1 mb-3 d-flex flex-row justify-content-between align-items-center" >
<button className='btn btn-danger' onClick={()=>handleOnDeleteBtnClick(product)}>Delete</button>
<button className='btn btn-primary' onClick={()=>{handleUpdateBtnClick(product._id)}}>Update</button>
<button className='btn btn-primary' onClick={()=>{handleProductClick(product._id)}}>View</button>
</div>}
{(role==="upComingAuctions" || role==="endedAuctions" )&& <div className="w-100 px-3 my-1 mb-3 d-flex flex-row justify-content-end align-items-center" >
<button className='btn btn-primary w-50' onClick={()=>{handleProductClick(product._id)}}>View</button>
{(role==="upComingAuctions" || role==="endedAuctions" )&& <div className="w-100 px-3 my-1 mb-3 d-flex flex-column justify-content-center align-items-center" >
<button className='btn btn-primary w-100' onClick={()=>{handleProductClick(product._id)}}>View</button>
{new Date(product.endDate) < new Date() && product.userId === userId && <button className='mt-4 btn btn-primary w-100' onClick={()=>ProceedTransaction(product)}>Proceed Transaction</button>}
</div>}

</div>
Expand Down
Loading

0 comments on commit 2ac1a2d

Please sign in to comment.