From 12a2f3c819821d51d08c9b6dcf13e070bbab2677 Mon Sep 17 00:00:00 2001 From: Alex Efremov Date: Fri, 2 Aug 2024 13:25:23 +0700 Subject: [PATCH 1/6] Change logic of the useVIewCartPixel hook --- react/Minicart.tsx | 11 +++++++++-- react/components/DrawerMode.tsx | 3 +++ react/modules/pixelHelper.ts | 2 +- react/modules/useViewCartPixel.tsx | 22 +++++++++++++++------- 4 files changed, 28 insertions(+), 10 deletions(-) diff --git a/react/Minicart.tsx b/react/Minicart.tsx index 0afae41b..3c067588 100644 --- a/react/Minicart.tsx +++ b/react/Minicart.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react' +import React, { FC, useState } from 'react' import { IconCart } from 'vtex.store-icons' import { BackdropMode } from 'vtex.store-drawer' import { useOrderForm } from 'vtex.order-manager/OrderForm' @@ -61,10 +61,12 @@ export const Minicart: FC = ({ const { orderForm }: OrderFormContext = useOrderForm() + const [isDrawerOpen, setIsDrawerOpen] = useState(false) const { variation, open } = useMinicartState() const { url: checkoutUrl } = useCheckoutURL() - useViewCartPixel(open, orderForm?.items) + // for Popup it uses "open" and for Drawer it uses "isDrawerOpen" to send view_cart pixel event + useViewCartPixel(variation === 'drawer' ? isDrawerOpen : open, orderForm?.items) if (variation === 'link') { return ( @@ -102,6 +104,10 @@ export const Minicart: FC = ({ ) } + const onDrawerVisibilityChanged = (visible: boolean) => { + setIsDrawerOpen(visible) + } + return (