Repository navigation
Ensure that disabled feature page cannot be accessed using deep-link #37902
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
17377da
7ed9fa6
c8a7312
cf310c3
941e7fa
699f38a
daacbfe
7fb586e
4bd3e8a
7a71b4b
09203e4
2040059
c3e6470
b6f7c34
68e55e5
1c1d7fd
45d502c
e0580db
47b9904
139d14b
4764459
9da57fa
5fffd62
1a3b367
f5b7ea0
c901703
9c23128
540b2fa
169ab18
417ee81
216015d
96bf4ff
44ae002
4e63dac
1a61fe2
514bc3b
0b908d8
58e1b4b
919f7c7
c13cda3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we created a new Workspace and then enabled a new feature right after that (ie: Workflows), we called create workspace and enable feature consecutively, this condition won't be enough to address that case so It will introduce the bug: #39443. |
||
| 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); | ||
Uh oh!
There was an error while loading. Please reload this page.