add cancel logic
This commit is contained in:
@@ -1,31 +1,41 @@
|
|||||||
// import { useGlobals } from "../../hooks/useGlobals";
|
// import { useGlobals } from "../../hooks/useGlobals";
|
||||||
import { Button, Card } from "antd";
|
import { Button, Card, message } from "antd";
|
||||||
import BackIcon from "components/Icons/BackIcon";
|
import BackIcon from "components/Icons/BackIcon";
|
||||||
import CancelIcon from "components/Icons/CancelIcon";
|
import CancelIcon from "components/Icons/CancelIcon";
|
||||||
import CancelPopupIcon from "components/Icons/CancelPopupIcon";
|
import CancelPopupIcon from "components/Icons/CancelPopupIcon";
|
||||||
import NextIcon from "components/Icons/NextIcon";
|
import NextIcon from "components/Icons/NextIcon";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
|
import { useParams } from "react-router-dom";
|
||||||
|
import { useCancelOrderMutation } from "redux/api/others";
|
||||||
|
import { useAppSelector } from "redux/hooks";
|
||||||
import { ProBottomSheet } from "../ProBottomSheet/ProBottomSheet";
|
import { ProBottomSheet } from "../ProBottomSheet/ProBottomSheet";
|
||||||
import ProText from "../ProText";
|
import ProText from "../ProText";
|
||||||
import ProTitle from "../ProTitle";
|
import ProTitle from "../ProTitle";
|
||||||
import styles from "./CustomBottomSheet.module.css";
|
import styles from "./CustomBottomSheet.module.css";
|
||||||
|
|
||||||
interface CancelOrderBottomSheetProps {
|
export function CancelOrderBottomSheet() {
|
||||||
initialValue?: string;
|
|
||||||
onSave?: (value: string) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export function CancelOrderBottomSheet({}: CancelOrderBottomSheetProps) {
|
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const [isOpen, setIsOpen] = useState(false);
|
const [isOpen, setIsOpen] = useState(false);
|
||||||
const isRTL = false; // Default to LTR
|
const { isRTL } = useAppSelector((state) => state.locale);
|
||||||
|
const { orderID } = useParams();
|
||||||
|
|
||||||
const handleSave = () => {
|
const [cancelOrder] = useCancelOrderMutation();
|
||||||
|
|
||||||
|
const handleCancelOrder = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
|
cancelOrder({
|
||||||
|
orderID: orderID,
|
||||||
|
}).then((res: any) => {
|
||||||
|
if (res.error) {
|
||||||
|
message.error(res.error.data.message);
|
||||||
|
} else {
|
||||||
|
message.success(res.data.message);
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleCancel = () => {
|
const handleKeepOrder = () => {
|
||||||
setIsOpen(false);
|
setIsOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -65,12 +75,12 @@ export function CancelOrderBottomSheet({}: CancelOrderBottomSheetProps) {
|
|||||||
|
|
||||||
<ProBottomSheet
|
<ProBottomSheet
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
onClose={handleCancel}
|
onClose={() => setIsOpen(false)}
|
||||||
title={t("order.cancelOrder")}
|
title={t("order.cancelOrder")}
|
||||||
showCloseButton={false}
|
showCloseButton={false}
|
||||||
initialSnap={1}
|
initialSnap={1}
|
||||||
height={"45vh"}
|
height={350}
|
||||||
snapPoints={["40vh"]}
|
snapPoints={[350]}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
@@ -95,7 +105,7 @@ export function CancelOrderBottomSheet({}: CancelOrderBottomSheetProps) {
|
|||||||
type="secondary"
|
type="secondary"
|
||||||
style={{
|
style={{
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
marginBottom: 10
|
marginBottom: 10,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
{t("order.thisActionCannotBeUndone")}
|
{t("order.thisActionCannotBeUndone")}
|
||||||
@@ -112,7 +122,7 @@ export function CancelOrderBottomSheet({}: CancelOrderBottomSheetProps) {
|
|||||||
<Button
|
<Button
|
||||||
type="primary"
|
type="primary"
|
||||||
style={{ width: "100%", height: 50, color: "#FFF" }}
|
style={{ width: "100%", height: 50, color: "#FFF" }}
|
||||||
onClick={handleSave}
|
onClick={handleKeepOrder}
|
||||||
>
|
>
|
||||||
{t("order.keepOrder")}
|
{t("order.keepOrder")}
|
||||||
</Button>
|
</Button>
|
||||||
@@ -126,7 +136,7 @@ export function CancelOrderBottomSheet({}: CancelOrderBottomSheetProps) {
|
|||||||
borderColor: "#ea1f22",
|
borderColor: "#ea1f22",
|
||||||
backgroundColor: "#fff",
|
backgroundColor: "#fff",
|
||||||
}}
|
}}
|
||||||
onClick={handleSave}
|
onClick={handleCancelOrder}
|
||||||
>
|
>
|
||||||
{t("order.cancelOrder")}
|
{t("order.cancelOrder")}
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
CANCEL_ORDER_URL,
|
||||||
CREATE_ORDER_URL,
|
CREATE_ORDER_URL,
|
||||||
ORDER_DETAILS_URL,
|
ORDER_DETAILS_URL,
|
||||||
ORDERS_URL,
|
ORDERS_URL,
|
||||||
@@ -46,6 +47,14 @@ export const branchApi = baseApi.injectEndpoints({
|
|||||||
}),
|
}),
|
||||||
invalidatesTags: ["Orders"],
|
invalidatesTags: ["Orders"],
|
||||||
}),
|
}),
|
||||||
|
cancelOrder: builder.mutation({
|
||||||
|
query: (body: any) => ({
|
||||||
|
url: CANCEL_ORDER_URL,
|
||||||
|
method: "POST",
|
||||||
|
body,
|
||||||
|
}),
|
||||||
|
invalidatesTags: ["Orders"],
|
||||||
|
}),
|
||||||
getTables: builder.query<
|
getTables: builder.query<
|
||||||
any,
|
any,
|
||||||
{ restaurantID: string; tableType: string }
|
{ restaurantID: string; tableType: string }
|
||||||
@@ -89,4 +98,5 @@ export const {
|
|||||||
useGetOrdersQuery,
|
useGetOrdersQuery,
|
||||||
useGetTablesQuery,
|
useGetTablesQuery,
|
||||||
useGetOrderDetailsQuery,
|
useGetOrderDetailsQuery,
|
||||||
|
useCancelOrderMutation
|
||||||
} = branchApi;
|
} = branchApi;
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ export const PRODUCT_DETAILS_URL = `${BASE_URL}getOptionsForItem/`;
|
|||||||
export const ORDERS_URL = `${BASE_URL}customer_orders`;
|
export const ORDERS_URL = `${BASE_URL}customer_orders`;
|
||||||
export const ORDER_DETAILS_URL = `${BASE_URL}restaurant/getOneOrderForWebmenu`;
|
export const ORDER_DETAILS_URL = `${BASE_URL}restaurant/getOneOrderForWebmenu`;
|
||||||
export const CREATE_ORDER_URL = `${BASE_URL}create_order_webmenu`;
|
export const CREATE_ORDER_URL = `${BASE_URL}create_order_webmenu`;
|
||||||
|
export const CANCEL_ORDER_URL = `${BASE_URL}restaurant/cancelOrder`;
|
||||||
export const TABLES_URL = `${BASE_URL}restaurant/getTables`;
|
export const TABLES_URL = `${BASE_URL}restaurant/getTables`;
|
||||||
export const LOGIN_URL = `${API_BASE_URL}login`;
|
export const LOGIN_URL = `${API_BASE_URL}login`;
|
||||||
export const SEND_OTP_URL = `${API_BASE_URL}sendOtp`;
|
export const SEND_OTP_URL = `${API_BASE_URL}sendOtp`;
|
||||||
|
|||||||
Reference in New Issue
Block a user