"use client"; import AppContext from "@ctx/AppContext"; import Chapar from "plugins/Chapar"; import { useContext, useState } from "react"; import { BottomSheet } from "react-spring-bottom-sheet"; import { toast } from "react-toastify"; const BottomSheetDiscount = ({ orderId }) => { // const [item, setItem] = useState(); const CTX = useContext(AppContext); const [discountCode, setDiscountCode] = useState(null); const body = { orderId, discountCode }; // Function to handle discount operation asynchronously const handleDiscount = async () => { // Retrieve token from localStorage asynchronously const token = localStorage.getItem("token"); try { // Send a POST request to the API endpoint to apply discount const data = await Chapar.post( `${process.env.NEXT_PUBLIC_API_URL}/order/bag/discount/${orderId}?discountCode=${discountCode}`, { // Include the token in the Authorization header headers: { Authorization: token, }, } ); // Update the checkout data with the response CTX.setCheckOutData(data); // Close the bottom sheet for discount CTX.setBottomSheetDiscountOpen(false); } catch ({ error, status }) { // If there's an error, display an error message using toast toast.error(`${error?.response?.data?.message}`, { position: "bottom-right", closeOnClick: true, }); } }; return ( CTX.setBottomSheetDiscountOpen(false)} className={"z-50 relative"} >

افزودن کد تخفیف

setDiscountCode(e.target.value)} />
); }; export default BottomSheetDiscount;