70 lines
2.1 KiB
JavaScript
70 lines
2.1 KiB
JavaScript
"use client";
|
|
|
|
import CardCart from "@comp/Cards/CardCart/page";
|
|
import AppContext from "@ctx/AppContext";
|
|
import Link from "next/link";
|
|
import Chapar from "plugins/Chapar";
|
|
import PersianNumber from "plugins/PersianNumber";
|
|
import React, { useContext, useState } from "react";
|
|
import { BottomSheet } from "react-spring-bottom-sheet";
|
|
import { toast } from "react-toastify";
|
|
|
|
const BottomSheetDiscount = ({ orderId }) => {
|
|
const CTX = useContext(AppContext);
|
|
|
|
const [discountCode, setDiscountCode] = useState(null);
|
|
|
|
const body = { orderId, discountCode };
|
|
|
|
const handleDiscount = async () => {
|
|
try {
|
|
const data = await Chapar.post(
|
|
`${process.env.NEXT_PUBLIC_API_URL}/order/bag/discount/${orderId}?discountCode=${discountCode}`,
|
|
|
|
{
|
|
headers: {
|
|
Authorization: localStorage.getItem("token"),
|
|
},
|
|
}
|
|
);
|
|
CTX.setCheckOutData(data);
|
|
CTX.setBottomSheetDiscountOpen(false);
|
|
} catch ({ error, status }) {
|
|
toast.error(`${error?.response?.data?.message}`, {
|
|
position: "bottom-right",
|
|
closeOnClick: true,
|
|
});
|
|
}
|
|
};
|
|
return (
|
|
<BottomSheet
|
|
open={CTX.state.bottomSheetDiscountOpen}
|
|
onDismiss={() => CTX.setBottomSheetDiscountOpen(false)}
|
|
className={"z-50 relative"}
|
|
>
|
|
<div className="text-center p-3">
|
|
<p className="mb-0 text-sm pb-3">افزودن کد تخفیف </p>
|
|
</div>
|
|
|
|
<div className="p-3">
|
|
<input
|
|
type="text"
|
|
className="form-control bg-white !border-[1px] focus:!border-[1px] border-gray-400 focus:!border-gray-300 rounded-lg text-right !text-sm tr03 "
|
|
placeholder="کد را وارد کنید"
|
|
onChange={(e) => setDiscountCode(e.target.value)}
|
|
/>
|
|
</div>
|
|
<div className="w-full p-3 ">
|
|
<button
|
|
className="btn btn-primary text-sm w-full py-3 rounded-3xl"
|
|
onClick={() => handleDiscount()}
|
|
>
|
|
برسی کد تخفیف{" "}
|
|
</button>
|
|
</div>
|
|
</BottomSheet>
|
|
);
|
|
};
|
|
|
|
export default BottomSheetDiscount;
|