Skip to content

Commit

Permalink
fix: hide google customer reviews in buyer portal
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 committed Aug 29, 2023
1 parent 9db1f4f commit 24c88ea
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ export default function App() {

const [customStyles, setCustomStyle] = useState<string>(CUSTOM_STYLES)

useDomHooks({ setOpenPage })
useDomHooks({ setOpenPage, isOpen })

// open storefront
useSetOpen(isOpen, openUrl, params)
Expand Down
6 changes: 5 additions & 1 deletion apps/storefront/src/hooks/dom/useDomHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,18 @@ import { GlobaledContext } from '@/shared/global'
import { removeCartPermissions } from '@/utils/b3RolePermissions'

import useCartToQuote from './useCartToQuote'
import useHideGoogleCustomerReviews from './useHideGoogleCustomerReviews'
import useMyQuote from './useMyQuote'
import { useOpenPDP } from './useOpenPDP'
import useRegisteredbctob2b from './useRegisteredbctob2b'

type DispatchProps = Dispatch<SetStateAction<OpenPageState>>
interface MutationObserverProps {
setOpenPage: DispatchProps
isOpen: boolean
}

const useDomHooks = ({ setOpenPage }: MutationObserverProps) => {
const useDomHooks = ({ setOpenPage, isOpen }: MutationObserverProps) => {
const {
state: {
customerId,
Expand Down Expand Up @@ -49,6 +51,8 @@ const useDomHooks = ({ setOpenPage }: MutationObserverProps) => {
setOpenPage,
cartQuoteEnabled,
})

useHideGoogleCustomerReviews({ isOpen })
}

export default useDomHooks
30 changes: 30 additions & 0 deletions apps/storefront/src/hooks/dom/useHideGoogleCustomerReviews.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { useEffect } from 'react'

import useMobile from '@/hooks/useMobile'

interface B3HideGoogleCustomerReviewsProps {
isOpen: boolean
}

const useHideGoogleCustomerReviews = (
props: B3HideGoogleCustomerReviewsProps
) => {
const { isOpen } = props

const [isMobile] = useMobile()

useEffect(() => {
if (isMobile) return
const googleCustomerReviewsDoms = document.querySelectorAll(
'[title="Google Customer Reviews"]'
)
const newVisibilityStyle = isOpen ? 'none' : 'inline-block'

googleCustomerReviewsDoms.forEach((dom) => {
if (dom?.parentElement)
dom.parentElement.style.display = newVisibilityStyle
})
}, [isOpen])
}

export default useHideGoogleCustomerReviews
1 change: 1 addition & 0 deletions apps/storefront/src/hooks/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export { default as useCartToQuote } from './dom/useCartToQuote'
export { default as useDomHooks } from './dom/useDomHooks'
export { default as useHideGoogleCustomerReviews } from './dom/useHideGoogleCustomerReviews'
export { default as useMyQuote } from './dom/useMyQuote'
export * from './dom/useOpenPDP'
export { default as useRegisteredbctob2b } from './dom/useRegisteredbctob2b'
Expand Down

0 comments on commit 24c88ea

Please sign in to comment.