cancel order
This commit is contained in:
@@ -10,8 +10,11 @@ import { Clock } from 'iconsax-react';
|
|||||||
import clsx from 'clsx';
|
import clsx from 'clsx';
|
||||||
import useToggle from '@/hooks/helpers/useToggle';
|
import useToggle from '@/hooks/helpers/useToggle';
|
||||||
import Prompt from '@/components/utils/Prompt';
|
import Prompt from '@/components/utils/Prompt';
|
||||||
import { useGetOrderDetail } from '../../checkout/hooks/useOrderData';
|
import { useCancelOrder, useGetOrderDetail } from '../../checkout/hooks/useOrderData';
|
||||||
import ordersTranslations from '@/locales/fa/orders.json';
|
import ordersTranslations from '@/locales/fa/orders.json';
|
||||||
|
import { toast } from '@/components/Toast';
|
||||||
|
import { extractErrorMessage } from '@/lib/func';
|
||||||
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
|
|
||||||
const getDeliveryMethodTitle = (method: string) => {
|
const getDeliveryMethodTitle = (method: string) => {
|
||||||
switch (method) {
|
switch (method) {
|
||||||
@@ -59,12 +62,24 @@ const getStatusText = (status: string): string => {
|
|||||||
function OrderTrackingPage() {
|
function OrderTrackingPage() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
const { state: cancelModal, toggle: toggleCancelModal } = useToggle();
|
const { state: cancelModal, toggle: toggleCancelModal } = useToggle();
|
||||||
const { data: orderDetail, isLoading } = useGetOrderDetail(id as string);
|
const { data: orderDetail, isLoading } = useGetOrderDetail(id as string);
|
||||||
|
const { mutate: cancelOrder } = useCancelOrder();
|
||||||
|
|
||||||
const onCancelOrder = (e: React.MouseEvent | null) => {
|
const onCancelOrder = (e: React.MouseEvent | null) => {
|
||||||
if (!e) return;
|
if (!e || !id) return;
|
||||||
// TODO: Implement cancel order logic
|
|
||||||
|
cancelOrder(id as string, {
|
||||||
|
onSuccess: () => {
|
||||||
|
toggleCancelModal();
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['order-detail', id] });
|
||||||
|
toast('سفارش با موفقیت لغو شد', 'success');
|
||||||
|
},
|
||||||
|
onError: (error) => {
|
||||||
|
toast(extractErrorMessage(error), 'error');
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user