-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37902 from rezkiy37/feature/37785-restrict-access…
…-WorkspaceMoreFeaturesPage Ensure that disabled feature page cannot be accessed using deep-link
- Loading branch information
Showing
28 changed files
with
992 additions
and
724 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/pages/workspace/FeatureEnabledAccessOrNotFoundWrapper.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* eslint-disable rulesdir/no-negated-variables */ | ||
import React, {useEffect} from 'react'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView'; | ||
import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import * as PolicyUtils from '@libs/PolicyUtils'; | ||
import * as Policy from '@userActions/Policy'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
import type * as OnyxTypes from '@src/types/onyx'; | ||
import type {PolicyFeatureName} from '@src/types/onyx/Policy'; | ||
import {isEmptyObject} from '@src/types/utils/EmptyObject'; | ||
|
||
type FeatureEnabledAccessOrNotFoundOnyxProps = { | ||
/** The report currently being looked at */ | ||
policy: OnyxEntry<OnyxTypes.Policy>; | ||
|
||
/** Indicated whether the report data is loading */ | ||
isLoadingReportData: OnyxEntry<boolean>; | ||
}; | ||
|
||
type FeatureEnabledAccessOrNotFoundComponentProps = FeatureEnabledAccessOrNotFoundOnyxProps & { | ||
/** The children to render */ | ||
children: ((props: FeatureEnabledAccessOrNotFoundOnyxProps) => React.ReactNode) | React.ReactNode; | ||
|
||
/** The report currently being looked at */ | ||
policyID: string; | ||
|
||
/** The current feature name that the user tries to get access */ | ||
featureName: PolicyFeatureName; | ||
}; | ||
|
||
function FeatureEnabledAccessOrNotFoundComponent(props: FeatureEnabledAccessOrNotFoundComponentProps) { | ||
const isPolicyIDInRoute = !!props.policyID?.length; | ||
const shouldShowFullScreenLoadingIndicator = props.isLoadingReportData !== false && (!Object.entries(props.policy ?? {}).length || !props.policy?.id); | ||
const shouldShowNotFoundPage = isEmptyObject(props.policy) || !props.policy?.id || !PolicyUtils.isPolicyFeatureEnabled(props.policy, props.featureName); | ||
|
||
useEffect(() => { | ||
if (!isPolicyIDInRoute || !isEmptyObject(props.policy)) { | ||
// If the workspace is not required or is already loaded, we don't need to call the API | ||
return; | ||
} | ||
|
||
Policy.openWorkspace(props.policyID, []); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [isPolicyIDInRoute, props.policyID]); | ||
|
||
if (shouldShowFullScreenLoadingIndicator) { | ||
return <FullscreenLoadingIndicator />; | ||
} | ||
|
||
if (shouldShowNotFoundPage) { | ||
return ( | ||
<FullPageNotFoundView | ||
shouldShow={shouldShowNotFoundPage} | ||
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_WORKSPACES)} | ||
shouldForceFullScreen | ||
/> | ||
); | ||
} | ||
|
||
return typeof props.children === 'function' ? props.children(props) : props.children; | ||
} | ||
|
||
export default withOnyx<FeatureEnabledAccessOrNotFoundComponentProps, FeatureEnabledAccessOrNotFoundOnyxProps>({ | ||
policy: { | ||
key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID ?? ''}`, | ||
}, | ||
isLoadingReportData: { | ||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||
}, | ||
})(FeatureEnabledAccessOrNotFoundComponent); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.