|
@@ -2,32 +2,34 @@
|
|
|
import { FC, ReactNode } from "react";
|
|
import { FC, ReactNode } from "react";
|
|
|
import { useAppDispatch } from "@/store/hooks";
|
|
import { useAppDispatch } from "@/store/hooks";
|
|
|
import { openAddToCartDialog } from "@/store/slices/addToCartDialogSlice";
|
|
import { openAddToCartDialog } from "@/store/slices/addToCartDialogSlice";
|
|
|
-import { GET_PRODUCT_BY_URL_KEY } from "@/graphql";
|
|
|
|
|
|
|
+import { GET_PRODUCT_BY_ID } from "@/graphql";
|
|
|
import { useLazyQuery } from "@apollo/client/react";
|
|
import { useLazyQuery } from "@apollo/client/react";
|
|
|
import { LoadingSpinner } from "@components/common/LoadingSpinner";
|
|
import { LoadingSpinner } from "@components/common/LoadingSpinner";
|
|
|
import ShoppingCartIcon from "@components/common/icons/ShoppingCartIcon";
|
|
import ShoppingCartIcon from "@components/common/icons/ShoppingCartIcon";
|
|
|
import { useCustomToast } from "@utils/hooks/useToast";
|
|
import { useCustomToast } from "@utils/hooks/useToast";
|
|
|
import { handleApolloBusinessError } from "@/lib/ApolloErrorHandler";
|
|
import { handleApolloBusinessError } from "@/lib/ApolloErrorHandler";
|
|
|
interface OpenAddToCartModalButtonProps {
|
|
interface OpenAddToCartModalButtonProps {
|
|
|
- productUrlKey: string;
|
|
|
|
|
|
|
+ // productUrlKey?: string;
|
|
|
|
|
+ productId: number;
|
|
|
icon?: ReactNode;
|
|
icon?: ReactNode;
|
|
|
}
|
|
}
|
|
|
export const OpenAddToCartModalButton: FC<OpenAddToCartModalButtonProps> = ({
|
|
export const OpenAddToCartModalButton: FC<OpenAddToCartModalButtonProps> = ({
|
|
|
- productUrlKey,
|
|
|
|
|
|
|
+ // productUrlKey,
|
|
|
|
|
+ productId,
|
|
|
icon,
|
|
icon,
|
|
|
}) => {
|
|
}) => {
|
|
|
const dispatch = useAppDispatch();
|
|
const dispatch = useAppDispatch();
|
|
|
// const [loading, setLoading] = useState(false);
|
|
// const [loading, setLoading] = useState(false);
|
|
|
const { showToast } = useCustomToast();
|
|
const { showToast } = useCustomToast();
|
|
|
|
|
|
|
|
- const [getContent, { loading }] = useLazyQuery(GET_PRODUCT_BY_URL_KEY, {
|
|
|
|
|
|
|
+ const [getContent, { loading }] = useLazyQuery(GET_PRODUCT_BY_ID, {
|
|
|
fetchPolicy: "network-only",
|
|
fetchPolicy: "network-only",
|
|
|
});
|
|
});
|
|
|
const openDialog = async () => {
|
|
const openDialog = async () => {
|
|
|
if (loading) return;
|
|
if (loading) return;
|
|
|
try {
|
|
try {
|
|
|
const result = await getContent({
|
|
const result = await getContent({
|
|
|
- variables: { urlKey: productUrlKey },
|
|
|
|
|
|
|
+ variables: { id: productId },
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
console.log("product ----- ", result);
|
|
console.log("product ----- ", result);
|