-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Handle blocked copilot and Expensify card flows gracefully #52103
Changes from 1 commit
a047d8a
b0465b9
f33b43f
cd5a453
61b69c1
feff84b
7cadc0f
285b061
617282c
7adfac1
c1b09af
6b74659
c095972
cb314b3
85da30a
c6a2529
3906089
ead9296
853ccde
887356c
d3eb43f
5df885f
08e7be3
96d6216
4d1b7e1
5fa58ff
e68f388
a7d8cb3
43c3e6c
79792d5
bfe6d6e
97c9677
72d0ba3
993841d
9a6492d
fe02315
1cd8fa5
b720e98
edfbbcd
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,71 @@ | ||
import React from 'react'; | ||
import {OnyxEntry, useOnyx} from 'react-native-onyx'; | ||
Check failure on line 2 in src/components/DelegateNoAccessWrapper.tsx
|
||
import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
import AccountUtils from '@libs/AccountUtils'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import NotFoundPage from '@pages/ErrorPage/NotFoundPage'; | ||
import CONST from '@src/CONST'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import ROUTES from '@src/ROUTES'; | ||
Check failure on line 9 in src/components/DelegateNoAccessWrapper.tsx
|
||
import {Account} from '@src/types/onyx'; | ||
Check failure on line 10 in src/components/DelegateNoAccessWrapper.tsx
|
||
import callOrReturn from '@src/types/utils/callOrReturn'; | ||
import {FullPageNotFoundViewProps} from './BlockingViews/FullPageNotFoundView'; | ||
Check failure on line 12 in src/components/DelegateNoAccessWrapper.tsx
|
||
|
||
const DENIED_ACCESS_VARIANTS = { | ||
[CONST.DELEGATE.DENIED_ACCESS_VARIANTS.DELEGATE]: (account: OnyxEntry<Account>) => isDelegate(account), | ||
[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[]; | ||
FullPageNotFoundViewProps?: FullPageNotFoundViewProps; | ||
shouldShowFullScreenFallback?: boolean; | ||
children: (() => React.ReactNode) | React.ReactNode; | ||
}; | ||
|
||
type PageNotFoundFallbackProps = { | ||
shouldShowFullScreenFallback?: boolean; | ||
}; | ||
|
||
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 PageNotFoundFallback({shouldShowFullScreenFallback}: PageNotFoundFallbackProps) { | ||
Check failure on line 42 in src/components/DelegateNoAccessWrapper.tsx
|
||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
return ( | ||
<NotFoundPage | ||
shouldForceFullScreen={shouldShowFullScreenFallback} | ||
onBackButtonPress={() => { | ||
if (shouldShowFullScreenFallback) { | ||
Navigation.dismissModal(); | ||
return; | ||
} | ||
Navigation.goBack(); | ||
}} | ||
shouldShowBackButton={!shouldShowFullScreenFallback ? shouldUseNarrowLayout : undefined} | ||
/> | ||
); | ||
} | ||
|
||
function DelegateNoAccessWrapper({accessDeniedVariants = [], shouldShowFullScreenFallback, ...props}: DelegateNoAccessWrapperProps) { | ||
const [account] = useOnyx(ONYXKEYS.ACCOUNT); | ||
const isPageAccessDenied = accessDeniedVariants.reduce((acc, variant) => { | ||
const accessDeniedFunction = DENIED_ACCESS_VARIANTS[variant]; | ||
return acc || accessDeniedFunction(account); | ||
}, false); | ||
if (isPageAccessDenied) { | ||
return <PageNotFoundFallback shouldShowFullScreenFallback={shouldShowFullScreenFallback} />; | ||
} | ||
return callOrReturn(props.children); | ||
} | ||
|
||
export default DelegateNoAccessWrapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DelegateNoAccessWrapper
is wrapped withinScreenWrapper
everywhere else except here. Any reason for this?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a mistake, It should be inside
ScreenWrapper
. Fixing...