diff --git a/client/src/components/ItemBody.css b/client/src/components/ItemBody.css new file mode 100644 index 0000000..ccf5eda --- /dev/null +++ b/client/src/components/ItemBody.css @@ -0,0 +1,5 @@ +.card-img-top { + height: auto; + width: 100%; + object-fit: cover; +} \ No newline at end of file diff --git a/client/src/components/Item_body.js b/client/src/components/Item_body.js index 3ffeb46..d45306f 100644 --- a/client/src/components/Item_body.js +++ b/client/src/components/Item_body.js @@ -3,6 +3,8 @@ import logo from '../img/showcase.jpg' import axios from 'axios' import { TimeCounter } from './utils' import QnA from './QnA' +import Modal from 'react-bootstrap/Modal' +import Button from 'react-bootstrap/Button' const { REACT_APP_SERVER_IP, REACT_APP_PORT } = process.env @@ -12,28 +14,34 @@ const Item_body = ({ itemid }) => { const [itemObj, setItemObj] = useState(null) const [timeLeft, setTimeLeft] = useState(0) const [bidAmount, setBidAmount] = useState(0) - const [errorMessage, setErrorMessage] = useState("") - + const [showMessage, setShowMessage] = useState(false); + const [message, setMessage] = useState(""); + + const handleClose = () => setShowMessage(false); + useEffect(() => { const fetchUrl = 'http://' + REACT_APP_SERVER_IP + ':' + REACT_APP_PORT + `/item?id=${itemid}` axios.get(fetchUrl) - .then(res => { - setItemObj(res.data) - setTimeLeft(new Date(res.data.endTime) - Date.now()) - setLoaded(true) - }) - .catch(err => console.log(err)) + .then(res => { + setItemObj(res.data) + setTimeLeft(new Date(res.data.endTime) - Date.now()) + setLoaded(true) + }) + .catch(err => console.log(err)) }, []) - + + function submitBid() { - const minReqBid = parseInt(itemObj.highestBid ? itemObj.highestBid : itemObj.minBid) - if (bidAmount < minReqBid) { - setErrorMessage("Submitted bid cannot be lesser than minimum bid.") + + if(itemObj.highestBid && bidAmount <= itemObj.highestBid){ + setMessage("Submitted bid should be greater than the current bid !") + setShowMessage(true) return } - if (bidAmount == minReqBid) { - setErrorMessage("Submitted bid cannot be equal to minimum bid.") + else if(!itemObj.highestBid && bidAmount < itemObj.minBid){ + setMessage("Submitted bid should be greater than or equal to the minimum bid !") + setShowMessage(true) return } @@ -53,76 +61,80 @@ const Item_body = ({ itemid }) => { function addToWatchlist() { const postItemUrl = 'http://' + REACT_APP_SERVER_IP + ':' + REACT_APP_PORT + '/watchlist' axios.post(postItemUrl, null, { params: { id: itemid } }) - .then( - setErrorMessage("Item added to watchlist.") - ) + .then(res => { + setMessage("Item added to watchlist successfully!") + setShowMessage(true) + }) .catch(err => console.log(err)) } return ( -
+ <> {!loaded &&


Loading...

} {loaded && <> -
-
-
-
+
+
+ +
+
...
-
-
-
-
{itemObj.name}
-
{itemObj.category}
-
-
-
-

- {itemObj.description} -

-
-
- Minimum Bid: {itemObj.minBid} -
-
-
-
-
Current Bid: {itemObj.highestBid?itemObj.highestBid:"No bids yet."}
-
-
-
Time remaining:
-
-
-
-
- setBidAmount(parseInt(e.target.value))} placeholder="Enter bid amount" type="number" aria-label="Search"/> -
-
- +
+ +
+
{itemObj.name}
+
+ +
-
- + +
+

{itemObj.description}

+
+
Category :  {itemObj.category}
+
Minimum Bid :  ₹{itemObj.minBid}
+
Time remaining :  
+
Current Bid :  ₹{itemObj.highestBid?itemObj.highestBid:"No bids yet."}
+ +
Place a bid!
+
+ setBidAmount(e.target.value)}/> + +
+
-
-
-
{errorMessage}
-
-
-
-
+ + + Message + + {message} + + + + -
-
- +
+ +
+ +
+
+ +
+
+ +
+
+
} -
+ ) } diff --git a/server/src/index.js b/server/src/index.js index 0814a54..7b7a16d 100644 --- a/server/src/index.js +++ b/server/src/index.js @@ -211,8 +211,8 @@ app.post('/bidItem', checkAuthenticate, async(req, res)=> { if(!obj) return res.status(404).send("Item with given id does not exist."); - if(req.query.bid <= obj.minBid) { - return res.status(400).send('bid is lesser than or equal to minimum bid') + if(req.query.bid < obj.minBid) { + return res.status(400).send('bid is lesser than the minimum bid') } else { item = await Item.findOneAndUpdate({_id: obj.id}, {