Skip to content

Commit

Permalink
Refactor changes in FeatureEnabledAccessOrNotFoundComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenjaHorbach committed Apr 20, 2024
1 parent 3f893fd commit 0744c28
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/pages/workspace/FeatureEnabledAccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,27 +41,17 @@ function FeatureEnabledAccessOrNotFoundComponent(props: FeatureEnabledAccessOrNo
const [isPolicyFeatureEnabled, setIsPolicyFeatureEnabled] = useState(isFeatureEnabled);
const shouldShowNotFoundPage = isEmptyObject(props.policy) || !props.policy?.id || !isPolicyFeatureEnabled;
const pendingField = props.policy?.pendingFields?.[props.featureName];
const [isFeatureScreenOpen, setIsFeatureScreenOpen] = useState(false);
const isFocused = useIsFocused();
const {isOffline} = useNetwork();

useEffect(() => {
if (!isFeatureScreenOpen && isFocused) {
setIsFeatureScreenOpen(true);
setIsPolicyFeatureEnabled(isFeatureEnabled);
return;
}
if (!isFocused) {
setIsFeatureScreenOpen(false);
return;
}
setIsPolicyFeatureEnabled((isPrevFeatureEnabled) => {
if (!pendingField || isOffline) {
return isFeatureEnabled;
}
return isPrevFeatureEnabled;
});
}, [isFocused, pendingField, isOffline, isFeatureEnabled, isFeatureScreenOpen]);
if (!pendingField || isOffline) {
setIsPolicyFeatureEnabled(isFeatureEnabled);
}
}, [isFocused, pendingField, isOffline, isFeatureEnabled]);

useEffect(() => {
if (!isPolicyIDInRoute || !isEmptyObject(props.policy)) {
Expand Down

0 comments on commit 0744c28

Please sign in to comment.