Skip to content

Commit

Permalink
Merge pull request Expensify#40319 from GandalfGwaihir/issue37554
Browse files Browse the repository at this point in the history
[Fix]: Requestee cannot hold requests in 1:1 IOU transactions
  • Loading branch information
dangrous authored Apr 26, 2024
2 parents 8c07611 + 9802487 commit 035adb8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 1 addition & 5 deletions src/components/MoneyRequestHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,8 @@ function MoneyRequestHeader({
if (isOnHold) {
IOU.unholdRequest(iouTransactionID, report?.reportID);
} else {
if (!policy?.type) {
return;
}

const activeRoute = encodeURIComponent(Navigation.getActiveRouteWithoutParams());
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy.type, iouTransactionID, report?.reportID, activeRoute));
Navigation.navigate(ROUTES.MONEY_REQUEST_HOLD_REASON.getRoute(policy?.type ?? CONST.POLICY.TYPE.PERSONAL, iouTransactionID, report?.reportID, activeRoute));
}
};

Expand Down
16 changes: 13 additions & 3 deletions src/pages/iou/HoldReasonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,21 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
const {transactionID, reportID, backTo} = route.params;

const report = ReportUtils.getReport(reportID);

// We first check if the report is part of a policy - if not, then it's a personal request (1:1 request)
// For personal requests, we need to allow both users to put the request on hold
const isWorkspaceRequest = ReportUtils.isGroupPolicy(report);
const parentReportAction = ReportActionsUtils.getReportAction(report?.parentReportID ?? '', report?.parentReportActionID ?? '');

const navigateBack = () => {
Navigation.navigate(backTo);
};

const onSubmit = (values: FormOnyxValues<typeof ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM>) => {
if (!ReportUtils.canEditMoneyRequest(parentReportAction)) {
// We have extra isWorkspaceRequest condition since, for 1:1 requests, canEditMoneyRequest will rightly return false
// as we do not allow requestee to edit fields like description and amount.
// But, we still want the requestee to be able to put the request on hold
if (!ReportUtils.canEditMoneyRequest(parentReportAction) && isWorkspaceRequest) {
return;
}

Expand All @@ -68,15 +75,18 @@ function HoldReasonPage({route}: HoldReasonPageProps) {
if (!values.comment) {
errors.comment = 'common.error.fieldRequired';
}
if (!ReportUtils.canEditMoneyRequest(parentReportAction)) {
// We have extra isWorkspaceRequest condition since, for 1:1 requests, canEditMoneyRequest will rightly return false
// as we do not allow requestee to edit fields like description and amount.
// But, we still want the requestee to be able to put the request on hold
if (!ReportUtils.canEditMoneyRequest(parentReportAction) && isWorkspaceRequest) {
const formErrors = {};
ErrorUtils.addErrorMessage(formErrors, 'reportModified', 'common.error.requestModified');
FormActions.setErrors(ONYXKEYS.FORMS.MONEY_REQUEST_HOLD_FORM, formErrors);
}

return errors;
},
[parentReportAction],
[parentReportAction, isWorkspaceRequest],
);

useEffect(() => {
Expand Down

0 comments on commit 035adb8

Please sign in to comment.