******ADDING TOAST MESSAGES*****

 WE USE TOAST MESSAGES TO DISPLAY THE MESSAGES MORE LIKE A NOTIFICATION 

IN SELL WINDOW.JS WE ADD TOAST TO DISPLAY IF THE ORDER IS PLACED OR NOT.

AS WE DISPLAY MESSAGE AFTER THE ORDER IS PLACED WE ADD THEM IN THE HANDLE CLICK FUNCTION.  THE MESSAGE IS SENT FROM THE SELL WINDOW

AND THE MESSAGE IS DISPLAYED IN HOLDINGS.

SELLWINDOW.JS

import { toast } from "react-toastify";


export default function SellActionWindow({ uid, price }) {
  const [stockQty, setStockQty] = useState(1);
  const [stockPrice, setStockPrice] = useState(price);
  const generalContext = useContext(GeneralContext);
  const handleSellClick = async () => {
    try {
      const response = await axios.post(
        "http://localhost:3002/newOrder",
        {
          name: uid,
          qty: stockQty,
          price: stockPrice,
          mode: "SELL",
        },
        { withCredentials: true }
      );
      console.log(response);
      try {
        generalContext.closeSellWindow();
        toast.success("Sell order placed successfully.");
      } catch (e) {
        console.error("Error after response:", e);
      }
    } catch (error) {
      if (error.response && error.response.status === 400) {
        toast.error(
          error.response.data.message || "Not enough holdings to sell."
        );
      } else {
        toast.error("Something went wrong. Please try again.");
      }
      console.error("Sell failed:", error);
    }
  };
  const handleCancelClick = () => {
    generalContext.closeSellWindow();
  };


IN HOLDING.JS WE ADD THE TOAST CONTAINER TO DISPLAY THE MESSAGE.

import { ToastContainer } from "react-toastify";


    </div>
          <ToastContainer position="top-right" autoClose={3000} />
          <AreaGraph data={data} />




Comments

Popular posts from this blog

*********UPDATING THE FRONTEND*********

**************** EXTRACTING DATA FROM API **************