From 8d417a9fcb574be07168835eb968824570e135e3 Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Tue, 19 Dec 2023 16:35:16 -0800 Subject: [PATCH] Check policy violations locally for distance requests --- src/libs/actions/IOU.js | 30 +++++++++++++++++-- .../step/IOURequestStepConfirmation.js | 5 +++- .../iou/steps/MoneyRequestConfirmPage.js | 18 ++++++++++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ea29ae75387c..6bfe3fda88b2 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -290,6 +290,26 @@ function resetMoneyRequestInfo(id = '') { }); } +/** + * Builds the Onyx data for a money request. + * + * @param {Object} chatReport + * @param {Object} iouReport + * @param {Object} transaction + * @param {Object} chatCreatedAction + * @param {Object} iouCreatedAction + * @param {Object} iouAction + * @param {Object} optimisticPersonalDetailListAction + * @param {Object} reportPreviewAction + * @param {Array} optimisticPolicyRecentlyUsedCategories + * @param {Array} optimisticPolicyRecentlyUsedTags + * @param {boolean} isNewChatReport + * @param {boolean} isNewIOUReport + * @param {Object} policy - May be undefined, an empty object, or an object matching the Policy type (src/types/onyx/Policy.ts) + * @param {Array} policyTags + * @param {Array} policyCategories + * @returns {Array} - An array containing the optimistic data, success data, and failure data. + */ function buildOnyxDataForMoneyRequest( chatReport, iouReport, @@ -814,9 +834,12 @@ function getMoneyRequestInformation( * @param {String} currency * @param {String} merchant * @param {Boolean} [billable] - * @param {Obejct} validWaypoints + * @param {Object} validWaypoints + * @param {Object} policy - May be undefined, an empty object, or an object matching the Policy type (src/types/onyx/Policy.ts) + * @param {Array} policyTags + * @param {Array} policyCategories */ -function createDistanceRequest(report, participant, comment, created, category, tag, amount, currency, merchant, billable, validWaypoints) { +function createDistanceRequest(report, participant, comment, created, category, tag, amount, currency, merchant, billable, validWaypoints, policy, policyTags, policyCategories) { // If the report is an iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); const currentChatReport = isMoneyRequestReport ? ReportUtils.getReport(report.chatReportID) : report; @@ -840,6 +863,9 @@ function createDistanceRequest(report, participant, comment, created, category, category, tag, billable, + policy, + policyTags, + policyCategories, ); API.write( 'CreateDistanceRequest', diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 9d725ee34d8c..07f232297339 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -199,9 +199,12 @@ function IOURequestStepConfirmation({ transaction.merchant, transaction.billable, TransactionUtils.getValidWaypoints(transaction.comment.waypoints, true), + policy, + policyTags, + policyCategories, ); }, - [report, transaction], + [policy, policyCategories, policyTags, report, transaction], ); const createTransaction = useCallback( diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 3a6b8cb74529..1738ac78df47 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -216,9 +216,25 @@ function MoneyRequestConfirmPage(props) { props.iou.currency, props.iou.merchant, props.iou.billable, + props.policy, + props.policyTags, + props.policyCategories, ); }, - [props.report, props.iou.created, props.iou.transactionID, props.iou.category, props.iou.tag, props.iou.amount, props.iou.currency, props.iou.merchant, props.iou.billable], + [ + props.report, + props.iou.created, + props.iou.transactionID, + props.iou.category, + props.iou.tag, + props.iou.amount, + props.iou.currency, + props.iou.merchant, + props.iou.billable, + props.policy, + props.policyTags, + props.policyCategories, + ], ); const createTransaction = useCallback(