From ad42f5ac57fc0b96b9aacd36504c1aa377e4cd04 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 20 Sep 2023 11:43:39 +0200 Subject: [PATCH 01/40] re-test From d07017bbcf5de6c5933a2d91dc970840c0161bc7 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 20 Sep 2023 12:54:51 +0200 Subject: [PATCH 02/40] connect report of participants of MoneyRequestCategoryPage --- src/pages/iou/MoneyRequestCategoryPage.js | 26 ++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/pages/iou/MoneyRequestCategoryPage.js b/src/pages/iou/MoneyRequestCategoryPage.js index 80b88a762609..ac4cae65229c 100644 --- a/src/pages/iou/MoneyRequestCategoryPage.js +++ b/src/pages/iou/MoneyRequestCategoryPage.js @@ -4,6 +4,7 @@ import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; import ROUTES from '../../ROUTES'; import Navigation from '../../libs/Navigation/Navigation'; +import compose from '../../libs/compose'; import useLocalize from '../../hooks/useLocalize'; import ScreenWrapper from '../../components/ScreenWrapper'; import HeaderWithBackButton from '../../components/HeaderWithBackButton'; @@ -65,8 +66,23 @@ MoneyRequestCategoryPage.displayName = 'MoneyRequestCategoryPage'; MoneyRequestCategoryPage.propTypes = propTypes; MoneyRequestCategoryPage.defaultProps = defaultProps; -export default withOnyx({ - report: { - key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${lodashGet(route, 'params.reportID', '')}`, - }, -})(MoneyRequestCategoryPage); +export default compose( + withOnyx({ + iou: { + key: ONYXKEYS.IOU, + }, + }), + withOnyx({ + report: { + key: ({route, iou}) => { + let reportID = lodashGet(route, 'params.reportID', ''); + if (!reportID) { + // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. + // Get the report id from the participants list on the IOU object stored in Onyx. + reportID = lodashGet(iou, 'participants.0.reportID', ''); + } + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; + }, + }, + }), +)(MoneyRequestCategoryPage); From 16a1bbaa488c1030bc7437564409e526e11d1e42 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 20 Sep 2023 16:01:45 +0200 Subject: [PATCH 03/40] attach category to split bill request --- src/libs/actions/IOU.js | 28 ++++++++++++++----- .../iou/steps/MoneyRequestConfirmPage.js | 3 ++ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 9e8dadbd53b7..9f2c71bf37f1 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -669,11 +669,12 @@ function requestMoney(report, amount, currency, created, merchant, payeeEmail, p * @param {Number} amount - always in the smallest unit of the currency * @param {String} comment * @param {String} currency + * @param {String} category * @param {String} existingSplitChatReportID - the report ID where the split bill happens, could be a group chat or a workspace chat * * @return {Object} */ -function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, existingSplitChatReportID = '') { +function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '') { const currentUserEmailForIOUSplit = OptionsListUtils.addSMSDomainIfPhoneNumber(currentUserLogin); const participantAccountIDs = _.map(participants, (participant) => Number(participant.accountID)); const existingSplitChatReport = @@ -697,6 +698,10 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco '', '', `${Localize.translateLocal('iou.splitBill')} ${Localize.translateLocal('common.with')} ${formattedParticipants} [${DateUtils.getDBTime().slice(0, 10)}]`, + undefined, + undefined, + undefined, + category, ); // Note: The created action must be optimistically generated before the IOU action so there's no chance that the created action appears after the IOU action in the chat @@ -824,8 +829,8 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco const hasMultipleParticipants = participants.length > 1; _.each(participants, (participant) => { // In case the participant is a worskapce, email & accountID should remain undefined and won't be used in the rest of this code - const email = isOwnPolicyExpenseChat ? '' : OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login).toLowerCase(); - const accountID = isOwnPolicyExpenseChat ? 0 : Number(participant.accountID); + const email = isOwnPolicyExpenseChat ? '' : OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login || '').toLowerCase(); + const accountID = isOwnPolicyExpenseChat ? 0 : Number(participant.accountID) || 0; if (email === currentUserEmailForIOUSplit) { return; } @@ -877,6 +882,11 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco '', CONST.IOU.MONEY_REQUEST_TYPE.SPLIT, splitTransaction.transactionID, + undefined, + undefined, + undefined, + undefined, + category, ); // STEP 4: Build optimistic reportActions. We need: @@ -976,10 +986,11 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco * @param {Number} amount - always in smallest currency unit * @param {String} comment * @param {String} currency + * @param {String} category * @param {String} existingSplitChatReportID - Either a group DM or a workspace chat */ -function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, existingSplitChatReportID = '') { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, existingSplitChatReportID); +function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '') { + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID); API.write( 'SplitBill', @@ -989,6 +1000,7 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, splits: JSON.stringify(splits), currency, comment, + category, transactionID: splitData.transactionID, reportActionID: splitData.reportActionID, createdReportActionID: splitData.createdReportActionID, @@ -1009,9 +1021,10 @@ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, * @param {Number} amount - always in smallest currency unit * @param {String} comment * @param {String} currency + * @param {String} category */ -function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency) { - const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency); +function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category) { + const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category); API.write( 'SplitBillAndOpenReport', @@ -1021,6 +1034,7 @@ function splitBillAndOpenReport(participants, currentUserLogin, currentUserAccou splits: JSON.stringify(splits), currency, comment, + category, transactionID: splitData.transactionID, reportActionID: splitData.reportActionID, createdReportActionID: splitData.createdReportActionID, diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 224f661915d8..e22254ff19d0 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -192,6 +192,7 @@ function MoneyRequestConfirmPage(props) { props.iou.amount, trimmedComment, props.iou.currency, + props.iou.category, reportID.current, ); return; @@ -206,6 +207,7 @@ function MoneyRequestConfirmPage(props) { props.iou.amount, trimmedComment, props.iou.currency, + props.iou.category, ); return; } @@ -230,6 +232,7 @@ function MoneyRequestConfirmPage(props) { props.currentUserPersonalDetails.login, props.currentUserPersonalDetails.accountID, props.iou.currency, + props.iou.category, props.iou.receiptPath, props.iou.receiptSource, isDistanceRequest, From 576ad9391f396b24523a7a664ff1ac2d8e3239aa Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 21 Sep 2023 14:54:47 +0200 Subject: [PATCH 04/40] fix crash when a participant a workspace --- src/libs/actions/IOU.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index dbbebce3a5cb..75049004063f 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -886,9 +886,11 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco const hasMultipleParticipants = participants.length > 1; _.each(participants, (participant) => { + const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(participant); + // In case the participant is a worskapce, email & accountID should remain undefined and won't be used in the rest of this code - const email = isOwnPolicyExpenseChat ? '' : OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login || '').toLowerCase(); - const accountID = isOwnPolicyExpenseChat ? 0 : Number(participant.accountID) || 0; + const email = isOwnPolicyExpenseChat || isPolicyExpenseChat ? '' : OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login).toLowerCase(); + const accountID = isOwnPolicyExpenseChat || isPolicyExpenseChat ? 0 : Number(participant.accountID); if (email === currentUserEmailForIOUSplit) { return; } @@ -1050,7 +1052,6 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco */ function splitBill(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID = '') { const {splitData, splits, onyxData} = createSplitsAndOnyxData(participants, currentUserLogin, currentUserAccountID, amount, comment, currency, category, existingSplitChatReportID); - API.write( 'SplitBill', { From f4f86d8538a055ce6f9c4e30fe9f89be0357c854 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 21 Sep 2023 15:18:01 +0200 Subject: [PATCH 05/40] fix policy and report props of MoneyRequestConfirmationList --- 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 f9d80e784e22..6b90a4bc5f37 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -322,14 +322,14 @@ function MoneyRequestConfirmPage(props) { receiptPath={props.iou.receiptPath} receiptSource={props.iou.receiptSource} iouType={iouType.current} - reportID={reportID.current} + reportID={reportID.current || lodashGet(props.iou, 'participants.0.reportID', '')} // The participants can only be modified when the action is initiated from directly within a group chat and not the floating-action-button. // This is because when there is a group of people, say they are on a trip, and you have some shared expenses with some of the people, // but not all of them (maybe someone skipped out on dinner). Then it's nice to be able to select/deselect people from the group chat bill // split rather than forcing the user to create a new group, just for that expense. The reportID is empty, when the action was initiated from // the floating-action-button (since it is something that exists outside the context of a report). canModifyParticipants={!_.isEmpty(reportID.current)} - policyID={props.report.policyID} + policyID={props.policy.id} bankAccountRoute={ReportUtils.getBankAccountRoute(props.report)} iouMerchant={props.iou.merchant} iouCreated={props.iou.created} From e7ba3fc0716f3c11f5ea166b0b969f6ad70eafd2 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 21 Sep 2023 15:20:42 +0200 Subject: [PATCH 06/40] fix props --- 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 6b90a4bc5f37..c43635d484d3 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -329,7 +329,7 @@ function MoneyRequestConfirmPage(props) { // split rather than forcing the user to create a new group, just for that expense. The reportID is empty, when the action was initiated from // the floating-action-button (since it is something that exists outside the context of a report). canModifyParticipants={!_.isEmpty(reportID.current)} - policyID={props.policy.id} + policyID={props.report.policyID} bankAccountRoute={ReportUtils.getBankAccountRoute(props.report)} iouMerchant={props.iou.merchant} iouCreated={props.iou.created} From aa8f4f6f409a37fda24c48c2a5f093f656d50cab Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 21 Sep 2023 15:46:12 +0200 Subject: [PATCH 07/40] fix adding recently categories --- src/libs/actions/IOU.js | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 75049004063f..6b3c82eb21fb 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -465,13 +465,16 @@ function getMoneyRequestInformation( billable, ); - const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories - ? _.filter( - allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`], - (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category, - ) - : []; - const optimisticPolicyRecentlyUsedCategories = [category, ...uniquePolicyRecentlyUsedCategories]; + let optimisticPolicyRecentlyUsedCategories; + if (category) { + const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories + ? _.filter( + allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`], + (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category, + ) + : []; + optimisticPolicyRecentlyUsedCategories = [category, ...uniquePolicyRecentlyUsedCategories]; + } const optimisticPolicyRecentlyUsedTags = {}; const recentlyUsedPolicyTags = allRecentlyUsedTags[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`]; From 495894eae7a3e5aa89b3c782ed8e686e91e97291 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 21 Sep 2023 15:54:12 +0200 Subject: [PATCH 08/40] add recently categories for split bills optimistic --- src/libs/actions/IOU.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 6b3c82eb21fb..f793d7e776c4 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -990,6 +990,17 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport); } + let optimisticPolicyRecentlyUsedCategories; + if (category && isPolicyExpenseChat) { + const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories + ? _.filter( + allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${participant.policyID}`], + (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category, + ) + : []; + optimisticPolicyRecentlyUsedCategories = [category, ...uniquePolicyRecentlyUsedCategories]; + } + // STEP 5: Build Onyx Data const [oneOnOneOptimisticData, oneOnOneSuccessData, oneOnOneFailureData] = buildOnyxDataForMoneyRequest( oneOnOneChatReport, @@ -1000,7 +1011,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco oneOnOneIOUAction, oneOnOnePersonalDetailListAction, oneOnOneReportPreviewAction, - [], + optimisticPolicyRecentlyUsedCategories, {}, isNewOneOnOneChatReport, shouldCreateNewOneOnOneIOUReport, From cd5a6c2687e321ec1aa6436ad56baa509facd7ab Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 21 Sep 2023 19:13:35 +0200 Subject: [PATCH 09/40] use one withOnyx --- src/pages/iou/MoneyRequestCategoryPage.js | 35 ++++++++++------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/pages/iou/MoneyRequestCategoryPage.js b/src/pages/iou/MoneyRequestCategoryPage.js index 246e94a6e261..5e94ec498b01 100644 --- a/src/pages/iou/MoneyRequestCategoryPage.js +++ b/src/pages/iou/MoneyRequestCategoryPage.js @@ -4,7 +4,6 @@ import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; import ROUTES from '../../ROUTES'; import Navigation from '../../libs/Navigation/Navigation'; -import compose from '../../libs/compose'; import useLocalize from '../../hooks/useLocalize'; import ScreenWrapper from '../../components/ScreenWrapper'; import HeaderWithBackButton from '../../components/HeaderWithBackButton'; @@ -83,23 +82,19 @@ MoneyRequestCategoryPage.displayName = 'MoneyRequestCategoryPage'; MoneyRequestCategoryPage.propTypes = propTypes; MoneyRequestCategoryPage.defaultProps = defaultProps; -export default compose( - withOnyx({ - iou: { - key: ONYXKEYS.IOU, +export default withOnyx({ + iou: { + key: ONYXKEYS.IOU, + }, + report: { + key: ({route, iou}) => { + let reportID = lodashGet(route, 'params.reportID', ''); + if (!reportID) { + // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. + // Get the report id from the participants list on the IOU object stored in Onyx. + reportID = lodashGet(iou, 'participants.0.reportID', ''); + } + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, - }), - withOnyx({ - report: { - key: ({route, iou}) => { - let reportID = lodashGet(route, 'params.reportID', ''); - if (!reportID) { - // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. - // Get the report id from the participants list on the IOU object stored in Onyx. - reportID = lodashGet(iou, 'participants.0.reportID', ''); - } - return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; - }, - }, - }), -)(MoneyRequestCategoryPage); + }, +})(MoneyRequestCategoryPage); From 57b61e5645a59f605419dffaab8172c0bd13bd4a Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 22 Sep 2023 14:05:26 +0200 Subject: [PATCH 10/40] add comments --- src/libs/actions/IOU.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 7183baebdd55..818f4ab9633b 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -889,9 +889,10 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco const hasMultipleParticipants = participants.length > 1; _.each(participants, (participant) => { + // In a case when a participant is a workspace, even when a current user is not an owner of the workspace const isPolicyExpenseChat = ReportUtils.isPolicyExpenseChat(participant); - // In case the participant is a worskapce, email & accountID should remain undefined and won't be used in the rest of this code + // In case the participant is a workspace, email & accountID should remain undefined and won't be used in the rest of this code const email = isOwnPolicyExpenseChat || isPolicyExpenseChat ? '' : OptionsListUtils.addSMSDomainIfPhoneNumber(participant.login).toLowerCase(); const accountID = isOwnPolicyExpenseChat || isPolicyExpenseChat ? 0 : Number(participant.accountID); if (email === currentUserEmailForIOUSplit) { @@ -990,6 +991,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco oneOnOneReportPreviewAction = ReportUtils.buildOptimisticReportPreview(oneOnOneChatReport, oneOnOneIOUReport); } + // Add category to optimistic policy recently used categories when a participant is a workspace let optimisticPolicyRecentlyUsedCategories; if (category && isPolicyExpenseChat) { const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories From a036c4da73ba6cbf9da4d9ee40a2ebdee479edf0 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 22 Sep 2023 15:11:11 +0200 Subject: [PATCH 11/40] move isPolicyExpenseChat to parent --- src/components/MoneyRequestConfirmationList.js | 10 +++++----- src/pages/iou/steps/MoneyRequestConfirmPage.js | 4 +++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 13471407914f..cdcb875f163f 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -137,6 +137,9 @@ const propTypes = { /** Whether the money request is a distance request */ isDistanceRequest: PropTypes.bool, + /** A flag for verifying that the current report is a workspace */ + isPolicyExpenseChat: PropTypes.bool.isRequired, + /* Onyx Props */ /** Collection of categories attached to a policy */ policyCategories: PropTypes.objectOf(categoryPropTypes), @@ -195,11 +198,8 @@ function MoneyRequestConfirmationList(props) { const distance = lodashGet(transaction, 'routes.route0.distance', 0); const shouldCalculateDistanceAmount = props.isDistanceRequest && props.iouAmount === 0; - // A flag for verifying that the current report is a sub-report of a workspace chat - const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(ReportUtils.getReport(props.reportID))), [props.reportID]); - // A flag for showing the categories field - const shouldShowCategories = isPolicyExpenseChat && Permissions.canUseCategories(props.betas) && OptionsListUtils.hasEnabledOptions(_.values(props.policyCategories)); + const shouldShowCategories = props.isPolicyExpenseChat && Permissions.canUseCategories(props.betas) && OptionsListUtils.hasEnabledOptions(_.values(props.policyCategories)); // Fetches the first tag list of the policy const tagListKey = _.first(_.keys(props.policyTags)); @@ -207,7 +207,7 @@ function MoneyRequestConfirmationList(props) { const tagListName = lodashGet(props.policyTags, [tagListKey, 'name'], ''); const canUseTags = Permissions.canUseTags(props.betas); // A flag for showing the tags field - const shouldShowTags = isPolicyExpenseChat && canUseTags && _.any(tagList, (tag) => tag.enabled); + const shouldShowTags = props.isPolicyExpenseChat && canUseTags && _.any(tagList, (tag) => tag.enabled); // A flag for showing the billable field const shouldShowBillable = canUseTags && !lodashGet(props.policy, 'disabledFields.defaultBillable', true); diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 3b9f7dcebcfa..5916e0662c99 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -74,6 +74,7 @@ function MoneyRequestConfirmPage(props) { }), [props.iou.participants, props.personalDetails], ); + const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(props.report)), [props.report]); useEffect(() => { const policyExpenseChat = _.find(participants, (participant) => participant.isPolicyExpenseChat); @@ -325,7 +326,8 @@ function MoneyRequestConfirmPage(props) { receiptPath={props.iou.receiptPath} receiptSource={props.iou.receiptSource} iouType={iouType.current} - reportID={reportID.current || lodashGet(props.iou, 'participants.0.reportID', '')} + reportID={reportID.current} + isPolicyExpenseChat={isPolicyExpenseChat} // The participants can only be modified when the action is initiated from directly within a group chat and not the floating-action-button. // This is because when there is a group of people, say they are on a trip, and you have some shared expenses with some of the people, // but not all of them (maybe someone skipped out on dinner). Then it's nice to be able to select/deselect people from the group chat bill From ddcf5d6fa946017467d8c454bd4fed602ce093ef Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 22 Sep 2023 15:11:22 +0200 Subject: [PATCH 12/40] hack onyx forwarding --- src/pages/iou/MoneyRequestCategoryPage.js | 38 ++++++++++++++--------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/src/pages/iou/MoneyRequestCategoryPage.js b/src/pages/iou/MoneyRequestCategoryPage.js index 36fa5624cc58..65e514f8582e 100644 --- a/src/pages/iou/MoneyRequestCategoryPage.js +++ b/src/pages/iou/MoneyRequestCategoryPage.js @@ -2,6 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import lodashGet from 'lodash/get'; import {withOnyx} from 'react-native-onyx'; +import compose from '../../libs/compose'; import ROUTES from '../../ROUTES'; import Navigation from '../../libs/Navigation/Navigation'; import useLocalize from '../../hooks/useLocalize'; @@ -83,19 +84,26 @@ MoneyRequestCategoryPage.displayName = 'MoneyRequestCategoryPage'; MoneyRequestCategoryPage.propTypes = propTypes; MoneyRequestCategoryPage.defaultProps = defaultProps; -export default withOnyx({ - iou: { - key: ONYXKEYS.IOU, - }, - report: { - key: ({route, iou}) => { - let reportID = lodashGet(route, 'params.reportID', ''); - if (!reportID) { - // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. - // Get the report id from the participants list on the IOU object stored in Onyx. - reportID = lodashGet(iou, 'participants.0.reportID', ''); - } - return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; +export default compose( + withOnyx({ + iou: { + key: ONYXKEYS.IOU, }, - }, -})(MoneyRequestCategoryPage); + }), + // This is a temporary hack to forward forward iou value to next getter. + // There is a problem that with one withOnyx it does not forward value from first to second. + // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file + withOnyx({ + report: { + key: ({route, iou}) => { + let reportID = lodashGet(route, 'params.reportID', ''); + if (!reportID) { + // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. + // Get the report id from the participants list on the IOU object stored in Onyx. + reportID = lodashGet(iou, 'participants.0.reportID', ''); + } + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; + }, + }, + }), +)(MoneyRequestCategoryPage); From 36b69512bfede11cda937f098d35e9bc87640665 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 22 Sep 2023 16:02:08 +0200 Subject: [PATCH 13/40] fix props types --- src/components/MoneyRequestConfirmationList.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index cdcb875f163f..c04c6be55218 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -138,7 +138,7 @@ const propTypes = { isDistanceRequest: PropTypes.bool, /** A flag for verifying that the current report is a workspace */ - isPolicyExpenseChat: PropTypes.bool.isRequired, + isPolicyExpenseChat: PropTypes.bool, /* Onyx Props */ /** Collection of categories attached to a policy */ @@ -181,6 +181,7 @@ const defaultProps = { transaction: {}, mileageRate: {unit: CONST.CUSTOM_UNITS.DISTANCE_UNIT_MILES, rate: 0, currency: 'USD'}, isDistanceRequest: false, + isPolicyExpenseChat: false, }; function MoneyRequestConfirmationList(props) { From 0bcda516755ab261aa5de9aa1e72216ed0d15c78 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 26 Sep 2023 15:13:39 +0200 Subject: [PATCH 14/40] unify a fix to get report id on confirm page --- src/pages/iou/MoneyRequestCategoryPage.js | 4 +--- src/pages/iou/MoneyRequestTagPage.js | 17 +++++++++++--- .../iou/steps/MoneyRequestConfirmPage.js | 2 +- .../MoneyRequestParticipantsPage.js | 23 ++++--------------- .../MoneyRequestParticipantsSelector.js | 2 +- 5 files changed, 22 insertions(+), 26 deletions(-) diff --git a/src/pages/iou/MoneyRequestCategoryPage.js b/src/pages/iou/MoneyRequestCategoryPage.js index c18a8f1f50df..6a630c2ec705 100644 --- a/src/pages/iou/MoneyRequestCategoryPage.js +++ b/src/pages/iou/MoneyRequestCategoryPage.js @@ -90,15 +90,13 @@ export default compose( key: ONYXKEYS.IOU, }, }), - // This is a temporary hack to forward forward iou value to next getter. - // There is a problem that with one withOnyx it does not forward value from first to second. // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ report: { key: ({route, iou}) => { let reportID = lodashGet(route, 'params.reportID', ''); if (!reportID) { - // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. + // When the money request or split bill creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. // Get the report id from the participants list on the IOU object stored in Onyx. reportID = lodashGet(iou, 'participants.0.reportID', ''); } diff --git a/src/pages/iou/MoneyRequestTagPage.js b/src/pages/iou/MoneyRequestTagPage.js index 43c0cd9d1480..44adf34385c5 100644 --- a/src/pages/iou/MoneyRequestTagPage.js +++ b/src/pages/iou/MoneyRequestTagPage.js @@ -98,14 +98,25 @@ MoneyRequestTagPage.defaultProps = defaultProps; export default compose( withOnyx({ - report: { - key: ({route}) => `${ONYXKEYS.COLLECTION.REPORT}${lodashGet(route, 'params.reportID')}`, - }, iou: { key: ONYXKEYS.IOU, }, }), // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file + withOnyx({ + report: { + key: ({route, iou}) => { + let reportID = lodashGet(route, 'params.reportID', ''); + if (!reportID) { + // When the money request or split bill creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. + // Get the report id from the participants list on the IOU object stored in Onyx. + reportID = lodashGet(iou, 'participants.0.reportID', ''); + } + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; + }, + }, + }), + // eslint-disable-next-line rulesdir/no-multiple-onyx-in-file withOnyx({ policyTags: { key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`, diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index ee1e346a425b..41fd36c8d8f9 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -381,7 +381,7 @@ export default compose( key: ({route, iou}) => { let reportID = lodashGet(route, 'params.reportID', ''); if (!reportID) { - // When the money request creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. + // When the money request or split bill creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. // Get the report id from the participants list on the IOU object stored in Onyx. reportID = lodashGet(iou, 'participants.0.reportID', ''); } diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js index 8d745903eb40..89c18efc4e76 100644 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsPage.js @@ -45,7 +45,6 @@ const defaultProps = { function MoneyRequestParticipantsPage({iou, selectedTab, route}) { const {translate} = useLocalize(); const prevMoneyRequestId = useRef(iou.id); - const isNewReportIDSelectedLocally = useRef(false); const optionsSelectorRef = useRef(); const iouType = useRef(lodashGet(route, 'params.iouType', '')); const reportID = useRef(lodashGet(route, 'params.reportID', '')); @@ -63,19 +62,7 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) { setHeaderTitle(_.isEmpty(iou.participants) ? translate('tabSelector.manual') : translate('iou.split')); }, [iou.participants, isDistanceRequest, translate]); - const navigateToRequestStep = (moneyRequestType, option) => { - if (option.reportID) { - isNewReportIDSelectedLocally.current = true; - IOU.setMoneyRequestId(`${moneyRequestType}${option.reportID}`); - Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(moneyRequestType, option.reportID)); - return; - } - - IOU.setMoneyRequestId(moneyRequestType); - Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(moneyRequestType, reportID.current)); - }; - - const navigateToSplitStep = (moneyRequestType) => { + const navigateToConfirmationStep = (moneyRequestType) => { IOU.setMoneyRequestId(moneyRequestType); Navigation.navigate(ROUTES.MONEY_REQUEST_CONFIRMATION.getRoute(moneyRequestType, reportID.current)); }; @@ -88,7 +75,7 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) { // ID in Onyx could change by initiating a new request in a separate browser tab or completing a request if (prevMoneyRequestId.current !== iou.id) { // The ID is cleared on completing a request. In that case, we will do nothing - if (iou.id && !isDistanceRequest && !isSplitRequest && !isNewReportIDSelectedLocally.current) { + if (iou.id && !isDistanceRequest && !isSplitRequest) { navigateBack(true); } return; @@ -96,7 +83,7 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) { // Reset the money request Onyx if the ID in Onyx does not match the ID from params const moneyRequestId = `${iouType.current}${reportID.current}`; - const shouldReset = iou.id !== moneyRequestId && !isNewReportIDSelectedLocally.current; + const shouldReset = iou.id !== moneyRequestId; if (shouldReset) { IOU.resetMoneyRequestInfo(moneyRequestId); } @@ -126,8 +113,8 @@ function MoneyRequestParticipantsPage({iou, selectedTab, route}) { ref={(el) => (optionsSelectorRef.current = el)} participants={iou.participants} onAddParticipants={IOU.setMoneyRequestParticipants} - navigateToRequest={(option) => navigateToRequestStep(CONST.IOU.MONEY_REQUEST_TYPE.REQUEST, option)} - navigateToSplit={() => navigateToSplitStep(CONST.IOU.MONEY_REQUEST_TYPE.SPLIT)} + navigateToRequest={() => navigateToConfirmationStep(CONST.IOU.MONEY_REQUEST_TYPE.REQUEST)} + navigateToSplit={() => navigateToConfirmationStep(CONST.IOU.MONEY_REQUEST_TYPE.SPLIT)} safeAreaPaddingBottomStyle={safeAreaPaddingBottomStyle} iouType={iouType.current} isDistanceRequest={isDistanceRequest} diff --git a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js index 170ee042bffa..a8da1b4ec9ed 100755 --- a/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js +++ b/src/pages/iou/steps/MoneyRequstParticipantsPage/MoneyRequestParticipantsSelector.js @@ -161,7 +161,7 @@ function MoneyRequestParticipantsSelector({ onAddParticipants([ {accountID: option.accountID, login: option.login, isPolicyExpenseChat: option.isPolicyExpenseChat, reportID: option.reportID, selected: true, searchText: option.searchText}, ]); - navigateToRequest(option); + navigateToRequest(); }; /** From d5f884cdb2d672ea1a9d170114707dbeb37ae614 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 28 Sep 2023 15:49:16 +0700 Subject: [PATCH 15/40] Safely catch translation key when it's wrong or missing --- src/CONST.ts | 2 ++ src/libs/Localize/index.js | 19 ++++++++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index dbe47c6ed1a7..1dcedbc58488 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -906,6 +906,7 @@ const CONST = { RECEIPTS: 'receipts@expensify.com', STUDENT_AMBASSADOR: 'studentambassadors@expensify.com', SVFG: 'svfg@expensify.com', + EXPENSIFY_EMAIL_DOMAIN: '@expensify', }, ACCOUNT_ID: { @@ -2677,6 +2678,7 @@ const CONST = { HIDDEN_MARGIN_VERTICAL: 0, HIDDEN_BORDER_BOTTOM_WIDTH: 0, }, + MISSING_TRANSLATION: 'MISSING TRANSLATION', } as const; export default CONST; diff --git a/src/libs/Localize/index.js b/src/libs/Localize/index.js index db371301f43f..e017e63ee419 100644 --- a/src/libs/Localize/index.js +++ b/src/libs/Localize/index.js @@ -2,12 +2,26 @@ import _ from 'underscore'; import lodashGet from 'lodash/get'; import Str from 'expensify-common/lib/str'; import * as RNLocalize from 'react-native-localize'; +import Onyx from 'react-native-onyx'; import Log from '../Log'; import Config from '../../CONFIG'; import translations from '../../languages/translations'; import CONST from '../../CONST'; import LocaleListener from './LocaleListener'; import BaseLocaleListener from './LocaleListener/BaseLocaleListener'; +import ONYXKEYS from '../../ONYXKEYS'; + +let userEmail; +Onyx.connect({ + key: ONYXKEYS.SESSION, + waitForCollectionCallback: true, + callback: (val) => { + if (!val) { + return; + } + userEmail = val.email; + }, +}); // Listener when an update in Onyx happens so we use the updated locale when translating/localizing items. LocaleListener.connect(); @@ -72,9 +86,12 @@ function translate(desiredLanguage = CONST.LOCALES.DEFAULT, phraseKey, phrasePar // Phrase is not found in default language, on production log an alert to server // on development throw an error - if (Config.IS_IN_PRODUCTION) { + if (Config.IS_IN_PRODUCTION || Config.IS_IN_STAGING) { const phraseString = _.isArray(phraseKey) ? phraseKey.join('.') : phraseKey; Log.alert(`${phraseString} was not found in the en locale`); + if (_.contains(userEmail, CONST.EMAIL.EXPENSIFY_EMAIL_DOMAIN)) { + return CONST.MISSING_TRANSLATION; + } return phraseString; } throw new Error(`${phraseKey} was not found in the default language`); From 8e27b0c37489590473b36530d654e28563bc233c Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 28 Sep 2023 16:05:36 +0700 Subject: [PATCH 16/40] update comment --- src/libs/Localize/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Localize/index.js b/src/libs/Localize/index.js index e017e63ee419..74ca2e22faa7 100644 --- a/src/libs/Localize/index.js +++ b/src/libs/Localize/index.js @@ -84,7 +84,7 @@ function translate(desiredLanguage = CONST.LOCALES.DEFAULT, phraseKey, phrasePar return Str.result(translatedPhrase, phraseParameters); } - // Phrase is not found in default language, on production log an alert to server + // Phrase is not found in default language, on production and staging log an alert to server // on development throw an error if (Config.IS_IN_PRODUCTION || Config.IS_IN_STAGING) { const phraseString = _.isArray(phraseKey) ? phraseKey.join('.') : phraseKey; From 6b581a9c5be6b525e40cf50ea1b2887309f8edc0 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 28 Sep 2023 13:23:45 +0200 Subject: [PATCH 17/40] clarify comment --- src/components/MoneyRequestConfirmationList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/MoneyRequestConfirmationList.js b/src/components/MoneyRequestConfirmationList.js index 521eb676491b..621a8e3d1b87 100755 --- a/src/components/MoneyRequestConfirmationList.js +++ b/src/components/MoneyRequestConfirmationList.js @@ -138,7 +138,7 @@ const propTypes = { /** Whether the money request is a distance request */ isDistanceRequest: PropTypes.bool, - /** A flag for verifying that the current report is a workspace */ + /** A flag for verifying that the current report is a sub-report of a workspace chat */ isPolicyExpenseChat: PropTypes.bool, /* Onyx Props */ From d21274f8221b7c18df2703f18cb49520f5ea35e8 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 28 Sep 2023 14:58:57 +0200 Subject: [PATCH 18/40] unify iou report id getter --- src/libs/actions/IOU.js | 12 ++++++++++++ src/pages/iou/MoneyRequestCategoryPage.js | 4 +--- src/pages/iou/MoneyRequestTagPage.js | 4 +--- src/pages/iou/steps/MoneyRequestConfirmPage.js | 4 +--- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index e34774ef5328..d1e566fb2852 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2333,6 +2333,17 @@ function navigateToNextPage(iou, iouType, report, path = '') { Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType)); } +/** + * When the money request or split bill creation flow is initialized via FAB, the reportID is not passed as a navigation + * parameter. + * Gets a report id from the first participant of the IOU object stored in Onyx. + * @param {Object} iou + * @returns {String} + */ +function getIOUReportID(iou) { + return lodashGet(iou, 'participants.0.reportID', ''); +} + export { createDistanceRequest, editMoneyRequest, @@ -2363,4 +2374,5 @@ export { navigateToNextPage, updateDistanceRequest, replaceReceipt, + getIOUReportID, }; diff --git a/src/pages/iou/MoneyRequestCategoryPage.js b/src/pages/iou/MoneyRequestCategoryPage.js index 6a630c2ec705..3ef0ce6aaee1 100644 --- a/src/pages/iou/MoneyRequestCategoryPage.js +++ b/src/pages/iou/MoneyRequestCategoryPage.js @@ -96,9 +96,7 @@ export default compose( key: ({route, iou}) => { let reportID = lodashGet(route, 'params.reportID', ''); if (!reportID) { - // When the money request or split bill creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. - // Get the report id from the participants list on the IOU object stored in Onyx. - reportID = lodashGet(iou, 'participants.0.reportID', ''); + reportID = IOU.getIOUReportID(iou); } return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, diff --git a/src/pages/iou/MoneyRequestTagPage.js b/src/pages/iou/MoneyRequestTagPage.js index 44adf34385c5..a8ca82eed302 100644 --- a/src/pages/iou/MoneyRequestTagPage.js +++ b/src/pages/iou/MoneyRequestTagPage.js @@ -108,9 +108,7 @@ export default compose( key: ({route, iou}) => { let reportID = lodashGet(route, 'params.reportID', ''); if (!reportID) { - // When the money request or split bill creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. - // Get the report id from the participants list on the IOU object stored in Onyx. - reportID = lodashGet(iou, 'participants.0.reportID', ''); + reportID = IOU.getIOUReportID(iou); } return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 24227c1f39ae..e199b818cfcb 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -382,9 +382,7 @@ export default compose( key: ({route, iou}) => { let reportID = lodashGet(route, 'params.reportID', ''); if (!reportID) { - // When the money request or split bill creation flow is initialized on Global Create, the reportID is not passed as a navigation parameter. - // Get the report id from the participants list on the IOU object stored in Onyx. - reportID = lodashGet(iou, 'participants.0.reportID', ''); + reportID = IOU.getIOUReportID(iou); } return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, From 5a5dc17214349f701e88515fece8c4ad3e90050b Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Thu, 28 Sep 2023 15:15:58 +0200 Subject: [PATCH 19/40] unify adding a category to recently used --- src/libs/PolicyUtils.js | 15 +++++++++++++++ src/libs/actions/IOU.js | 23 +++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index 347a825f59cc..ef8506791a21 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -261,6 +261,20 @@ function isPendingDeletePolicy(policy) { return policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; } +/** + * Creates a new array based on a previous instance of "policyRecentlyUsedCategories", + * where a new category is a first one. + * + * @param {Array} recentlyUsedPolicyCategories + * @param {String} category + * @returns {Array} + */ +function addCategoryToRecentlyUsed(recentlyUsedPolicyCategories, category) { + const uniquePolicyRecentlyUsedCategories = _.filter(recentlyUsedPolicyCategories, (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category); + + return [category, ...uniquePolicyRecentlyUsedCategories]; +} + export { getActivePolicies, hasPolicyMemberError, @@ -280,4 +294,5 @@ export { getTagListName, getTagList, isPendingDeletePolicy, + addCategoryToRecentlyUsed, }; diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index d1e566fb2852..27cfc21daaf6 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -22,6 +22,7 @@ import * as Report from './Report'; import * as NumberUtils from '../NumberUtils'; import ReceiptGeneric from '../../../assets/images/receipt-generic.png'; import * as LocalePhoneNumber from '../LocalePhoneNumber'; +import * as PolicyUtils from '../PolicyUtils'; let allReports; Onyx.connect({ @@ -483,13 +484,10 @@ function getMoneyRequestInformation( let optimisticPolicyRecentlyUsedCategories; if (category) { - const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories - ? _.filter( - allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`], - (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category, - ) - : []; - optimisticPolicyRecentlyUsedCategories = [category, ...uniquePolicyRecentlyUsedCategories]; + optimisticPolicyRecentlyUsedCategories = PolicyUtils.addCategoryToRecentlyUsed( + allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`] || [], + category, + ); } const optimisticPolicyRecentlyUsedTags = {}; @@ -1150,13 +1148,10 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco // Add category to optimistic policy recently used categories when a participant is a workspace let optimisticPolicyRecentlyUsedCategories; if (category && isPolicyExpenseChat) { - const uniquePolicyRecentlyUsedCategories = allRecentlyUsedCategories - ? _.filter( - allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${participant.policyID}`], - (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category, - ) - : []; - optimisticPolicyRecentlyUsedCategories = [category, ...uniquePolicyRecentlyUsedCategories]; + optimisticPolicyRecentlyUsedCategories = PolicyUtils.addCategoryToRecentlyUsed( + allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${participant.policyID}`] || [], + category, + ); } // STEP 5: Build Onyx Data From 43144a92d07b5d9ad50917f36ffaa3ce349b4f0b Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 29 Sep 2023 14:47:28 +0200 Subject: [PATCH 20/40] revert a fix --- src/libs/actions/IOU.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 27cfc21daaf6..1254cb0e6cb2 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -482,13 +482,10 @@ function getMoneyRequestInformation( billable, ); - let optimisticPolicyRecentlyUsedCategories; - if (category) { - optimisticPolicyRecentlyUsedCategories = PolicyUtils.addCategoryToRecentlyUsed( - allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`] || [], - category, - ); - } + const optimisticPolicyRecentlyUsedCategories = PolicyUtils.addCategoryToRecentlyUsed( + allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`] || [], + category, + ); const optimisticPolicyRecentlyUsedTags = {}; const recentlyUsedPolicyTags = allRecentlyUsedTags[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`]; From 31e4209f250d0ca7069f92e893268f0b45e9bb2a Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 29 Sep 2023 14:53:04 +0200 Subject: [PATCH 21/40] extend getIOUReportID --- src/libs/actions/IOU.js | 25 +++++++++++++++++-- src/pages/iou/MoneyRequestCategoryPage.js | 6 ++--- src/pages/iou/MoneyRequestTagPage.js | 6 ++--- .../iou/steps/MoneyRequestConfirmPage.js | 6 ++--- 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 1254cb0e6cb2..23f124e61736 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2325,15 +2325,36 @@ function navigateToNextPage(iou, iouType, report, path = '') { Navigation.navigate(ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType)); } +// route: PropTypes.shape({ +// /** Route specific parameters used on this screen via route :iouType/new/category/:reportID? */ +// params: PropTypes.shape({ +// /** The type of IOU report, i.e. bill, request, send */ +// iouType: PropTypes.string, + +// /** The report ID of the IOU */ +// reportID: PropTypes.string, +// }), +// }).isRequired, + /** * When the money request or split bill creation flow is initialized via FAB, the reportID is not passed as a navigation * parameter. * Gets a report id from the first participant of the IOU object stored in Onyx. * @param {Object} iou + * @param {Array} iou.participants + * @param {Object} route + * @param {Object} route.params + * @param {String} [route.params.reportID] * @returns {String} */ -function getIOUReportID(iou) { - return lodashGet(iou, 'participants.0.reportID', ''); +function getIOUReportID(iou, route) { + let reportID = lodashGet(route, 'params.reportID', ''); + + if (!reportID) { + reportID = lodashGet(iou, 'participants.0.reportID', ''); + } + + return reportID; } export { diff --git a/src/pages/iou/MoneyRequestCategoryPage.js b/src/pages/iou/MoneyRequestCategoryPage.js index 3ef0ce6aaee1..5055c9f90f8a 100644 --- a/src/pages/iou/MoneyRequestCategoryPage.js +++ b/src/pages/iou/MoneyRequestCategoryPage.js @@ -94,10 +94,8 @@ export default compose( withOnyx({ report: { key: ({route, iou}) => { - let reportID = lodashGet(route, 'params.reportID', ''); - if (!reportID) { - reportID = IOU.getIOUReportID(iou); - } + const reportID = IOU.getIOUReportID(iou, route); + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, }, diff --git a/src/pages/iou/MoneyRequestTagPage.js b/src/pages/iou/MoneyRequestTagPage.js index a8ca82eed302..2fc37d2c4271 100644 --- a/src/pages/iou/MoneyRequestTagPage.js +++ b/src/pages/iou/MoneyRequestTagPage.js @@ -106,10 +106,8 @@ export default compose( withOnyx({ report: { key: ({route, iou}) => { - let reportID = lodashGet(route, 'params.reportID', ''); - if (!reportID) { - reportID = IOU.getIOUReportID(iou); - } + const reportID = IOU.getIOUReportID(iou, route); + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, }, diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index e199b818cfcb..429f62ab280d 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -380,10 +380,8 @@ export default compose( withOnyx({ report: { key: ({route, iou}) => { - let reportID = lodashGet(route, 'params.reportID', ''); - if (!reportID) { - reportID = IOU.getIOUReportID(iou); - } + const reportID = IOU.getIOUReportID(iou, route); + return `${ONYXKEYS.COLLECTION.REPORT}${reportID}`; }, }, From 3563a7c2526e0e18b63517c6ca78dbc4ea33a46c Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 29 Sep 2023 16:36:26 +0200 Subject: [PATCH 22/40] fix unit-tests --- tests/actions/IOUTest.js | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 3df3b137bab3..25ae453a865e 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -57,7 +57,10 @@ describe('actions/IOU', () => { let iouAction; let transactionID; fetch.pause(); - IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {}).then(() => + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment), + ); + return waitForBatchedUpdates() .then( () => @@ -221,6 +224,7 @@ describe('actions/IOU', () => { [createdAction.reportActionID]: createdAction, }), ) + .then(() => Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {})) .then(() => { IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates(); @@ -413,6 +417,7 @@ describe('actions/IOU', () => { }), ) .then(() => Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${existingTransaction.transactionID}`, existingTransaction)) + .then(() => Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {})) .then(() => { IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates(); @@ -547,7 +552,10 @@ describe('actions/IOU', () => { let iouAction; let transactionID; fetch.pause(); - IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); + Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {}).then(() => + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment), + ); + return ( waitForBatchedUpdates() .then( @@ -901,6 +909,7 @@ describe('actions/IOU', () => { }), ) .then(() => Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${julesExistingTransaction.transactionID}`, julesExistingTransaction)) + .then(() => Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {})) .then(() => { // When we split a bill offline fetch.pause(); From c6d978669ab6949f09cb591ac03df8df804f0020 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 29 Sep 2023 18:19:41 +0200 Subject: [PATCH 23/40] simplify condition --- src/libs/actions/IOU.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 23f124e61736..d92cf866b27a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -2348,13 +2348,7 @@ function navigateToNextPage(iou, iouType, report, path = '') { * @returns {String} */ function getIOUReportID(iou, route) { - let reportID = lodashGet(route, 'params.reportID', ''); - - if (!reportID) { - reportID = lodashGet(iou, 'participants.0.reportID', ''); - } - - return reportID; + return lodashGet(route, 'params.reportID') || lodashGet(iou, 'participants.0.reportID', ''); } export { From 2a061f0f0ae391b56bc7806908dffe6d7a7b5776 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Fri, 29 Sep 2023 18:21:14 +0200 Subject: [PATCH 24/40] Revert "fix unit-tests" This reverts commit 3563a7c2526e0e18b63517c6ca78dbc4ea33a46c. --- tests/actions/IOUTest.js | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/actions/IOUTest.js b/tests/actions/IOUTest.js index 25ae453a865e..3df3b137bab3 100644 --- a/tests/actions/IOUTest.js +++ b/tests/actions/IOUTest.js @@ -57,10 +57,7 @@ describe('actions/IOU', () => { let iouAction; let transactionID; fetch.pause(); - Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {}).then(() => - IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment), - ); - + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', merchant, RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates() .then( () => @@ -224,7 +221,6 @@ describe('actions/IOU', () => { [createdAction.reportActionID]: createdAction, }), ) - .then(() => Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {})) .then(() => { IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates(); @@ -417,7 +413,6 @@ describe('actions/IOU', () => { }), ) .then(() => Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${existingTransaction.transactionID}`, existingTransaction)) - .then(() => Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {})) .then(() => { IOU.requestMoney(chatReport, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return waitForBatchedUpdates(); @@ -552,10 +547,7 @@ describe('actions/IOU', () => { let iouAction; let transactionID; fetch.pause(); - Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {}).then(() => - IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment), - ); - + IOU.requestMoney({}, amount, CONST.CURRENCY.USD, '', '', RORY_EMAIL, RORY_ACCOUNT_ID, {login: CARLOS_EMAIL, accountID: CARLOS_ACCOUNT_ID}, comment); return ( waitForBatchedUpdates() .then( @@ -909,7 +901,6 @@ describe('actions/IOU', () => { }), ) .then(() => Onyx.set(`${ONYXKEYS.COLLECTION.TRANSACTION}${julesExistingTransaction.transactionID}`, julesExistingTransaction)) - .then(() => Onyx.set(ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, {})) .then(() => { // When we split a bill offline fetch.pause(); From 56cfc89f20bdea91c7de258421bf07ef4ece17f9 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 2 Oct 2023 14:37:25 +0200 Subject: [PATCH 25/40] implement buildOptimisticPolicyRecentlyUsedCategories --- src/libs/actions/IOU.js | 29 ++++++----------------------- src/libs/actions/Policy.js | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 23 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 24c192e807ff..5b12b2f018d7 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -22,7 +22,7 @@ import * as Report from './Report'; import * as NumberUtils from '../NumberUtils'; import ReceiptGeneric from '../../../assets/images/receipt-generic.png'; import * as LocalePhoneNumber from '../LocalePhoneNumber'; -import * as PolicyUtils from '../PolicyUtils'; +import * as Policy from './Policy'; let allReports; Onyx.connect({ @@ -45,13 +45,6 @@ Onyx.connect({ }, }); -let allRecentlyUsedCategories = {}; -Onyx.connect({ - key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, - waitForCollectionCallback: true, - callback: (val) => (allRecentlyUsedCategories = val), -}); - let allRecentlyUsedTags = {}; Onyx.connect({ key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS, @@ -176,11 +169,7 @@ function buildOnyxDataForMoneyRequest( ]; if (!_.isEmpty(optimisticRecentlyUsedCategories)) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`, - value: optimisticRecentlyUsedCategories, - }); + optimisticData.push(optimisticRecentlyUsedCategories); } if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { @@ -464,10 +453,7 @@ function getMoneyRequestInformation( billable, ); - const optimisticPolicyRecentlyUsedCategories = PolicyUtils.addCategoryToRecentlyUsed( - allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`] || [], - category, - ); + const optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(iouReport.policyID, category); const optimisticPolicyRecentlyUsedTags = {}; const recentlyUsedPolicyTags = allRecentlyUsedTags[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_TAGS}${iouReport.policyID}`]; @@ -1125,12 +1111,9 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco } // Add category to optimistic policy recently used categories when a participant is a workspace - let optimisticPolicyRecentlyUsedCategories; - if (category && isPolicyExpenseChat) { - optimisticPolicyRecentlyUsedCategories = PolicyUtils.addCategoryToRecentlyUsed( - allRecentlyUsedCategories[`${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${participant.policyID}`] || [], - category, - ); + let optimisticPolicyRecentlyUsedCategories = {}; + if (isPolicyExpenseChat) { + optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(participant.policyID, category); } // STEP 5: Build Onyx Data diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index fcce909c5582..b8f94ba37149 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -12,6 +12,7 @@ import * as OptionsListUtils from '../OptionsListUtils'; import * as ErrorUtils from '../ErrorUtils'; import * as ReportUtils from '../ReportUtils'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; +import * as PolicyUtils from '../PolicyUtils'; import Log from '../Log'; const allPolicies = {}; @@ -65,6 +66,13 @@ Onyx.connect({ callback: (val) => (allPersonalDetails = val), }); +let allRecentlyUsedCategories = {}; +Onyx.connect({ + key: ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES, + waitForCollectionCallback: true, + callback: (val) => (allRecentlyUsedCategories = val), +}); + /** * Stores in Onyx the policy ID of the last workspace that was accessed by the user * @param {String|null} policyID @@ -1168,6 +1176,25 @@ function clearErrors(policyID) { hideWorkspaceAlertMessage(policyID); } +/** + * @param {String} policyID + * @param {String} category + * @returns {Object} + */ +function buildOptimisticPolicyRecentlyUsedCategories(policyID, category) { + if (!policyID || !category) { + return {}; + } + + const policyRecentlyUsedCategories = lodashGet(allRecentlyUsedCategories, `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, []); + + return { + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, + value: PolicyUtils.addCategoryToRecentlyUsed(policyRecentlyUsedCategories, category), + }; +} + export { removeMembers, addMembersToWorkspace, @@ -1197,4 +1224,5 @@ export { setWorkspaceInviteMembersDraft, clearErrors, openDraftWorkspaceRequest, + buildOptimisticPolicyRecentlyUsedCategories, }; From 87154dc61ab2c4599ed96ca11198fd0d807ef144 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 2 Oct 2023 17:11:44 +0200 Subject: [PATCH 26/40] remove extra helper --- src/libs/PolicyUtils.js | 15 --------------- src/libs/actions/Policy.js | 4 ++-- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js index ef8506791a21..347a825f59cc 100644 --- a/src/libs/PolicyUtils.js +++ b/src/libs/PolicyUtils.js @@ -261,20 +261,6 @@ function isPendingDeletePolicy(policy) { return policy.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE; } -/** - * Creates a new array based on a previous instance of "policyRecentlyUsedCategories", - * where a new category is a first one. - * - * @param {Array} recentlyUsedPolicyCategories - * @param {String} category - * @returns {Array} - */ -function addCategoryToRecentlyUsed(recentlyUsedPolicyCategories, category) { - const uniquePolicyRecentlyUsedCategories = _.filter(recentlyUsedPolicyCategories, (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category); - - return [category, ...uniquePolicyRecentlyUsedCategories]; -} - export { getActivePolicies, hasPolicyMemberError, @@ -294,5 +280,4 @@ export { getTagListName, getTagList, isPendingDeletePolicy, - addCategoryToRecentlyUsed, }; diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index b8f94ba37149..819b3163c492 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -12,7 +12,6 @@ import * as OptionsListUtils from '../OptionsListUtils'; import * as ErrorUtils from '../ErrorUtils'; import * as ReportUtils from '../ReportUtils'; import * as PersonalDetailsUtils from '../PersonalDetailsUtils'; -import * as PolicyUtils from '../PolicyUtils'; import Log from '../Log'; const allPolicies = {}; @@ -1187,11 +1186,12 @@ function buildOptimisticPolicyRecentlyUsedCategories(policyID, category) { } const policyRecentlyUsedCategories = lodashGet(allRecentlyUsedCategories, `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, []); + const uniquePolicyRecentlyUsedCategories = _.filter(policyRecentlyUsedCategories, (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category); return { onyxMethod: Onyx.METHOD.SET, key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, - value: PolicyUtils.addCategoryToRecentlyUsed(policyRecentlyUsedCategories, category), + value: [category, ...uniquePolicyRecentlyUsedCategories], }; } From 864154caa1deb7c384f44f09eea25356a5e8f4a2 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 2 Oct 2023 18:07:42 +0200 Subject: [PATCH 27/40] unify --- src/libs/actions/IOU.js | 12 ++++++++---- src/libs/actions/Policy.js | 8 ++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 5b12b2f018d7..26ff5f7b7773 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -117,7 +117,7 @@ function buildOnyxDataForMoneyRequest( iouAction, optimisticPersonalDetailListAction, reportPreviewAction, - optimisticRecentlyUsedCategories, + optimisticPolicyRecentlyUsedCategories, optimisticPolicyRecentlyUsedTags, isNewChatReport, isNewIOUReport, @@ -168,8 +168,12 @@ function buildOnyxDataForMoneyRequest( }, ]; - if (!_.isEmpty(optimisticRecentlyUsedCategories)) { - optimisticData.push(optimisticRecentlyUsedCategories); + if (!_.isEmpty(optimisticPolicyRecentlyUsedCategories)) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.SET, + key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${iouReport.policyID}`, + value: optimisticPolicyRecentlyUsedCategories, + }); } if (!_.isEmpty(optimisticPolicyRecentlyUsedTags)) { @@ -1111,7 +1115,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco } // Add category to optimistic policy recently used categories when a participant is a workspace - let optimisticPolicyRecentlyUsedCategories = {}; + let optimisticPolicyRecentlyUsedCategories = []; if (isPolicyExpenseChat) { optimisticPolicyRecentlyUsedCategories = Policy.buildOptimisticPolicyRecentlyUsedCategories(participant.policyID, category); } diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index 819b3163c492..f4ad81e9d62c 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -1182,17 +1182,13 @@ function clearErrors(policyID) { */ function buildOptimisticPolicyRecentlyUsedCategories(policyID, category) { if (!policyID || !category) { - return {}; + return []; } const policyRecentlyUsedCategories = lodashGet(allRecentlyUsedCategories, `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, []); const uniquePolicyRecentlyUsedCategories = _.filter(policyRecentlyUsedCategories, (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category); - return { - onyxMethod: Onyx.METHOD.SET, - key: `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, - value: [category, ...uniquePolicyRecentlyUsedCategories], - }; + return [category, ...uniquePolicyRecentlyUsedCategories]; } export { From 733d2292ed299492ce90a349c92141ada9dc77cf Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Tue, 3 Oct 2023 17:07:18 +0200 Subject: [PATCH 28/40] clear category on go back --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index 429f62ab280d..a508b8b22402 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -117,11 +117,15 @@ function MoneyRequestConfirmPage(props) { const navigateBack = () => { let fallback; + if (reportID.current) { fallback = ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current); } else { fallback = ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType.current); } + + IOU.resetMoneyRequestCategory(); + Navigation.goBack(fallback); }; From 0bbe1594661356a6eabc2421dd83dbe673970f1b Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 4 Oct 2023 17:42:11 +0700 Subject: [PATCH 29/40] fix condition --- src/libs/Localize/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Localize/index.js b/src/libs/Localize/index.js index 74ca2e22faa7..d86617e4d7a0 100644 --- a/src/libs/Localize/index.js +++ b/src/libs/Localize/index.js @@ -89,7 +89,7 @@ function translate(desiredLanguage = CONST.LOCALES.DEFAULT, phraseKey, phrasePar if (Config.IS_IN_PRODUCTION || Config.IS_IN_STAGING) { const phraseString = _.isArray(phraseKey) ? phraseKey.join('.') : phraseKey; Log.alert(`${phraseString} was not found in the en locale`); - if (_.contains(userEmail, CONST.EMAIL.EXPENSIFY_EMAIL_DOMAIN)) { + if (userEmail.includes(CONST.EMAIL.EXPENSIFY_EMAIL_DOMAIN)) { return CONST.MISSING_TRANSLATION; } return phraseString; From df19f0397c1dad0a5599357098f2b0b4f6b3ae67 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Wed, 4 Oct 2023 12:56:45 +0200 Subject: [PATCH 30/40] clear values on start confirm --- src/pages/iou/steps/MoneyRequestConfirmPage.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/pages/iou/steps/MoneyRequestConfirmPage.js b/src/pages/iou/steps/MoneyRequestConfirmPage.js index a508b8b22402..907869c0e3a4 100644 --- a/src/pages/iou/steps/MoneyRequestConfirmPage.js +++ b/src/pages/iou/steps/MoneyRequestConfirmPage.js @@ -78,6 +78,11 @@ function MoneyRequestConfirmPage(props) { const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(ReportUtils.getRootParentReport(props.report)), [props.report]); const isManualRequestDM = props.selectedTab === CONST.TAB.MANUAL && iouType.current === CONST.IOU.MONEY_REQUEST_TYPE.REQUEST; + useEffect(() => { + IOU.resetMoneyRequestCategory(); + IOU.resetMoneyRequestTag(); + }, []); + useEffect(() => { const policyExpenseChat = _.find(participants, (participant) => participant.isPolicyExpenseChat); if (policyExpenseChat) { @@ -117,15 +122,11 @@ function MoneyRequestConfirmPage(props) { const navigateBack = () => { let fallback; - if (reportID.current) { fallback = ROUTES.MONEY_REQUEST.getRoute(iouType.current, reportID.current); } else { fallback = ROUTES.MONEY_REQUEST_PARTICIPANTS.getRoute(iouType.current); } - - IOU.resetMoneyRequestCategory(); - Navigation.goBack(fallback); }; From 660823422a8b9dd7cfd898fe0abb4f422605075d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 4 Oct 2023 18:01:30 +0700 Subject: [PATCH 31/40] fix test --- src/libs/Localize/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Localize/index.js b/src/libs/Localize/index.js index d86617e4d7a0..18ce57f9f67e 100644 --- a/src/libs/Localize/index.js +++ b/src/libs/Localize/index.js @@ -11,7 +11,7 @@ import LocaleListener from './LocaleListener'; import BaseLocaleListener from './LocaleListener/BaseLocaleListener'; import ONYXKEYS from '../../ONYXKEYS'; -let userEmail; +let userEmail = ''; Onyx.connect({ key: ONYXKEYS.SESSION, waitForCollectionCallback: true, From d4c8acdbac381e4e630c1c2604d001773dbc5619 Mon Sep 17 00:00:00 2001 From: someone-here Date: Thu, 5 Oct 2023 00:07:11 +0530 Subject: [PATCH 32/40] Disable SelectCircle in split bill --- src/components/OptionRow.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/OptionRow.js b/src/components/OptionRow.js index 70415ab03a13..47ab4fe45db1 100644 --- a/src/components/OptionRow.js +++ b/src/components/OptionRow.js @@ -282,6 +282,7 @@ class OptionRow extends Component { ) : ( this.props.onSelectedStatePressed(this.props.option)} + disabled={this.state.isDisabled} accessibilityRole={CONST.ACCESSIBILITY_ROLE.CHECKBOX} accessibilityLabel={CONST.ACCESSIBILITY_ROLE.CHECKBOX} > From 7defd51ff27e0c7a4cc873fb97554c4d28cb744d Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Thu, 5 Oct 2023 11:28:30 +0100 Subject: [PATCH 33/40] add dedicated screenshot/video section to standard issue template --- .github/ISSUE_TEMPLATE/Standard.md | 56 ++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Standard.md b/.github/ISSUE_TEMPLATE/Standard.md index 39d1c38fa56f..25493866c0e6 100644 --- a/.github/ISSUE_TEMPLATE/Standard.md +++ b/.github/ISSUE_TEMPLATE/Standard.md @@ -24,12 +24,12 @@ Can the user still use Expensify without this being fixed? Have you informed the Check off any platforms that are affected by this issue ---> Which of our officially supported platforms is this issue occurring on? -- [ ] Android / native -- [ ] Android / Chrome -- [ ] iOS / native -- [ ] iOS / Safari -- [ ] MacOS / Chrome / Safari -- [ ] MacOS / Desktop +- [ ] Android: Native +- [ ] Android: Chrome +- [ ] iOS: Native +- [ ] iOS: Safari +- [ ] MacOS: Chrome / Safari +- [ ] MacOS: Desktop **Version Number:** **Reproducible in staging?:** @@ -37,9 +37,51 @@ Which of our officially supported platforms is this issue occurring on? **If this was caught during regression testing, add the test name, ID and link from TestRail:** **Email or phone of affected tester (no customers):** **Logs:** https://stackoverflow.com/c/expensify/questions/4856 -**Notes/Photos/Videos:** Any additional supporting documentation **Expensify/Expensify Issue URL:** **Issue reported by:** **Slack conversation:** +## Screenshots/Videos +
+Android: Native + + + +
+ +
+Android: Chrome + + + +
+ +
+iOS: Native + + + +
+ +
+iOS: Safari + + + +
+ +
+MacOS: Chrome / Safari + + + +
+ +
+MacOS: Desktop + + + +
+ [View all open jobs on GitHub](https://github.com/Expensify/App/issues?q=is%3Aopen+is%3Aissue+label%3A%22Help+Wanted%22) From e4b957f8ba788e46874e3276a26fb97d42ebef35 Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Thu, 5 Oct 2023 11:30:24 +0100 Subject: [PATCH 34/40] move details to top of issue for better visibility --- .github/ISSUE_TEMPLATE/Standard.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Standard.md b/.github/ISSUE_TEMPLATE/Standard.md index 25493866c0e6..964e27729984 100644 --- a/.github/ISSUE_TEMPLATE/Standard.md +++ b/.github/ISSUE_TEMPLATE/Standard.md @@ -7,6 +7,16 @@ labels: Bug, Daily If you haven’t already, check out our [contributing guidelines](https://github.com/Expensify/ReactNativeChat/blob/main/contributingGuides/CONTRIBUTING.md) for onboarding and email contributors@expensify.com to request to join our Slack channel! ___ +**Version Number:** +**Reproducible in staging?:** +**Reproducible in production?:** +**If this was caught during regression testing, add the test name, ID and link from TestRail:** +**Email or phone of affected tester (no customers):** +**Logs:** https://stackoverflow.com/c/expensify/questions/4856 +**Expensify/Expensify Issue URL:** +**Issue reported by:** +**Slack conversation:** + ## Action Performed: Break down in numbered steps @@ -31,16 +41,6 @@ Which of our officially supported platforms is this issue occurring on? - [ ] MacOS: Chrome / Safari - [ ] MacOS: Desktop -**Version Number:** -**Reproducible in staging?:** -**Reproducible in production?:** -**If this was caught during regression testing, add the test name, ID and link from TestRail:** -**Email or phone of affected tester (no customers):** -**Logs:** https://stackoverflow.com/c/expensify/questions/4856 -**Expensify/Expensify Issue URL:** -**Issue reported by:** -**Slack conversation:** - ## Screenshots/Videos
Android: Native From dd05a2531fc290dcaa370df0aca990810a0a4da7 Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Thu, 5 Oct 2023 11:34:43 +0100 Subject: [PATCH 35/40] align the pull request device list with the standard issue template --- .github/PULL_REQUEST_TEMPLATE.md | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 800888580518..2dff4583f219 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -70,12 +70,12 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c - [ ] I tested this PR with a [High Traffic account](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#high-traffic-accounts) against the staging or production API to ensure there are no regressions (e.g. long loading states that impact usability). - [ ] I included screenshots or videos for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) - [ ] I ran the tests on **all platforms** & verified they passed on: - - [ ] Android / native - - [ ] Android / Chrome - - [ ] iOS / native - - [ ] iOS / Safari - - [ ] MacOS / Chrome / Safari - - [ ] MacOS / Desktop + - [ ] Android: Native + - [ ] Android: Chrome + - [ ] iOS: Native + - [ ] iOS: Safari + - [ ] MacOS: Chrome / Safari + - [ ] MacOS: Desktop - [ ] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed) - [ ] I followed proper code patterns (see [Reviewing the code](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md#reviewing-the-code)) - [ ] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. `toggleReport` and not `onIconClick`) @@ -120,42 +120,42 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c ### Screenshots/Videos
-Web +Android: Native
-Mobile Web - Chrome +Android: Chrome
-Mobile Web - Safari +iOS: Native
-Desktop +iOS: Safari
-iOS +MacOS: Chrome / Safari
-Android +MacOS: Desktop From 0e2d417f688f8fddc7aaf4f841f3b711a03c102a Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Thu, 5 Oct 2023 11:36:14 +0100 Subject: [PATCH 36/40] reintroduce mWeb for clarity --- .github/ISSUE_TEMPLATE/Standard.md | 8 ++++---- .github/PULL_REQUEST_TEMPLATE.md | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Standard.md b/.github/ISSUE_TEMPLATE/Standard.md index 964e27729984..5e0e3633f3bc 100644 --- a/.github/ISSUE_TEMPLATE/Standard.md +++ b/.github/ISSUE_TEMPLATE/Standard.md @@ -35,9 +35,9 @@ Check off any platforms that are affected by this issue ---> Which of our officially supported platforms is this issue occurring on? - [ ] Android: Native -- [ ] Android: Chrome +- [ ] Android: mWeb Chrome - [ ] iOS: Native -- [ ] iOS: Safari +- [ ] iOS: mWeb Safari - [ ] MacOS: Chrome / Safari - [ ] MacOS: Desktop @@ -50,7 +50,7 @@ Which of our officially supported platforms is this issue occurring on?
-Android: Chrome +Android: mWeb Chrome @@ -64,7 +64,7 @@ Which of our officially supported platforms is this issue occurring on?
-iOS: Safari +iOS: mWeb Safari diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 2dff4583f219..0396a7543b50 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -71,9 +71,9 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c - [ ] I included screenshots or videos for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) - [ ] I ran the tests on **all platforms** & verified they passed on: - [ ] Android: Native - - [ ] Android: Chrome + - [ ] Android: mWeb Chrome - [ ] iOS: Native - - [ ] iOS: Safari + - [ ] iOS: mWeb Safari - [ ] MacOS: Chrome / Safari - [ ] MacOS: Desktop - [ ] I verified there are no console errors (if there's a console error not related to the PR, report it or open an issue for it to be fixed) @@ -127,7 +127,7 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c
-Android: Chrome +Android: mWeb Chrome @@ -141,7 +141,7 @@ This is a checklist for PR authors. Please make sure to complete all tasks and c
-iOS: Safari +iOS: mWeb Safari From 667fe65b6f65b25857a4fc0144d69631c7ff05ed Mon Sep 17 00:00:00 2001 From: Jules Rosser Date: Thu, 5 Oct 2023 11:40:19 +0100 Subject: [PATCH 37/40] align device naming across all issue templates --- .github/ISSUE_TEMPLATE/Accessibility.md | 12 ++++++------ .github/ISSUE_TEMPLATE/Performance.md | 12 ++++++------ contributingGuides/REVIEWER_CHECKLIST.md | 12 ++++++------ 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/Accessibility.md b/.github/ISSUE_TEMPLATE/Accessibility.md index 1323e2c17e78..97fc17d28a94 100644 --- a/.github/ISSUE_TEMPLATE/Accessibility.md +++ b/.github/ISSUE_TEMPLATE/Accessibility.md @@ -35,12 +35,12 @@ What can we do to fix the issue? Check off any platforms that are affected by this issue ---> Which of our officially supported platforms is this issue occurring on? Please only tick the box if you have provided a screen-recording in the thread for each platform: -- [ ] Android / native -- [ ] Android / Chrome -- [ ] iOS / native -- [ ] iOS / Safari -- [ ] MacOS / Chrome / Safari -- [ ] MacOS / Desktop +- [ ] Android: Native +- [ ] Android: mWeb Chrome +- [ ] iOS: Native +- [ ] iOS: mWeb Safari +- [ ] MacOS: Chrome / Safari +- [ ] MacOS: Desktop **Version Number:** **Reproducible in staging?:** diff --git a/.github/ISSUE_TEMPLATE/Performance.md b/.github/ISSUE_TEMPLATE/Performance.md index 67b2e6971874..bbb729e8af31 100644 --- a/.github/ISSUE_TEMPLATE/Performance.md +++ b/.github/ISSUE_TEMPLATE/Performance.md @@ -28,12 +28,12 @@ Note: These should be the same as the benchmarks collected before any changes. Check off any platforms that are affected by this issue ---> Which of our officially supported platforms is this issue occurring on? -- [ ] Android / native -- [ ] Android / Chrome -- [ ] iOS / native -- [ ] iOS / Safari -- [ ] MacOS / Chrome / Safari -- [ ] MacOS / Desktop +- [ ] Android: Native +- [ ] Android: mWeb Chrome +- [ ] iOS: Native +- [ ] iOS: mWeb Safari +- [ ] MacOS: Chrome / Safari +- [ ] MacOS: Desktop **Version Number:** **Reproducible in staging?:** diff --git a/contributingGuides/REVIEWER_CHECKLIST.md b/contributingGuides/REVIEWER_CHECKLIST.md index 6a5dffc8b073..d52d80a818bb 100644 --- a/contributingGuides/REVIEWER_CHECKLIST.md +++ b/contributingGuides/REVIEWER_CHECKLIST.md @@ -10,12 +10,12 @@ - [ ] I checked that screenshots or videos are included for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) - [ ] I included screenshots or videos for tests on [all platforms](https://github.com/Expensify/App/blob/main/contributingGuides/CONTRIBUTING.md#make-sure-you-can-test-on-all-platforms) - [ ] I verified tests pass on **all platforms** & I tested again on: - - [ ] Android / native - - [ ] Android / Chrome - - [ ] iOS / native - - [ ] iOS / Safari - - [ ] MacOS / Chrome / Safari - - [ ] MacOS / Desktop + - [ ] Android: Native + - [ ] Android: mWeb Chrome + - [ ] iOS: Native + - [ ] iOS: mWeb Safari + - [ ] MacOS: Chrome / Safari + - [ ] MacOS: Desktop - [ ] If there are any errors in the console that are unrelated to this PR, I either fixed them (preferred) or linked to where I reported them in Slack - [ ] I verified proper code patterns were followed (see [Reviewing the code](https://github.com/Expensify/App/blob/main/contributingGuides/PR_REVIEW_GUIDELINES.md#reviewing-the-code)) - [ ] I verified that any callback methods that were added or modified are named for what the method does and never what callback they handle (i.e. `toggleReport` and not `onIconClick`). From 604b07809944c441b46b731c14eaf12025ae61a0 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 9 Oct 2023 15:51:04 +0700 Subject: [PATCH 38/40] fix comments --- src/CONST.ts | 2 +- src/libs/Localize/index.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/CONST.ts b/src/CONST.ts index 939a6b85e708..5d75f43cedd9 100755 --- a/src/CONST.ts +++ b/src/CONST.ts @@ -930,7 +930,7 @@ const CONST = { RECEIPTS: 'receipts@expensify.com', STUDENT_AMBASSADOR: 'studentambassadors@expensify.com', SVFG: 'svfg@expensify.com', - EXPENSIFY_EMAIL_DOMAIN: '@expensify', + EXPENSIFY_EMAIL_DOMAIN: '@expensify.com', }, ACCOUNT_ID: { diff --git a/src/libs/Localize/index.js b/src/libs/Localize/index.js index 18ce57f9f67e..3abbd6e079f4 100644 --- a/src/libs/Localize/index.js +++ b/src/libs/Localize/index.js @@ -11,6 +11,7 @@ import LocaleListener from './LocaleListener'; import BaseLocaleListener from './LocaleListener/BaseLocaleListener'; import ONYXKEYS from '../../ONYXKEYS'; +// Save the email after user logins let userEmail = ''; Onyx.connect({ key: ONYXKEYS.SESSION, From 8c7f8a2987ba7f68137128b14a06b2a1ded1a82f Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 9 Oct 2023 16:04:09 +0700 Subject: [PATCH 39/40] change comment --- src/libs/Localize/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/Localize/index.js b/src/libs/Localize/index.js index 3abbd6e079f4..a26c7d4ebc10 100644 --- a/src/libs/Localize/index.js +++ b/src/libs/Localize/index.js @@ -11,7 +11,7 @@ import LocaleListener from './LocaleListener'; import BaseLocaleListener from './LocaleListener/BaseLocaleListener'; import ONYXKEYS from '../../ONYXKEYS'; -// Save the email after user logins +// Current user mail is needed for handling missing translations let userEmail = ''; Onyx.connect({ key: ONYXKEYS.SESSION, From 585d6a226ea191b15af22f310247945a8b3b0f37 Mon Sep 17 00:00:00 2001 From: Mykhailo Kravchenko Date: Mon, 9 Oct 2023 15:06:04 +0200 Subject: [PATCH 40/40] simplify combining array --- src/libs/actions/Policy.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy.js b/src/libs/actions/Policy.js index f4ad81e9d62c..3e5e91a74488 100644 --- a/src/libs/actions/Policy.js +++ b/src/libs/actions/Policy.js @@ -1,6 +1,7 @@ import _ from 'underscore'; import Onyx from 'react-native-onyx'; import lodashGet from 'lodash/get'; +import lodashUnion from 'lodash/union'; import {PUBLIC_DOMAINS} from 'expensify-common/lib/CONST'; import Str from 'expensify-common/lib/str'; import {escapeRegExp} from 'lodash'; @@ -1186,9 +1187,8 @@ function buildOptimisticPolicyRecentlyUsedCategories(policyID, category) { } const policyRecentlyUsedCategories = lodashGet(allRecentlyUsedCategories, `${ONYXKEYS.COLLECTION.POLICY_RECENTLY_USED_CATEGORIES}${policyID}`, []); - const uniquePolicyRecentlyUsedCategories = _.filter(policyRecentlyUsedCategories, (recentlyUsedPolicyCategory) => recentlyUsedPolicyCategory !== category); - return [category, ...uniquePolicyRecentlyUsedCategories]; + return lodashUnion([category], policyRecentlyUsedCategories); } export {