forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
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 Expensify#52103 from ChavdaSachin/fix-50796/Handle…
…-blocked-copilot-and-Expensify-card-flows-gracefully Handle blocked copilot and Expensify card flows gracefully
- Loading branch information
Showing
48 changed files
with
1,101 additions
and
688 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import React from 'react'; | ||
import {useOnyx} from 'react-native-onyx'; | ||
import type {OnyxEntry} from 'react-native-onyx'; | ||
import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
import AccountUtils from '@libs/AccountUtils'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Account} from '@src/types/onyx'; | ||
import callOrReturn from '@src/types/utils/callOrReturn'; | ||
import FullPageNotFoundView from './BlockingViews/FullPageNotFoundView'; | ||
|
||
const DENIED_ACCESS_VARIANTS = { | ||
// To Restrict All Delegates From Accessing The Page. | ||
[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]: (account: OnyxEntry<Account>) => isDelegate(account), | ||
// To Restrict Only Limited Access Delegates From Accessing The Page. | ||
[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.SUBMITTER]: (account: OnyxEntry<Account>) => isSubmitter(account), | ||
} as const satisfies Record<string, (account: OnyxEntry<Account>) => boolean>; | ||
|
||
type AccessDeniedVariants = keyof typeof DENIED_ACCESS_VARIANTS; | ||
|
||
type DelegateNoAccessWrapperProps = { | ||
accessDeniedVariants?: AccessDeniedVariants[]; | ||
shouldForceFullScreen?: boolean; | ||
children?: (() => React.ReactNode) | React.ReactNode; | ||
}; | ||
|
||
function isDelegate(account: OnyxEntry<Account>) { | ||
const isActingAsDelegate = !!account?.delegatedAccess?.delegate; | ||
return isActingAsDelegate; | ||
} | ||
|
||
function isSubmitter(account: OnyxEntry<Account>) { | ||
const isDelegateOnlySubmitter = AccountUtils.isDelegateOnlySubmitter(account); | ||
return isDelegateOnlySubmitter; | ||
} | ||
|
||
function DelegateNoAccessWrapper({accessDeniedVariants = [], shouldForceFullScreen, ...props}: DelegateNoAccessWrapperProps) { | ||
const [account] = useOnyx(ONYXKEYS.ACCOUNT); | ||
const isPageAccessDenied = accessDeniedVariants.reduce((acc, variant) => { | ||
const accessDeniedFunction = DENIED_ACCESS_VARIANTS[variant]; | ||
return acc || accessDeniedFunction(account); | ||
}, false); | ||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
|
||
if (isPageAccessDenied) { | ||
return ( | ||
<FullPageNotFoundView | ||
shouldShow | ||
shouldForceFullScreen={shouldForceFullScreen} | ||
onBackButtonPress={() => { | ||
if (shouldUseNarrowLayout) { | ||
Navigation.dismissModal(); | ||
return; | ||
} | ||
Navigation.goBack(); | ||
}} | ||
titleKey="delegate.notAllowed" | ||
subtitleKey="delegate.noAccessMessage" | ||
shouldShowLink={false} | ||
/> | ||
); | ||
} | ||
return callOrReturn(props.children); | ||
} | ||
|
||
export default DelegateNoAccessWrapper; |
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
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
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.