[APP-1761] Prevent welcome modal from reappearing (#9786)
* store welcome modal appearance in localstorage * lint * redundancy
This commit is contained in:
@@ -8,27 +8,23 @@ export function useWelcomeModal() {
|
|||||||
const [isOpen, setIsOpen] = useState(false)
|
const [isOpen, setIsOpen] = useState(false)
|
||||||
|
|
||||||
const open = () => setIsOpen(true)
|
const open = () => setIsOpen(true)
|
||||||
const close = () => {
|
const close = () => setIsOpen(false)
|
||||||
setIsOpen(false)
|
|
||||||
// Mark that user has actively closed the modal, don't show again this session
|
|
||||||
if (typeof window !== 'undefined') {
|
|
||||||
sessionStorage.setItem('welcomeModalClosed', 'true')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Only show modal if:
|
// Only show modal if:
|
||||||
// 1. User is not logged in
|
// 1. User is not logged in
|
||||||
// 2. We're on the web (this is a web-only feature)
|
// 2. We're on the web (this is a web-only feature)
|
||||||
// 3. We're on the homepage (path is '/' or '/home')
|
// 3. We're on the homepage (path is '/' or '/home')
|
||||||
// 4. User hasn't actively closed the modal in this session
|
// 4. Modal hasn't been shown before
|
||||||
if (IS_WEB && !hasSession && typeof window !== 'undefined') {
|
if (IS_WEB && !hasSession && typeof window !== 'undefined') {
|
||||||
const currentPath = window.location.pathname
|
const currentPath = window.location.pathname
|
||||||
const isHomePage = currentPath === '/'
|
const isHomePage = currentPath === '/'
|
||||||
const hasUserClosedModal =
|
const hasModalBeenShown =
|
||||||
sessionStorage.getItem('welcomeModalClosed') === 'true'
|
localStorage.getItem('welcomeModalShown') === 'true'
|
||||||
|
|
||||||
if (isHomePage && !hasUserClosedModal) {
|
if (isHomePage && !hasModalBeenShown) {
|
||||||
|
// Mark that the modal has been shown, don't show again
|
||||||
|
localStorage.setItem('welcomeModalShown', 'true')
|
||||||
// Small delay to ensure the page has loaded
|
// Small delay to ensure the page has loaded
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
open()
|
open()
|
||||||
|
|||||||
Reference in New Issue
Block a user