Skip to content

Commit

Permalink
Use allBetas from ReportUtils
Browse files Browse the repository at this point in the history
  • Loading branch information
fabioh8010 committed Oct 1, 2024
1 parent fcd7690 commit fdf3949
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6932,15 +6932,15 @@ function getReportOfflinePendingActionAndErrors(report: OnyxEntry<Report>): Repo
/**
* Check if the report can create the expense with type is iouType
*/
function canCreateRequest(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, betas: OnyxEntry<Beta[]>, iouType: ValueOf<typeof CONST.IOU.TYPE>): boolean {
function canCreateRequest(report: OnyxEntry<Report>, policy: OnyxEntry<Policy>, iouType: ValueOf<typeof CONST.IOU.TYPE>): boolean {
const participantAccountIDs = Object.keys(report?.participants ?? {}).map(Number);

if (!canUserPerformWriteAction(report)) {
return false;
}

const requestOptions = getMoneyRequestOptions(report, policy, participantAccountIDs);
if (Permissions.canUseCombinedTrackSubmit(betas ?? [])) {
if (Permissions.canUseCombinedTrackSubmit(allBetas ?? [])) {
requestOptions.push(CONST.IOU.TYPE.CREATE);
}

Expand Down
21 changes: 4 additions & 17 deletions src/pages/workspace/AccessOrNotFoundWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,16 @@ const ACCESS_VARIANTS = {
login: string,
report: OnyxEntry<OnyxTypes.Report>,
allPolicies: NonNullable<OnyxCollection<OnyxTypes.Policy>> | null,
betas: OnyxEntry<OnyxTypes.Beta[]>,
iouType?: IOUType,
) =>
!!iouType &&
IOUUtils.isValidMoneyRequestType(iouType) &&
// Allow the user to submit the expense if we are submitting the expense in global menu or the report can create the expense
(isEmptyObject(report?.reportID) || ReportUtils.canCreateRequest(report, policy, betas, iouType)) &&
(isEmptyObject(report?.reportID) || ReportUtils.canCreateRequest(report, policy, iouType)) &&
(iouType !== CONST.IOU.TYPE.INVOICE || PolicyUtils.canSendInvoice(allPolicies, login)),
} as const satisfies Record<
string,
(
policy: OnyxTypes.Policy,
login: string,
report: OnyxTypes.Report,
allPolicies: NonNullable<OnyxCollection<OnyxTypes.Policy>> | null,
betas: OnyxEntry<OnyxTypes.Beta[]>,
iouType?: IOUType,
) => boolean
(policy: OnyxTypes.Policy, login: string, report: OnyxTypes.Report, allPolicies: NonNullable<OnyxCollection<OnyxTypes.Policy>> | null, iouType?: IOUType) => boolean
>;

type AccessVariant = keyof typeof ACCESS_VARIANTS;
Expand All @@ -60,8 +52,6 @@ type AccessOrNotFoundWrapperOnyxProps = {

/** Indicated whether the report data is loading */
isLoadingReportData: OnyxEntry<boolean>;

betas: OnyxEntry<OnyxTypes.Beta[]>;
};

type AccessOrNotFoundWrapperProps = AccessOrNotFoundWrapperOnyxProps & {
Expand Down Expand Up @@ -113,7 +103,7 @@ function PageNotFoundFallback({policyID, shouldShowFullScreenFallback, fullPageN
}

function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps, shouldBeBlocked, ...props}: AccessOrNotFoundWrapperProps) {
const {policy, policyID, report, iouType, allPolicies, featureName, isLoadingReportData, betas} = props;
const {policy, policyID, report, iouType, allPolicies, featureName, isLoadingReportData} = props;
const {login = ''} = useCurrentUserPersonalDetails();
const isPolicyIDInRoute = !!policyID?.length;
const isMoneyRequest = !!iouType && IOUUtils.isValidMoneyRequestType(iouType);
Expand All @@ -139,7 +129,7 @@ function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps

const isPageAccessible = accessVariants.reduce((acc, variant) => {
const accessFunction = ACCESS_VARIANTS[variant];
return acc && accessFunction(policy, login, report, allPolicies ?? null, betas, iouType);
return acc && accessFunction(policy, login, report, allPolicies ?? null, iouType);
}, true);

const isPolicyNotAccessible = isEmptyObject(policy) || (Object.keys(policy).length === 1 && !isEmptyObject(policy.errors)) || !policy?.id;
Expand Down Expand Up @@ -185,7 +175,4 @@ export default withOnyx<AccessOrNotFoundWrapperProps, AccessOrNotFoundWrapperOny
isLoadingReportData: {
key: ONYXKEYS.IS_LOADING_REPORT_DATA,
},
betas: {
key: ONYXKEYS.BETAS,
},
})(AccessOrNotFoundWrapper);

0 comments on commit fdf3949

Please sign in to comment.