From e4135d11d975a2529da9c2ef39b8c5386058c74d Mon Sep 17 00:00:00 2001 From: Daniel Edwards Date: Tue, 21 Nov 2023 11:23:44 -0500 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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);