Skip to content

Commit

Permalink
Check policy violations locally for distance requests
Browse files Browse the repository at this point in the history
  • Loading branch information
lindboe committed Dec 21, 2023
1 parent a8741ab commit 8d417a9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 4 deletions.
30 changes: 28 additions & 2 deletions src/libs/actions/IOU.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand All @@ -840,6 +863,9 @@ function createDistanceRequest(report, participant, comment, created, category,
category,
tag,
billable,
policy,
policyTags,
policyCategories,
);
API.write(
'CreateDistanceRequest',
Expand Down
5 changes: 4 additions & 1 deletion src/pages/iou/request/step/IOURequestStepConfirmation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
18 changes: 17 additions & 1 deletion src/pages/iou/steps/MoneyRequestConfirmPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 8d417a9

Please sign in to comment.