From e4135d11d975a2529da9c2ef39b8c5386058c74d Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 21 Nov 2023 11:23:44 -0500 Subject: [PATCH 01/22] Possible solution to not passing down tags and categories --- src/libs/ReportUtils.js | 6 +++ src/libs/actions/IOU.js | 49 ++++++++++++++++++- .../iou/steps/MoneyRequestConfirmPage.js | 28 +++++++++++ 3 files changed, 82 insertions(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 673cb09232de..ebbc88278b03 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -100,6 +100,10 @@ function getPolicyTags(policyID) { return lodashGet(allPolicyTags, `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`, {}); } +function getPolicyCategories(policyID) { + return lodashGet(allPolicyTags, `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`, []); +} + function getChatType(report) { return report ? report.chatType : ''; } @@ -4295,6 +4299,8 @@ export { getParentNavigationSubtitle, getPolicyName, getPolicyType, + getPolicyCategories, + getPolicyTags, isArchivedRoom, isExpensifyOnlyParticipantInReport, canCreateTaskInReport, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 1f1cee166a0e..cccde7259cd6 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -19,6 +19,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as UserUtils from '@libs/UserUtils'; +import ViolationsUtils from '@libs/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -154,6 +155,7 @@ function buildOnyxDataForMoneyRequest( optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, + policyID, ) { const optimisticData = [ { @@ -380,6 +382,28 @@ function buildOnyxDataForMoneyRequest( }, ]; + if (!policyID) { + return [optimisticData, successData, failureData]; + } + const policy = ReportUtils.getPolicy(policyID); + const policyTags = ReportUtils.getPolicyTags(policyID); + const policyCategories = ReportUtils.getPolicyCategories(policyID); + + const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories); + + if (violationsOnyxData) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, + value: violationsOnyxData, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, + value: [], + }); + } + return [optimisticData, successData, failureData]; } @@ -401,6 +425,7 @@ function buildOnyxDataForMoneyRequest( * @param {String} [category] * @param {String} [tag] * @param {Boolean} [billable] + * @param {String} [policyID] * @returns {Object} data * @returns {String} data.payerEmail * @returns {Object} data.iouReport @@ -430,6 +455,7 @@ function getMoneyRequestInformation( category = undefined, tag = undefined, billable = undefined, + policyID = undefined, ) { const payerEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login); const payerAccountID = Number(participant.accountID); @@ -592,6 +618,7 @@ function getMoneyRequestInformation( optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, + policyID, ); return { @@ -839,6 +866,9 @@ function updateDistanceRequest(transactionID, transactionThreadReportID, transac * @param {String} [category] * @param {String} [tag] * @param {Boolean} [billable] + * @param {String} [policyID] + * @param {Object} [policyTags] + * @param {Object} [policyCategories] */ function requestMoney( report, @@ -854,12 +884,29 @@ function requestMoney( category = undefined, tag = undefined, billable = undefined, + policyID = undefined, ) { // If the report is 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; const {payerAccountID, payerEmail, iouReport, chatReport, transaction, iouAction, createdChatReportActionID, createdIOUReportActionID, reportPreviewAction, onyxData} = - getMoneyRequestInformation(currentChatReport, participant, comment, amount, currency, created, merchant, payeeAccountID, payeeEmail, receipt, undefined, category, tag, billable); + getMoneyRequestInformation( + currentChatReport, + participant, + comment, + amount, + currency, + created, + merchant, + payeeAccountID, + payeeEmail, + receipt, + undefined, + category, + tag, + billable, + policyID, + ); API.write( 'RequestMoney', diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index ebb687b324e8..0d3810bb34d2 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -50,12 +50,29 @@ const propTypes = { /** Personal details of all users */ personalDetails: personalDetailsPropType, + /** The policy of the current report */ + policy: PropTypes.shape({ + /** Whether the policy requires a tag */ + requiresTag: PropTypes.bool, + + /** Whether the policy requires a category */ + requiresCategory: PropTypes.bool, + + /** Whether there is more than one list of tags */ + hasMultipleTagLists: PropTypes.bool, + + /** Whether the policy has enable tax tracking */ + isTrackingTaxEnabled: PropTypes.bool, + }), + ...withCurrentUserPersonalDetailsPropTypes, }; const defaultProps = { report: {}, personalDetails: {}, + policyCategories: {}, + policyTags: {}, iou: iouDefaultProps, ...withCurrentUserPersonalDetailsDefaultProps, }; @@ -173,6 +190,7 @@ function MoneyRequestConfirmPage(props) { props.iou.category, props.iou.tag, props.iou.billable, + props.policy.id, ); }, [ @@ -186,6 +204,7 @@ function MoneyRequestConfirmPage(props) { props.iou.category, props.iou.tag, props.iou.billable, + props.policy.id, ], ); @@ -430,6 +449,15 @@ export default compose( selectedTab: { key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`, }, + policy: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, + }, + policyCategories: { + key: ONYXKEYS.POLICY_CATEGORIES, + }, + policyTags: { + key: ONYXKEYS.POLICY_TAGS, + }, }), // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ From 8fe667dcce7a3ef6500ea4d553b442ff700469a9 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 28 Nov 2023 09:34:24 -0500 Subject: [PATCH 02/22] Updated withPolicy with new properties and also passed through to IOU functions --- src/libs/actions/IOU.js | 60 +++++++++++-------- .../iou/steps/MoneyRequestConfirmPage.js | 28 +++++---- src/pages/workspace/withPolicy.tsx | 14 +++++ 3 files changed, 65 insertions(+), 37 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index cccde7259cd6..7469a4e57392 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -19,7 +19,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as UserUtils from '@libs/UserUtils'; -import ViolationsUtils from '@libs/ViolationsUtils'; +import ViolationsUtils from '@libs/Violations/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -78,19 +78,19 @@ Onyx.connect({ }, }); -let allPolicyTags = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.POLICY_TAGS, - waitForCollectionCallback: true, - callback: (value) => { - if (!value) { - allPolicyTags = {}; - return; - } +// let allPolicyTags = {}; +// Onyx.connect({ +// key: ONYXKEYS.COLLECTION.POLICY_TAGS, +// waitForCollectionCallback: true, +// callback: (value) => { +// if (!value) { +// allPolicyTags = {}; +// return; +// } - allPolicyTags = value; - }, -}); +// allPolicyTags = value; +// }, +// }); let userAccountID = ''; let currentUserEmail = ''; @@ -155,7 +155,9 @@ function buildOnyxDataForMoneyRequest( optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, - policyID, + policy, + policyTags, + policyCategories, ) { const optimisticData = [ { @@ -382,12 +384,9 @@ function buildOnyxDataForMoneyRequest( }, ]; - if (!policyID) { + if (!policy.id) { return [optimisticData, successData, failureData]; } - const policy = ReportUtils.getPolicy(policyID); - const policyTags = ReportUtils.getPolicyTags(policyID); - const policyCategories = ReportUtils.getPolicyCategories(policyID); const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories); @@ -425,7 +424,9 @@ function buildOnyxDataForMoneyRequest( * @param {String} [category] * @param {String} [tag] * @param {Boolean} [billable] - * @param {String} [policyID] + * @param {Object} [policy] + * @param {Object} [policyTags] + * @param {Object} [policyCategories] * @returns {Object} data * @returns {String} data.payerEmail * @returns {Object} data.iouReport @@ -455,7 +456,9 @@ function getMoneyRequestInformation( category = undefined, tag = undefined, billable = undefined, - policyID = undefined, + policy = undefined, + policyTags = undefined, + policyCategories = undefined, ) { const payerEmail = OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login); const payerAccountID = Number(participant.accountID); @@ -531,7 +534,8 @@ function getMoneyRequestInformation( } const optimisticPolicyRecentlyUsedTags = {}; - const policyTags = allPolicyTags[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${iouReport.policyID}`]; + // TODO: Remove the following line once everything is tested + // const policyTags = allPolicyTags[`${ONYXKEYS.COLLECTION.POLICY_TAGS}${iouReport.policyID}`]; const recentlyUsedPolicyTags = allRecentlyUsedTags[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`]; if (policyTags) { @@ -618,7 +622,9 @@ function getMoneyRequestInformation( optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, - policyID, + policy, + policyTags, + policyCategories, ); return { @@ -866,7 +872,7 @@ function updateDistanceRequest(transactionID, transactionThreadReportID, transac * @param {String} [category] * @param {String} [tag] * @param {Boolean} [billable] - * @param {String} [policyID] + * @param {Object} [policy] * @param {Object} [policyTags] * @param {Object} [policyCategories] */ @@ -884,7 +890,9 @@ function requestMoney( category = undefined, tag = undefined, billable = undefined, - policyID = undefined, + policy = undefined, + policyTags = undefined, + policyCategories = undefined, ) { // If the report is iou or expense report, we should get the linked chat report to be passed to the getMoneyRequestInformation function const isMoneyRequestReport = ReportUtils.isMoneyRequestReport(report); @@ -905,7 +913,9 @@ function requestMoney( category, tag, billable, - policyID, + policy, + policyTags, + policyCategories, ); API.write( diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 0d3810bb34d2..4ccd47166634 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -22,6 +22,7 @@ import * as ReportUtils from '@libs/ReportUtils'; import {iouDefaultProps, iouPropTypes} from '@pages/iou/propTypes'; import personalDetailsPropType from '@pages/personalDetailsPropType'; import reportPropTypes from '@pages/reportPropTypes'; +import {policyDefaultProps, policyPropTypes} from '@pages/workspace/withPolicy'; import useThemeStyles from '@styles/useThemeStyles'; import * as IOU from '@userActions/IOU'; import * as Policy from '@userActions/Policy'; @@ -51,18 +52,16 @@ const propTypes = { personalDetails: personalDetailsPropType, /** The policy of the current report */ - policy: PropTypes.shape({ - /** Whether the policy requires a tag */ - requiresTag: PropTypes.bool, + policy: policyPropTypes, - /** Whether the policy requires a category */ - requiresCategory: PropTypes.bool, - - /** Whether there is more than one list of tags */ - hasMultipleTagLists: PropTypes.bool, + policyTags: PropTypes.shape({ + /** List of tags */ + tags: PropTypes.arrayOf(PropTypes.string), + }), - /** Whether the policy has enable tax tracking */ - isTrackingTaxEnabled: PropTypes.bool, + policyCategories: PropTypes.shape({ + /** List of categories */ + categories: PropTypes.arrayOf(PropTypes.string), }), ...withCurrentUserPersonalDetailsPropTypes, @@ -74,6 +73,7 @@ const defaultProps = { policyCategories: {}, policyTags: {}, iou: iouDefaultProps, + policy: policyDefaultProps, ...withCurrentUserPersonalDetailsDefaultProps, }; @@ -190,7 +190,9 @@ function MoneyRequestConfirmPage(props) { props.iou.category, props.iou.tag, props.iou.billable, - props.policy.id, + props.policy, + props.policyTags, + props.policyCategories, ); }, [ @@ -204,7 +206,9 @@ function MoneyRequestConfirmPage(props) { props.iou.category, props.iou.tag, props.iou.billable, - props.policy.id, + props.policy, + props.policyTags, + props.policyCategories, ], ); diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index 8db093ec24d0..96b89825fb6f 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -51,6 +51,20 @@ const policyPropTypes = { * } */ errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), + + /** Whether or not the policy requires tags */ + requiresTags: PropTypes.bool, + + /** Whether or not the policy requires categories */ + requiresCategories: PropTypes.bool, + + /** Whether or not the policy has multiple tag lists */ + hasMultipleTagLists: PropTypes.bool, + + /** Whether or not the policy has tax tracking enabled */ + isTrackingTaxEnabled: PropTypes.bool, + + /** */ }), /** The employee list of this policy */ From 1cd0e08aac80489901ddc5d177e4b83266becb25 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 28 Nov 2023 10:10:56 -0500 Subject: [PATCH 03/22] Added some logs for testing -- remove these --- src/libs/Violations/ViolationsUtils.ts | 2 ++ src/libs/actions/IOU.js | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/libs/Violations/ViolationsUtils.ts b/src/libs/Violations/ViolationsUtils.ts index 28f5aedf10b9..b5b31d789211 100644 --- a/src/libs/Violations/ViolationsUtils.ts +++ b/src/libs/Violations/ViolationsUtils.ts @@ -58,6 +58,8 @@ const ViolationsUtils = { } } + // TODO: Remove the following line once everything is tested + console.log('ViolationsUtils.getViolationsOnyxData', newTransactionViolations); return { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 7469a4e57392..95d8725b39f8 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -388,8 +388,12 @@ function buildOnyxDataForMoneyRequest( return [optimisticData, successData, failureData]; } + // TODO: Remove the following line once everything is tested + console.log('POLICY: ', policy); const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories); + // TODO: Remove the following line once everything is tested + console.log('ONYXDATA', violationsOnyxData); if (violationsOnyxData) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From 6f84a871c1fd32d2b198270e824de611e36fa1c7 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 5 Dec 2023 11:57:59 -0500 Subject: [PATCH 04/22] remove unused export --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index dae93fd2c3c6..ec4e477a67de 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4279,7 +4279,6 @@ export { getParentNavigationSubtitle, getPolicyName, getPolicyType, - getPolicyCategories, getPolicyTags, isArchivedRoom, isExpensifyOnlyParticipantInReport, From f6f9cac5d14d5c79ca96faa9fc0d7ed2b5f0b8ca Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 5 Dec 2023 16:08:19 -0500 Subject: [PATCH 05/22] Remove console.log statements and fix import path in IOU.js --- src/libs/ViolationsUtils.ts | 2 -- src/libs/actions/IOU.js | 8 ++------ 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/libs/ViolationsUtils.ts b/src/libs/ViolationsUtils.ts index bb834d5fcb1c..4cfa259c9e78 100644 --- a/src/libs/ViolationsUtils.ts +++ b/src/libs/ViolationsUtils.ts @@ -74,8 +74,6 @@ const ViolationsUtils = { } } - // TODO: Remove the following line once everything is tested - console.log('ViolationsUtils.getViolationsOnyxData', newTransactionViolations); return { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index e06b863bb6b0..4a6e191e5fc9 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -19,7 +19,7 @@ import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; import * as UserUtils from '@libs/UserUtils'; -import ViolationsUtils from '@libs/Violations/ViolationsUtils'; +import ViolationsUtils from '@libs/ViolationsUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -356,16 +356,12 @@ function buildOnyxDataForMoneyRequest( }, ]; - if (!policy.id) { + if (!policy || !policy.id) { return [optimisticData, successData, failureData]; } - // TODO: Remove the following line once everything is tested - console.log('POLICY: ', policy); const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories); - // TODO: Remove the following line once everything is tested - console.log('ONYXDATA', violationsOnyxData); if (violationsOnyxData) { optimisticData.push({ onyxMethod: Onyx.METHOD.MERGE, From 9a041ccb538c50aee24cc51ff578cc51c7cb232c Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 5 Dec 2023 16:51:44 -0500 Subject: [PATCH 06/22] Remove unused function getPolicyTags --- src/libs/ReportUtils.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6ce2e68f3dbf..c444187cbd10 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4287,7 +4287,6 @@ export { getParentNavigationSubtitle, getPolicyName, getPolicyType, - getPolicyTags, isArchivedRoom, isExpensifyOnlyParticipantInReport, canCreateTaskInReport, From 150487e5453c7330abd0ebd9b65e49f4958bf857 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Wed, 6 Dec 2023 12:31:47 -0500 Subject: [PATCH 07/22] Fixed withOnyx call --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index c34f4191c958..7bc865b6e667 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -450,16 +450,10 @@ export default compose( key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, policyCategories: { - key: ONYXKEYS.POLICY_CATEGORIES, + key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy ? policy.id : '0'}`, }, policyTags: { - key: ONYXKEYS.POLICY_TAGS, - }, - }), - // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file - withOnyx({ - policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, + key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy ? policy.id : '0'}`, }, }), )(MoneyRequestConfirmPage); From 6c3015840738aefdf232ea23a98cb07e03265dd6 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:39:58 -0500 Subject: [PATCH 08/22] Update src/libs/actions/IOU.js Co-authored-by: Carlos Alvarez --- src/libs/actions/IOU.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 4a6e191e5fc9..c92ef5e11ce5 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -356,6 +356,7 @@ function buildOnyxDataForMoneyRequest( }, ]; + // Policy won't be set for P2P cases for which we don't need to compute violations if (!policy || !policy.id) { return [optimisticData, successData, failureData]; } From 705329cd823f683a7943bf0805150c6f0d939d63 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:40:05 -0500 Subject: [PATCH 09/22] Update src/pages/workspace/withPolicy.tsx Co-authored-by: Carlos Alvarez --- src/pages/workspace/withPolicy.tsx | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index 8ed6be67ebf8..5931d483b519 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -63,8 +63,6 @@ const policyPropTypes = { /** Whether or not the policy has tax tracking enabled */ isTrackingTaxEnabled: PropTypes.bool, - - /** */ }), /** The employee list of this policy */ From c93a59df1f0262aa87fc7e6b8028f6f6e5aec0ef Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:40:11 -0500 Subject: [PATCH 10/22] Update src/pages/iou/steps/MoneyRequestConfirmPage.js Co-authored-by: Carlos Alvarez --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 7bc865b6e667..f0ca0233cf33 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -48,7 +48,7 @@ const propTypes = { /** Holds data related to Money Request view state, rather than the underlying Money Request data. */ iou: iouPropTypes, - /** The policy of the current report */ + /** The policy of the current request */ policy: policyPropTypes, policyTags: PropTypes.shape({ From b6e959fe626acbdec8446229f3848908dee479dd Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:53:25 -0500 Subject: [PATCH 11/22] Update src/pages/workspace/withPolicy.tsx Co-authored-by: Luthfi --- src/pages/workspace/withPolicy.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index 5931d483b519..de8e6e29e29a 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -62,7 +62,7 @@ const policyPropTypes = { hasMultipleTagLists: PropTypes.bool, /** Whether or not the policy has tax tracking enabled */ - isTrackingTaxEnabled: PropTypes.bool, + isTaxTrackingEnabled: PropTypes.bool, }), /** The employee list of this policy */ From f0c609ba591404248ede8c55820cc9091ff79215 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:53:37 -0500 Subject: [PATCH 12/22] Update src/pages/workspace/withPolicy.tsx Co-authored-by: Luthfi --- src/pages/workspace/withPolicy.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index de8e6e29e29a..7a43f3f55825 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -53,7 +53,7 @@ const policyPropTypes = { errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)), /** Whether or not the policy requires tags */ - requiresTags: PropTypes.bool, + requiresTag: PropTypes.bool, /** Whether or not the policy requires categories */ requiresCategories: PropTypes.bool, From dbf3e5a5c90c10604fde511831f993a95858f48d Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:53:45 -0500 Subject: [PATCH 13/22] Update src/pages/workspace/withPolicy.tsx Co-authored-by: Luthfi --- src/pages/workspace/withPolicy.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/workspace/withPolicy.tsx b/src/pages/workspace/withPolicy.tsx index 7a43f3f55825..3528a6fcd4bd 100644 --- a/src/pages/workspace/withPolicy.tsx +++ b/src/pages/workspace/withPolicy.tsx @@ -56,7 +56,7 @@ const policyPropTypes = { requiresTag: PropTypes.bool, /** Whether or not the policy requires categories */ - requiresCategories: PropTypes.bool, + requiresCategory: PropTypes.bool, /** Whether or not the policy has multiple tag lists */ hasMultipleTagLists: PropTypes.bool, From 9783c47d1f335a3fd28ae77f6022b5b302199a5d Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Mon, 11 Dec 2023 10:53:55 -0500 Subject: [PATCH 14/22] Update src/libs/actions/IOU.js Co-authored-by: Luthfi --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index c92ef5e11ce5..b19cfdb41eab 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -361,7 +361,7 @@ function buildOnyxDataForMoneyRequest( return [optimisticData, successData, failureData]; } - const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTags, policyTags, policy.requiresCategory, policyCategories); + const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTag, policyTags, policy.requiresCategory, policyCategories); if (violationsOnyxData) { optimisticData.push({ From 3c0b52c349d8bfdfe6f44819ee253d4cc22a37c6 Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Wed, 13 Dec 2023 09:48:39 -0500 Subject: [PATCH 15/22] Updated proptypes and reimplemented the second withonyx --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 13c929b61ac3..37f5232705cc 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -4,11 +4,13 @@ import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; +import categoryPropTypes from '@components/categoryPropTypes'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; import MoneyRequestConfirmationList from '@components/MoneyRequestConfirmationList'; import {usePersonalDetails} from '@components/OnyxProvider'; import ScreenWrapper from '@components/ScreenWrapper'; +import tagPropTypes from '@components/tagPropTypes'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails'; import withLocalize from '@components/withLocalize'; import useInitialValue from '@hooks/useInitialValue'; @@ -51,15 +53,9 @@ const propTypes = { /** The policy of the current report */ policy: policyPropTypes, - policyTags: PropTypes.shape({ - /** List of tags */ - tags: PropTypes.arrayOf(PropTypes.string), - }), + policyTags: tagPropTypes, - policyCategories: PropTypes.shape({ - /** List of categories */ - categories: PropTypes.arrayOf(PropTypes.string), - }), + policyCategories: PropTypes.objectOf(categoryPropTypes), ...withCurrentUserPersonalDetailsPropTypes, }; @@ -446,14 +442,16 @@ export default compose( selectedTab: { key: `${ONYXKEYS.COLLECTION.SELECTED_TAB}${CONST.TAB.RECEIPT_TAB_ID}`, }, + }), + withOnyx({ policy: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, policyCategories: { - key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy ? policy.id : '0'}`, + key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy.id}`, }, policyTags: { - key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy ? policy.id : '0'}`, + key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy.id}`, }, }), )(MoneyRequestConfirmPage); From 633199bd22b516f513453aaf0d97cb0cacbb9402 Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Fri, 15 Dec 2023 14:23:13 -0800 Subject: [PATCH 16/22] Fix withOnyx references --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index b770455519e6..3a6b8cb74529 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -448,10 +448,10 @@ export default compose( key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, }, policyCategories: { - key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policy.id}`, + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, }, policyTags: { - key: ({policy}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policy.id}`, + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, }, }), )(MoneyRequestConfirmPage); From 919f967523e9ef169482d2aa89aa60b825e32876 Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Mon, 18 Dec 2023 14:43:49 -0800 Subject: [PATCH 17/22] Add policy data to new verison of money request confirmation screen --- .../step/IOURequestStepConfirmation.js | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 1f458ef37f01..2560c509740a 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -1,12 +1,15 @@ import lodashGet from 'lodash/get'; +import PropTypes from 'prop-types'; import React, {useCallback, useEffect, useMemo, useState} from 'react'; import {View} from 'react-native'; import {withOnyx} from 'react-native-onyx'; import _ from 'underscore'; +import categoryPropTypes from '@components/categoryPropTypes'; import HeaderWithBackButton from '@components/HeaderWithBackButton'; import * as Expensicons from '@components/Icon/Expensicons'; import MoneyRequestConfirmationList from '@components/MoneyTemporaryForRefactorRequestConfirmationList'; import ScreenWrapper from '@components/ScreenWrapper'; +import tagPropTypes from '@components/tagPropTypes'; import transactionPropTypes from '@components/transactionPropTypes'; import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsDefaultProps, withCurrentUserPersonalDetailsPropTypes} from '@components/withCurrentUserPersonalDetails'; import useLocalize from '@hooks/useLocalize'; @@ -46,6 +49,12 @@ const propTypes = { /** The policy of the report */ ...policyPropTypes, + /** The tag configuration of the report's policy */ + policyTags: tagPropTypes, + + /** The category configuration of the report's policy */ + policyCategories: PropTypes.objectOf(categoryPropTypes), + /** The full IOU report */ report: reportPropTypes, @@ -55,6 +64,8 @@ const propTypes = { const defaultProps = { personalDetails: {}, policy: {}, + policyCategories: {}, + policyTags: {}, report: {}, transaction: {}, ...withCurrentUserPersonalDetailsDefaultProps, @@ -63,6 +74,8 @@ function IOURequestStepConfirmation({ currentUserPersonalDetails, personalDetails, policy, + policyTags, + policyCategories, report, route: { params: {iouType, reportID, transactionID}, @@ -163,6 +176,9 @@ function IOURequestStepConfirmation({ transaction.category, transaction.tag, transaction.billable, + policy, + policyTags, + policyCategories, ); }, [report, transaction, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID], @@ -366,7 +382,13 @@ export default compose( // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ policy: { - key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${lodashGet(report, 'policyID', '0')}`, + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`, + }, + policyCategories: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`, + }, + policyTags: { + key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, }, }), )(IOURequestStepConfirmation); From 0f91f22975695d26e66ace3d13d83413667cea82 Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Mon, 18 Dec 2023 20:54:53 -0800 Subject: [PATCH 18/22] Fix hook dependencies --- .../request/step/IOURequestStepConfirmation.js | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js index 3a62168c9c48..9d725ee34d8c 100644 --- a/src/pages/iou/request/step/IOURequestStepConfirmation.js +++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js @@ -178,7 +178,7 @@ function IOURequestStepConfirmation({ policyCategories, ); }, - [report, transaction, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID], + [report, transaction, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, policy, policyTags, policyCategories], ); /** @@ -261,21 +261,7 @@ function IOURequestStepConfirmation({ requestMoney(selectedParticipants, trimmedComment); }, - [ - iouType, - transaction, - currentUserPersonalDetails.login, - currentUserPersonalDetails.accountID, - report, - reportID, - requestType, - createDistanceRequest, - requestMoney, - receiptFile, - policy, - policyTags, - policyCategories, - ], + [iouType, transaction, currentUserPersonalDetails.login, currentUserPersonalDetails.accountID, report, reportID, requestType, createDistanceRequest, requestMoney, receiptFile], ); /** From e5b607e3812f00a4558452470167c73c788413ec Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Tue, 19 Dec 2023 11:11:40 -0800 Subject: [PATCH 19/22] Fix transaction violation storage use data from utility function directly --- src/libs/actions/IOU.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 9c9c9d9d5883..893809f40ebc 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -554,11 +554,7 @@ function buildOnyxDataForMoneyRequest( const violationsOnyxData = ViolationsUtils.getViolationsOnyxData(transaction, [], policy.requiresTag, policyTags, policy.requiresCategory, policyCategories); if (violationsOnyxData) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, - value: violationsOnyxData, - }); + optimisticData.push(violationsOnyxData); failureData.push({ onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, From a8741abee22cf5300b7ca98af9963b6afbf9ce5c Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Tue, 19 Dec 2023 11:35:16 -0800 Subject: [PATCH 20/22] Use SET instead Avoid mixing SET and MERGE for the same key --- src/libs/actions/IOU.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 893809f40ebc..ea29ae75387c 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -556,7 +556,7 @@ function buildOnyxDataForMoneyRequest( if (violationsOnyxData) { optimisticData.push(violationsOnyxData); failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, + onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.TRANSACTION_VIOLATIONS}${transaction.transactionID}`, value: [], }); From 8d417a9fcb574be07168835eb968824570e135e3 Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Tue, 19 Dec 2023 16:35:16 -0800 Subject: [PATCH 21/22] 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( From ab06fbee62b46aff727b1a29805736998e5ad6ad Mon Sep 17 00:00:00 2001 From: Lizzi Lindboe Date: Wed, 3 Jan 2024 11:36:29 -0800 Subject: [PATCH 22/22] Use policy arg for fetching paid policy info --- src/libs/actions/IOU.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 78429cfcc724..dc24f5b7b4a8 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -685,8 +685,7 @@ function getMoneyRequestInformation( let needsToBeManuallySubmitted = false; let isFromPaidPolicy = false; if (isPolicyExpenseChat) { - const fetchedPolicy = ReportUtils.getPolicy(chatReport.policyID); - isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(fetchedPolicy); + isFromPaidPolicy = PolicyUtils.isPaidGroupPolicy(policy); // If the scheduled submit is turned off on the policy, user needs to manually submit the report which is indicated by GBR in LHN needsToBeManuallySubmitted = isFromPaidPolicy && !(policy.isHarvestingEnabled || false);