add table number + fix url verify

This commit is contained in:
hamid zarghami
2025-12-13 16:09:11 +03:30
parent 29b8256ce0
commit ec50011e02
5 changed files with 44 additions and 4 deletions
@@ -11,14 +11,16 @@ import { extractErrorMessage } from '@/lib/func';
import { useParams } from 'next/navigation'; import { useParams } from 'next/navigation';
import { useGetCartItems } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData'; import { useGetCartItems } from '@/app/[name]/(Dialogs)/cart/hooks/useCartData';
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData'; 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 = { type SummarySectionProps = {
cartModal: boolean; cartModal: boolean;
onToggleCartModal: () => void; onToggleCartModal: () => void;
deliveryType: string;
}; };
export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionProps) => { export const SummarySection = ({ cartModal, onToggleCartModal, deliveryType }: SummarySectionProps) => {
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
const { isSelectedAddress, isSelectedShipment, isSelectedPayment } = useCheckoutStore(); const { isSelectedAddress, isSelectedShipment, isSelectedPayment } = useCheckoutStore();
@@ -27,6 +29,16 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
const name = params.name as string; const name = params.name as string;
const { isSuccess } = useGetProfile(); const { isSuccess } = useGetProfile();
const { data: cartData } = useGetCartItems(isSuccess); 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( const formatPrice = useCallback(
(value: number) => value.toLocaleString('fa-IR'), (value: number) => value.toLocaleString('fa-IR'),
@@ -40,7 +52,7 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
const total = cartData?.data?.total ?? 0; const total = cartData?.data?.total ?? 0;
const handleSubmit = () => { const handleSubmit = () => {
if (!isSelectedAddress) { if (!isSelectedAddress && isSelectedShipment && isCourierDelivery) {
toast('لطفا آدرس را انتخاب کنید', 'error'); toast('لطفا آدرس را انتخاب کنید', 'error');
return; return;
} }
@@ -3,6 +3,8 @@
import { MinusIcon, PlusIcon } from 'lucide-react'; import { MinusIcon, PlusIcon } from 'lucide-react';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { useEffect } from 'react';
import { useSetTableNumber } from '../../hooks/useOrderData';
type TableSectionProps = { type TableSectionProps = {
tableNumber: number; tableNumber: number;
@@ -12,6 +14,17 @@ type TableSectionProps = {
export const TableSection = ({ tableNumber, onIncrement, onDecrement }: TableSectionProps) => { export const TableSection = ({ tableNumber, onIncrement, onDecrement }: TableSectionProps) => {
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' }); 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 ( return (
<section className="bg-container rounded-container box-shadow-normal p-4 py-2"> <section className="bg-container rounded-container box-shadow-normal p-4 py-2">
@@ -108,7 +108,7 @@ function OrderDetailInex() {
<AddressSection /> <AddressSection />
)} )}
{deliveryType === '1' && ( {selectedDeliveryMethod?.method === 'dineIn' && (
<TableSection <TableSection
tableNumber={tableNumber} tableNumber={tableNumber}
onIncrement={incrementTableNumber} onIncrement={incrementTableNumber}
@@ -132,6 +132,7 @@ function OrderDetailInex() {
<SummarySection <SummarySection
cartModal={cartModal} cartModal={cartModal}
onToggleCartModal={toggleCartModal} onToggleCartModal={toggleCartModal}
deliveryType={deliveryType}
/> />
</div> </div>
); );
@@ -8,6 +8,7 @@ import {
createOrder, createOrder,
applyCoupon, applyCoupon,
removeCoupon, removeCoupon,
setTableNumber,
} from "../service/OrderService"; } from "../service/OrderService";
export const useGetShipmentMethod = () => { 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"); const { data } = await api.delete("/public/cart/coupon");
return data; return data;
}; };
export const setTableNumber = async (number: number) => {
const { data } = await api.patch("/public/cart/table-number", {
tableNumber: number.toString(),
});
return data;
};