UPDATING NEW ORDER ROUTE (SELL WINDOW)
SELL WINDOW BACKEND
app.post("/sellOrder", userVerification, async (req, res) => {
console.log(req.body);
const userId = req.user._id;
let newOrder = new OrderModel({
userId,
name: req.body.name,
qty: req.body.qty,
price: req.body.price,
mode: req.body.mode,
});
await newOrder.save();
});
SELL WINDOW.JS
import React, { useState, useContext } from "react";
import { Link } from "react-router-dom";
import GeneralContext from "./GeneralContext";
import "./BuyActionWindow.css";
import axios from "axios";
export default function SellActionWindow({ uid, price }) {
const [stockQty, setStockQty] = useState(1);
const [stockPrice, setStockPrice] = useState(price);
const generalContext = useContext(GeneralContext);
const handleSellClick = () => {
axios.post(
"http://localhost:3002/sellOrder",
{
name: uid,
qty: stockQty,
price: stockPrice,
mode: "SELL",
},
{ withCredentials: true }
);
console.log(uid);
generalContext.closeSellWindow();
};
const handleCancelClick = () => {
generalContext.closeSellWindow();
};
return (
<div className="container" id="buy-window" draggable="true">
<div className="regular-order">
<div className="inputs">
<fieldset>
<legend>Qty.</legend>
<input
type="number"
name="qty"
id="qty"
onChange={(e) => {
setStockQty(e.target.value);
}}
value={stockQty}
/>
</fieldset>
<fieldset>
<legend>Price</legend>
<input
type="number"
name="price"
id="price"
step="0.05"
onChange={(e) => {
setStockPrice(e.target.value);
}}
value={stockPrice}
/>
</fieldset>
</div>
</div>
<div className="buttons">
{uid}
<span>Selling starts at:{price}</span>
<div>
<Link className="btn btn-error" onClick={handleSellClick}>
Sell
</Link>
<Link to="" className="btn btn-grey" onClick={handleCancelClick}>
Cancel
</Link>
</div>
</div>
</div>
);
}



Comments
Post a Comment