Skip to content

Commit c7b6210

Browse files
authored
fix(nav): Add localstorage backup for tour modal view state (#95145)
1 parent 5c1dd94 commit c7b6210

File tree

1 file changed

+28
-14
lines changed

1 file changed

+28
-14
lines changed

static/app/views/nav/tour/tour.tsx

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {useAssistant, useMutateAssistant} from 'sentry/components/tours/useAssis
1313
import {t} from 'sentry/locale';
1414
import {trackAnalytics} from 'sentry/utils/analytics';
1515
import normalizeUrl from 'sentry/utils/url/normalizeUrl';
16+
import {useLocalStorageState} from 'sentry/utils/useLocalStorageState';
1617
import {useLocation} from 'sentry/utils/useLocation';
1718
import {useNavigate} from 'sentry/utils/useNavigate';
1819
import useOrganization from 'sentry/utils/useOrganization';
@@ -256,6 +257,10 @@ export function useTourModal() {
256257
});
257258
const {mutate: mutateAssistant} = useMutateAssistant();
258259
const user = useUser();
260+
const [localTourState, setLocalTourState] = useLocalStorageState(
261+
STACKED_NAVIGATION_TOUR_GUIDE_KEY,
262+
{hasSeen: false}
263+
);
259264

260265
const enforceStackedNav = organization.features.includes('enforce-stacked-navigation');
261266
// We don't want to show the tour modal for new users that were forced into the new stacked navigation.
@@ -264,7 +269,19 @@ export function useTourModal() {
264269

265270
const shouldShowTourModal =
266271
assistantData?.find(item => item.guide === STACKED_NAVIGATION_TOUR_GUIDE_KEY)
267-
?.seen === false && !shouldSkipForNewUserEnforcedStackedNav;
272+
?.seen === false &&
273+
!shouldSkipForNewUserEnforcedStackedNav &&
274+
!localTourState.hasSeen;
275+
276+
const dismissTour = useCallback(() => {
277+
trackAnalytics('navigation.tour_modal_dismissed', {organization});
278+
mutateAssistant({
279+
guide: STACKED_NAVIGATION_TOUR_GUIDE_KEY,
280+
status: 'dismissed',
281+
});
282+
setLocalTourState({hasSeen: true});
283+
endTour();
284+
}, [mutateAssistant, organization, endTour, setLocalTourState]);
268285

269286
useEffect(() => {
270287
if (shouldShowTourModal && !hasOpenedTourModal.current) {
@@ -275,12 +292,7 @@ export function useTourModal() {
275292
<NavTourModal
276293
closeModal={props.closeModal}
277294
handleDismissTour={() => {
278-
trackAnalytics('navigation.tour_modal_dismissed', {organization});
279-
mutateAssistant({
280-
guide: STACKED_NAVIGATION_TOUR_GUIDE_KEY,
281-
status: 'dismissed',
282-
});
283-
endTour();
295+
dismissTour();
284296
props.closeModal();
285297
}}
286298
handleStartTour={startTour}
@@ -292,18 +304,20 @@ export function useTourModal() {
292304
// If user closes modal through other means, also prevent the modal from being shown again.
293305
onClose: reason => {
294306
if (reason) {
295-
trackAnalytics('navigation.tour_modal_dismissed', {organization});
296-
mutateAssistant({
297-
guide: STACKED_NAVIGATION_TOUR_GUIDE_KEY,
298-
status: 'dismissed',
299-
});
300-
endTour();
307+
dismissTour();
301308
}
302309
},
303310
}
304311
);
305312
}
306-
}, [shouldShowTourModal, startTour, mutateAssistant, endTour, organization]);
313+
}, [
314+
shouldShowTourModal,
315+
startTour,
316+
mutateAssistant,
317+
endTour,
318+
organization,
319+
dismissTour,
320+
]);
307321
}
308322

309323
const NAV_REFERRER = 'nav-tour';

0 commit comments

Comments
 (0)