web/plugins/bottomSheet/BottomSheetDeleteAddress.jsx

51 lines
1.4 KiB
React
Raw Permalink Normal View History

2024-02-16 18:23:02 +03:30
"use client";
import AppContext from "@ctx/AppContext";
2024-06-12 18:23:30 +03:30
import Chapar from "plugins/Chapar";
2024-02-16 19:36:30 +03:30
import { useContext } from "react";
2024-02-16 18:23:02 +03:30
import { BottomSheet } from "react-spring-bottom-sheet";
import { toast } from "react-toastify";
const BottomSheetDeleteAddress = ({ id }) => {
const CTX = useContext(AppContext);
const cart = CTX.state.cart;
2024-06-12 18:23:30 +03:30
const handleDelete = async () => {
2024-02-16 18:23:02 +03:30
try {
2024-06-12 18:23:30 +03:30
const data = await Chapar.delete(
2024-02-16 18:23:02 +03:30
`${process.env.NEXT_PUBLIC_API_URL}/user/address/${id}`
);
2024-06-12 18:23:30 +03:30
CTX.setBottomSheetDeleteAddressOpen(false);
CTX.fetchAddressUser();
2024-02-16 18:23:02 +03:30
} catch ({ error, status }) {
toast.error(`${error?.response?.data?.message}`, {
position: "bottom-right",
closeOnClick: true,
});
}
};
return (
<BottomSheet
open={CTX.state.bottomSheetDeleteAddressOpen}
onDismiss={() => CTX.setBottomSheetDeleteAddressOpen(false)}
className={"z-50 relative"}
>
<div className="text-center p-3">
<p className="mb-0 text-sm pb-3">آیا از حذف آدرس اطمینان دارید ؟ </p>
</div>
<div className="xs:w-full lg:w-3/12 mx-auto p-3 ">
<button
className="btn bg-red-500 text-white text-sm w-full py-3 rounded-3xl"
onClick={() => handleDelete()}
>
حذف آدرس
</button>
</div>
</BottomSheet>
);
};
export default BottomSheetDeleteAddress;