add table number + fix url verify
This commit is contained in:
@@ -11,14 +11,16 @@ import { extractErrorMessage } from '@/lib/func';
|
||||
import { useParams } from 'next/navigation';
|
||||
import { useGetCartItems } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData';
|
||||
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData';
|
||||
import { useCallback } from 'react';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import { useGetShipmentMethod } from '../../hooks/useOrderData';
|
||||
|
||||
type SummarySectionProps = {
|
||||
cartModal: boolean;
|
||||
onToggleCartModal: () => void;
|
||||
deliveryType: string;
|
||||
};
|
||||
|
||||
export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionProps) => {
|
||||
export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: SummarySectionProps) => {
|
||||
|
||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||
const { isSelectedAddress, isSelectedShipment, isSelectedPayment } = useCheckoutStore();
|
||||
@@ -27,6 +29,16 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
|
||||
const name = params.name as string;
|
||||
const { isSuccess } = useGetProfile();
|
||||
const { data: cartData } = useGetCartItems(isSuccess);
|
||||
const { data: shipmentMethod } = useGetShipmentMethod();
|
||||
|
||||
const selectedDeliveryMethod = useMemo(() => {
|
||||
if (!shipmentMethod?.data || !deliveryType) return null;
|
||||
return shipmentMethod.data.find((item) => item.id === deliveryType);
|
||||
}, [shipmentMethod?.data, deliveryType]);
|
||||
|
||||
const isCourierDelivery = useMemo(() => {
|
||||
return selectedDeliveryMethod?.method === 'deliveryCourier';
|
||||
}, [selectedDeliveryMethod]);
|
||||
|
||||
const formatPrice = useCallback(
|
||||
(value: number) => value.toLocaleString('fa-IR'),
|
||||
@@ -40,7 +52,7 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
|
||||
const total = cartData?.data?.total ?? 0;
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (!isSelectedAddress) {
|
||||
if (!isSelectedAddress && isSelectedShipment && isCourierDelivery) {
|
||||
toast('لطفا آدرس را انتخاب کنید', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
import { MinusIcon, PlusIcon } from 'lucide-react';
|
||||
import { motion } from 'framer-motion';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { useEffect } from 'react';
|
||||
import { useSetTableNumber } from '../../hooks/useOrderData';
|
||||
|
||||
type TableSectionProps = {
|
||||
tableNumber: number;
|
||||
@@ -12,6 +14,17 @@ type TableSectionProps = {
|
||||
|
||||
export const TableSection = ({ tableNumber, onIncrement, onDecrement }: TableSectionProps) => {
|
||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||
const { mutate: setTableNumber } = useSetTableNumber();
|
||||
|
||||
useEffect(() => {
|
||||
if (tableNumber === 0) return;
|
||||
|
||||
const timer = setTimeout(() => {
|
||||
setTableNumber(tableNumber);
|
||||
}, 1000);
|
||||
|
||||
return () => clearTimeout(timer);
|
||||
}, [tableNumber, setTableNumber]);
|
||||
|
||||
return (
|
||||
<section className="bg-container rounded-container box-shadow-normal p-4 py-2">
|
||||
|
||||
@@ -108,7 +108,7 @@ function OrderDetailInex() {
|
||||
<AddressSection />
|
||||
)}
|
||||
|
||||
{deliveryType === '1' && (
|
||||
{selectedDeliveryMethod?.method === 'dineIn' && (
|
||||
<TableSection
|
||||
tableNumber={tableNumber}
|
||||
onIncrement={incrementTableNumber}
|
||||
@@ -132,6 +132,7 @@ function OrderDetailInex() {
|
||||
<SummarySection
|
||||
cartModal={cartModal}
|
||||
onToggleCartModal={toggleCartModal}
|
||||
deliveryType={deliveryType}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
createOrder,
|
||||
applyCoupon,
|
||||
removeCoupon,
|
||||
setTableNumber,
|
||||
} from "../service/OrderService";
|
||||
|
||||
export const useGetShipmentMethod = () => {
|
||||
@@ -69,3 +70,9 @@ export const useRemoveCoupon = () => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const useSetTableNumber = () => {
|
||||
return useMutation({
|
||||
mutationFn: setTableNumber,
|
||||
});
|
||||
};
|
||||
|
||||
@@ -52,3 +52,10 @@ export const removeCoupon = async () => {
|
||||
const { data } = await api.delete("/public/cart/coupon");
|
||||
return data;
|
||||
};
|
||||
|
||||
export const setTableNumber = async (number: number) => {
|
||||
const { data } = await api.patch("/public/cart/table-number", {
|
||||
tableNumber: number.toString(),
|
||||
});
|
||||
return data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user