enable add to cart always but if product has variant redirect user to the details

This commit is contained in:
2025-10-07 23:06:00 +03:00
parent da9d7f8eb3
commit 9b98c4d5fe
3 changed files with 28 additions and 26 deletions

View File

@@ -1,18 +1,20 @@
import { PlusOutlined } from "@ant-design/icons";
import { Button, Grid } from "antd";
import { Button } from "antd";
import { addItem } from "features/order/orderSlice";
import useBreakPoint from "hooks/useBreakPoint";
import { useTranslation } from "react-i18next";
import { useNavigate, useParams } from "react-router-dom";
import { useAppDispatch, useAppSelector } from "redux/hooks";
import { colors } from "ThemeConstants";
import { Product } from "utils/types/appTypes";
const { useBreakpoint } = Grid;
export function AddToCart({ item }: { item: Product }) {
const { isRTL } = useAppSelector((state) => state.locale);
const { t } = useTranslation();
const dispatch = useAppDispatch();
const { xs, sm } = useBreakpoint();
const { isMobile, isTablet } = useBreakPoint();
const { id } = useParams();
const navigate = useNavigate();
const handleQuickAdd = (item: Product) => {
dispatch(
@@ -28,7 +30,7 @@ export function AddToCart({ item }: { item: Product }) {
extrasgroup: [],
},
quantity: 1,
})
}),
);
};
return (
@@ -36,7 +38,6 @@ export function AddToCart({ item }: { item: Product }) {
shape="round"
title="add"
iconPosition="start"
disabled={item.isHasVarint}
icon={
<PlusOutlined
title="add"
@@ -46,30 +47,28 @@ export function AddToCart({ item }: { item: Product }) {
}}
/>
}
size={xs || sm ? "small" : "middle"}
size={isMobile || isTablet ? "small" : "middle"}
onClick={(e) => {
e.preventDefault();
e.stopPropagation();
handleQuickAdd(item);
if (item.isHasVarint) {
navigate(`/${id}/menu`);
} else {
e.preventDefault();
e.stopPropagation();
handleQuickAdd(item);
}
}}
style={{
position: "absolute",
bottom: -10,
[isRTL ? "right" : "left"]: xs || sm ? "5%" : "15%",
[isRTL ? "right" : "left"]: isMobile ? "5%" : "15%",
zIndex: 1,
width: xs || sm ? 82 : 100,
height: xs || sm ? 32 : 44,
fontSize: xs || sm ? "1rem" : 18,
width: isMobile ? 82 : 100,
height: isMobile ? 32 : 44,
fontSize: isMobile ? "1rem" : 18,
fontWeight: 600,
border: 0,
backgroundColor: item.isHasVarint
? "rgba(233, 233, 233, 1)"
: colors.primary,
backgroundColor: colors.primary,
color: "#FFF",
// boxShadow:
// theme === "light"
// ? "0 2px 0 rgba(0,0,0,0.02)"
// : "0 2px 0 #6b6b6b",
}}
>
{t("common.add")}