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 ( -
- {itemObj.description} -
-{itemObj.description}