Skip to content

Commit

Permalink
add shouldBeBlocked for AccessOrNotFoundWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
hungvu193 committed May 5, 2024
1 parent 6029043 commit fa7ba27
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/components/SelectionScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ type SelectionScreenProps = {

/** The current feature name that the user tries to get access to */
featureName?: PolicyFeatureName;

/** Whether or not to block user from accessing the page */
shouldBeBlocked?: boolean;
};

function SelectionScreen({
Expand All @@ -63,13 +66,15 @@ function SelectionScreen({
policyID,
accessVariants,
featureName,
shouldBeBlocked,
}: SelectionScreenProps) {
const {translate} = useLocalize();
return (
<AccessOrNotFoundWrapper
policyID={policyID}
accessVariants={accessVariants}
featureName={featureName}
shouldBeBlocked={shouldBeBlocked}
>
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
Expand Down
8 changes: 6 additions & 2 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type AccessOrNotFoundWrapperProps = AccessOrNotFoundWrapperOnyxProps & {

/** Props for customizing fallback pages */
fullPageNotFoundViewProps?: FullPageNotFoundViewProps;

/** Whether or not to block user from accessing the page */
shouldBeBlocked?: boolean;
} & Pick<FullPageNotFoundViewProps, 'subtitleKey' | 'onLinkPress'>;

type PageNotFoundFallbackProps = Pick<AccessOrNotFoundWrapperProps, 'policyID' | 'fullPageNotFoundViewProps'> & {shouldShowFullScreenFallback: boolean};
Expand All @@ -68,7 +71,7 @@ function PageNotFoundFallback({policyID, shouldShowFullScreenFallback, fullPageN
);
}

function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps, ...props}: AccessOrNotFoundWrapperProps) {
function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps, shouldBeBlocked, ...props}: AccessOrNotFoundWrapperProps) {
const {policy, policyID, featureName, isLoadingReportData} = props;

const isPolicyIDInRoute = !!policyID?.length;
Expand All @@ -92,7 +95,8 @@ function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps
return acc && accessFunction(policy);
}, true);

const shouldShowNotFoundPage = isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors)) || !policy?.id || !isPageAccessible || !isFeatureEnabled;
const shouldShowNotFoundPage =
isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors)) || !policy?.id || !isPageAccessible || !isFeatureEnabled || shouldBeBlocked;

if (shouldShowFullScreenLoadingIndicator) {
return <FullscreenLoadingIndicator />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function XeroInvoiceAccountSelectorPage({policy}: WithPolicyConnectionsProps) {
const policyID = policy?.id ?? '';
const {bankAccounts} = policy?.connections?.xero?.data ?? {};

const {invoiceCollectionsAccountID} = policy?.connections?.xero?.config.sync ?? {};
const {invoiceCollectionsAccountID, syncReimbursedReports} = policy?.connections?.xero?.config.sync ?? {};

const xeroSelectorOptions = useMemo<SelectorType[]>(
() =>
Expand Down Expand Up @@ -62,6 +62,7 @@ function XeroInvoiceAccountSelectorPage({policy}: WithPolicyConnectionsProps) {
displayName={XeroInvoiceAccountSelectorPage.displayName}
sections={[{data: xeroSelectorOptions}]}
listItem={RadioListItem}
shouldBeBlocked={!syncReimbursedReports}
onSelectRow={updateMode}
initiallyFocusedOptionKey={initiallyFocusedOptionKey}
headerContent={listHeaderComponent}
Expand Down

0 comments on commit fa7ba27

Please sign in to comment.