Skip to content

Commit

Permalink
Fix bug with not found after reload
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenjaHorbach committed Apr 16, 2024
1 parent 7484834 commit 268b870
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3919,9 +3919,9 @@ function navigateWhenEnableFeature(policyID: string, featureRoute: Route) {
new Promise<void>((resolve) => {
resolve();
}).then(() => {
requestAnimationFrame(() => {
setTimeout(() => {
Navigation.navigate(featureRoute);
});
}, 300);
});
}

Expand Down
7 changes: 5 additions & 2 deletions src/pages/workspace/FeatureEnabledAccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* eslint-disable rulesdir/no-negated-variables */
import {useIsFocused} from '@react-navigation/native';
import React, {useEffect, useState} from 'react';
import type {OnyxEntry} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
Expand Down Expand Up @@ -42,6 +43,8 @@ function FeatureEnabledAccessOrNotFoundComponent(props: FeatureEnabledAccessOrNo
const shouldShowNotFoundPage = isEmptyObject(props.policy) || !props.policy?.id || !isPolicyFeatureEnabled;
const {isOffline} = useNetwork();

const isFocused = useIsFocused();
const prevIsFocused = usePrevious(isFocused);
const pendingField = props.policy?.pendingFields?.[props.featureName];
const prevPendingField = usePrevious(pendingField);

Expand All @@ -57,12 +60,12 @@ function FeatureEnabledAccessOrNotFoundComponent(props: FeatureEnabledAccessOrNo

useEffect(() => {
setIsPolicyFeatureEnabled((isCurrentPolicyFeatureEnabled) => {
if (prevPendingField !== pendingField || isOffline || !pendingField) {
if (prevPendingField !== pendingField || isOffline || !pendingField || !prevIsFocused) {
return isFeatureEnabled;
}
return isCurrentPolicyFeatureEnabled;
});
}, [pendingField, isFeatureEnabled, isOffline, prevPendingField]);
}, [pendingField, isFeatureEnabled, isOffline, prevPendingField, prevIsFocused]);

if (shouldShowFullScreenLoadingIndicator) {
return <FullscreenLoadingIndicator />;
Expand Down

0 comments on commit 268b870

Please sign in to comment.