Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions client/src/components/ItemBody.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.card-img-top {
height: auto;
width: 100%;
object-fit: cover;
}
142 changes: 77 additions & 65 deletions client/src/components/Item_body.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}

Expand All @@ -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 (
<div>
<>
{!loaded && <div className="m-5"><br /><br /><h1>Loading...</h1></div>}
{loaded &&
<>
<div className="parent-container d-flex m-5">
<div className="container" style={{ width: "auto" }}>
<div className="row">
<div className="col mt-5">
<div className="container-fluid">
<div className="row mt-5 mb-5">

<div className="col-5 mt-5">
<div className="container" style={{ width: "auto" }}>
<img id="imageContainer" src={itemObj.photo ? itemObj.photo : logo} className="card-img-top" alt="..." />
</div>
</div>
</div>

<div className="container ms-3">
<div className="row mt-4 mb-4">
<div className="col h2">{itemObj.name}</div>
<div className="col">{itemObj.category}</div>
</div>
<div className="row mt-4 mb-4">
<div className="col">
<p><i>
{itemObj.description}
</i></p>
</div>
<div className="col">
Minimum Bid: {itemObj.minBid}
</div>
</div>
<div className="row mt-4 mb-4">
<div className="col">
<h5>Current Bid: {itemObj.highestBid?itemObj.highestBid:"No bids yet."}</h5>
</div>
<div className="col">
<h5>Time remaining: <TimeCounter timeLeft={timeLeft} /></h5>
</div>
</div>
<div className="row mt-4">
<div className="col-3">
<input className="form-control me-2" onInput={e => setBidAmount(parseInt(e.target.value))} placeholder="Enter bid amount" type="number" aria-label="Search"/>
</div>
<div className="col">
<button className="btn btn-danger ms-2" onClick={submitBid}>BID</button>
<div className="col-7">

<div className="row mt-4 mb-5">
<div className="col-9 h2 pe-3">{itemObj.name}</div>
<div className="col-3">
<button className="btn rounded-pill btn-danger me-2 text-nowrap" onClick={addToWatchlist}>Add to Watchlist</button>
</div>
</div>
<div className="col">
<button className="btn rounded-pill btn-dark me-2 text-nowrap" onClick={addToWatchlist}>Add to Watchlist</button>

<div className="row mt-4 mb-4">
<div className="col pe-5"><p><i>{itemObj.description}</i></p></div>
<div className="col ps-5">
<div className="col text- mb-2"><strong className='text-danger'>Category : &nbsp;</strong>{itemObj.category}</div>
<div className="col mb-2"><strong className='text-danger'>Minimum Bid : &nbsp;</strong>₹{itemObj.minBid}</div>
<div className="col mb-2"><strong className='text-danger'>Time remaining : &nbsp;</strong><TimeCounter timeLeft={timeLeft} /></div>
<div className="col mb-2"><strong className='text-danger'>Current Bid : &nbsp;</strong>₹{itemObj.highestBid?itemObj.highestBid:"No bids yet."}</div>

<div className='mt-5 h4'>Place a bid!</div>
<div className="me-5 mt-3">
<input className="form-control" placeholder="Enter bid amount" type="number" onChange={(e) => setBidAmount(e.target.value)}/>
<button className="col-3 btn btn-danger pull-right mt-3" onClick={submitBid}>BID</button>
</div>
</div>
</div>
</div>
<div className="row mt-1">
<div style={{color: 'red'}} className="col">{errorMessage}</div>
</div>
</div>
</div>

<hr style={{ width: '85%', margin: 'auto' }} />
<Modal show={showMessage} onHide={handleClose}>
<Modal.Header closeButton>
<Modal.Title>Message</Modal.Title>
</Modal.Header>
<Modal.Body>{message}</Modal.Body>
<Modal.Footer>
<Button variant="secondary" onClick={handleClose}>Close</Button>
</Modal.Footer>
</Modal>

<div className="container mt-5 mb-5">
<div className='row'>
<QnA itemid={itemid} sellerId={itemObj.sellerId} qna={itemObj.questions}/>
</div>

</div>

<br />
<hr style={{ width: '85%', margin: 'auto' }} />

<div className="container mt-4 mb-5">
<div className='row'>
<QnA itemid={itemid} sellerId={itemObj.sellerId} qna={itemObj.questions}/>
</div>
</div>

</div>
<br />
</>
}
</div>
</>
)
}

Expand Down
4 changes: 2 additions & 2 deletions server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}, {
Expand Down