This commit is contained in:
hamid zarghami
2025-12-04 09:21:37 +03:30
parent 77535934d5
commit a170e4bd7c
6 changed files with 85 additions and 7 deletions
@@ -2,12 +2,14 @@
import React from 'react';
import Link from 'next/link';
import { useParams, useRouter, usePathname } from 'next/navigation';
import Button from '@/components/button/PrimaryButton';
import { useGetFoods } from '@/app/[name]/(Main)/hooks/useMenuData';
import type { Food } from '@/app/[name]/(Main)/types/Types';
import { useCart } from '../hook/useCart';
import { useTranslation } from 'react-i18next';
import { Add, Minus } from 'iconsax-react';
import { useGetProfile } from '@/app/[name]/(Profile)/profile/hooks/userProfileData';
interface CartSummaryProps {
description?: string;
@@ -15,6 +17,11 @@ interface CartSummaryProps {
}
const CartSummary = ({ description = '', onDescriptionChange }: CartSummaryProps) => {
const params = useParams();
const router = useRouter();
const pathname = usePathname();
const name = params.name as string;
const { isSuccess } = useGetProfile();
const { data: foodsResponse } = useGetFoods();
const foods = React.useMemo(() => foodsResponse?.data ?? [], [foodsResponse?.data]);
const { items } = useCart();
@@ -72,6 +79,13 @@ const CartSummary = ({ description = '', onDescriptionChange }: CartSummaryProps
onClick={(event) => {
if (isCartEmpty) {
event.preventDefault();
return;
}
if (!isSuccess) {
event.preventDefault();
const redirectUrl = encodeURIComponent(pathname);
router.push(`/${name}/auth?redirect=${redirectUrl}`);
return;
}
}}
className={isCartEmpty ? 'pointer-events-none opacity-60' : ''}