Skip to content

Commit

Permalink
fix: using local state for useMonitorBrowserBack (#1028)
Browse files Browse the repository at this point in the history
  • Loading branch information
deov31 authored Apr 25, 2024
1 parent 7c5e748 commit c5bd0c3
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions apps/storefront/src/hooks/dom/useMonitorBrowserBack.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { useEffect } from 'react'
import { useEffect, useState } from 'react'

import { useAppSelector } from '@/store'
import { CustomerRole } from '@/types'
import { B3SStorage } from '@/utils'

interface UseMonitorBrowserBackProps {
isOpen: boolean
Expand All @@ -13,16 +12,16 @@ const useMonitorBrowserBack = ({ isOpen }: UseMonitorBrowserBackProps) => {
const history = window.location
const isLogin = role !== CustomerRole.GUEST

useEffect(() => {
const isEnterB2BBuyerPortal = B3SStorage.get('isEnterB2BBuyerPortal')
const [isEnterB2BBuyerPortal, setIsEnterB2BBuyerPortal] = useState(false)

useEffect(() => {
if (isOpen && !history.hash.includes('/pdp')) {
B3SStorage.set('isEnterB2BBuyerPortal', true)
setIsEnterB2BBuyerPortal(true)
}

if (!isOpen && isLogin && isEnterB2BBuyerPortal) {
window.location.reload()
B3SStorage.set('isEnterB2BBuyerPortal', false)
setIsEnterB2BBuyerPortal(false)
}
// disabling to avoid unnecessary renders when adding the missing dependencies
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand Down

0 comments on commit c5bd0c3

Please sign in to comment.