From 2600133360f27e4b49c481e6039627e95f7a120b Mon Sep 17 00:00:00 2001 From: Ishpaul Singh Date: Mon, 9 Dec 2024 18:59:39 +0530 Subject: [PATCH] Refactor useProductTrainingContext to improve tooltip visibility logic --- src/components/ProductTrainingContext/index.tsx | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/components/ProductTrainingContext/index.tsx b/src/components/ProductTrainingContext/index.tsx index 811777de384d..fa49c8c61980 100644 --- a/src/components/ProductTrainingContext/index.tsx +++ b/src/components/ProductTrainingContext/index.tsx @@ -150,6 +150,7 @@ function ProductTrainingContextProvider({children}: ChildrenProps) { /> + {/* {processedContent()} */} ); @@ -170,7 +171,7 @@ function ProductTrainingContextProvider({children}: ChildrenProps) { return {children}; } -const useProductTrainingContext = (tooltipName: ProductTrainingTooltipName, shouldRegister = true) => { +const useProductTrainingContext = (tooltipName: ProductTrainingTooltipName, shouldShow = true) => { const context = useContext(ProductTrainingContext); if (!context) { throw new Error('useProductTourContext must be used within a ProductTourProvider'); @@ -179,18 +180,18 @@ const useProductTrainingContext = (tooltipName: ProductTrainingTooltipName, shou const {shouldRenderTooltip, registerTooltip, unregisterTooltip, renderProductTrainingTooltip} = context; useEffect(() => { - if (shouldRegister) { + if (shouldShow) { registerTooltip(tooltipName); return () => { unregisterTooltip(tooltipName); }; } return undefined; - }, [tooltipName, registerTooltip, unregisterTooltip, shouldRegister]); + }, [tooltipName, registerTooltip, unregisterTooltip, shouldShow]); const shouldShowProductTrainingTooltip = useMemo(() => { - return shouldRenderTooltip(tooltipName); - }, [tooltipName, shouldRenderTooltip]); + return shouldShow && shouldRenderTooltip(tooltipName); + }, [shouldShow, shouldRenderTooltip, tooltipName]); const hideProductTrainingTooltip = useCallback(() => { const tooltip = PRODUCT_TRAINING_TOOLTIP_DATA[tooltipName]; @@ -198,7 +199,7 @@ const useProductTrainingContext = (tooltipName: ProductTrainingTooltipName, shou unregisterTooltip(tooltipName); }, [tooltipName, unregisterTooltip]); - if (!tooltipName) { + if (!shouldShow) { return { renderProductTrainingTooltip: () => null, hideProductTrainingTooltip: () => {},