From 35f1bc4bf8bf59c49c797504e0ae3011b310c4ef Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 29 Sep 2023 11:05:46 +0700 Subject: [PATCH 1/7] remove optimistic personal detail after requesting money --- src/libs/actions/IOU.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 198ceb2b8172..ddf334c45def 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -241,6 +241,17 @@ function buildOnyxDataForMoneyRequest( }, ] : []), + ...(isNewIOUReport + ? [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [chatReport.participantAccountIDs[0]]: null, + }, + }, + ] + : []), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, @@ -313,6 +324,17 @@ function buildOnyxDataForMoneyRequest( }, ] : []), + ...(isNewIOUReport + ? [ + { + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.PERSONAL_DETAILS_LIST, + value: { + [chatReport.participantAccountIDs[0]]: null, + }, + }, + ] + : []), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, From eaffe5c685cb6591873fd2d2c48080514c0f7786 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 29 Sep 2023 14:00:34 +0700 Subject: [PATCH 2/7] hide optimistic personal detail in search page --- src/libs/OptionsListUtils.js | 5 ++++- src/libs/actions/IOU.js | 24 ++---------------------- src/pages/SearchPage.js | 3 +++ 3 files changed, 9 insertions(+), 23 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index e0f334ca36af..3d74eda970bf 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -459,6 +459,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { isPolicyExpenseChat: false, isExpenseReport: false, policyID: null, + isOptimisticPersonalDetail: false }; const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); @@ -469,6 +470,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { let reportName; result.participantsList = personalDetailList; + result.isOptimisticPersonalDetail = personalDetail.isOptimisticPersonalDetail; if (report) { result.isChatRoom = ReportUtils.isChatRoom(report); @@ -1151,7 +1153,7 @@ function getOptions( if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats _.each(allPersonalDetailsOptions, (personalDetailOption) => { - if (_.some(optionsToExclude, (optionToExclude) => optionToExclude.login === personalDetailOption.login)) { + if (_.some(optionsToExclude, (optionToExclude) => optionToExclude.login === personalDetailOption.login) || personalDetailOption.isOptimisticPersonalDetail) { return; } const {searchText, participantsList, isChatRoom} = personalDetailOption; @@ -1159,6 +1161,7 @@ function getOptions( if (searchValue && !isSearchStringMatch(searchValue, searchText, participantNames, isChatRoom)) { return; } + personalDetailsOptions.push(personalDetailOption); }); } diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index ddf334c45def..95db21b7843a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -241,17 +241,6 @@ function buildOnyxDataForMoneyRequest( }, ] : []), - ...(isNewIOUReport - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: { - [chatReport.participantAccountIDs[0]]: null, - }, - }, - ] - : []), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, @@ -324,17 +313,6 @@ function buildOnyxDataForMoneyRequest( }, ] : []), - ...(isNewIOUReport - ? [ - { - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.PERSONAL_DETAILS_LIST, - value: { - [chatReport.participantAccountIDs[0]]: null, - }, - }, - ] - : []), { onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, @@ -575,6 +553,7 @@ function getMoneyRequestInformation( avatar: UserUtils.getDefaultAvatarURL(payerAccountID), displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || payerEmail), login: participant.login, + isOptimisticPersonalDetail: true, }, } : undefined; @@ -1142,6 +1121,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco avatar: UserUtils.getDefaultAvatarURL(accountID), displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || email), login: participant.login, + isOptimisticPersonalDetail: true, }, } : undefined; diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 141f4e841853..2e35e6416ef7 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -59,6 +59,7 @@ class SearchPage extends Component { const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getSearchOptions(props.reports, props.personalDetails, '', props.betas); + this.state = { searchValue: '', recentReports, @@ -159,6 +160,8 @@ class SearchPage extends Component { } } + + render() { const sections = this.getSections(); const isOptionsDataReady = ReportUtils.isReportDataReady() && OptionsListUtils.isPersonalDetailsReady(this.props.personalDetails); From 708465f94ffcf8c2bf646e9e34416e12350efa9a Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 29 Sep 2023 14:02:58 +0700 Subject: [PATCH 3/7] fix linnt --- src/libs/OptionsListUtils.js | 2 +- src/pages/SearchPage.js | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 3d74eda970bf..9cd4fbe083b9 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -459,7 +459,7 @@ function createOption(accountIDs, personalDetails, report, reportActions = {}, { isPolicyExpenseChat: false, isExpenseReport: false, policyID: null, - isOptimisticPersonalDetail: false + isOptimisticPersonalDetail: false, }; const personalDetailMap = getPersonalDetailsForAccountIDs(accountIDs, personalDetails); diff --git a/src/pages/SearchPage.js b/src/pages/SearchPage.js index 2e35e6416ef7..141f4e841853 100755 --- a/src/pages/SearchPage.js +++ b/src/pages/SearchPage.js @@ -59,7 +59,6 @@ class SearchPage extends Component { const {recentReports, personalDetails, userToInvite} = OptionsListUtils.getSearchOptions(props.reports, props.personalDetails, '', props.betas); - this.state = { searchValue: '', recentReports, @@ -160,8 +159,6 @@ class SearchPage extends Component { } } - - render() { const sections = this.getSections(); const isOptionsDataReady = ReportUtils.isReportDataReady() && OptionsListUtils.isPersonalDetailsReady(this.props.personalDetails); From 1a0a0e7d19586563284f533324d6c0ae64a725e8 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 29 Sep 2023 14:41:23 +0700 Subject: [PATCH 4/7] fix jest --- src/libs/actions/IOU.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 95db21b7843a..73c8f3a03075 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1122,6 +1122,7 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || email), login: participant.login, isOptimisticPersonalDetail: true, + }, } : undefined; From a7918ff30f6d14bd545994b0f29d51c1099c4cb1 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 29 Sep 2023 14:41:52 +0700 Subject: [PATCH 5/7] fix lint --- src/libs/actions/IOU.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/IOU.js b/src/libs/actions/IOU.js index 73c8f3a03075..95db21b7843a 100644 --- a/src/libs/actions/IOU.js +++ b/src/libs/actions/IOU.js @@ -1122,7 +1122,6 @@ function createSplitsAndOnyxData(participants, currentUserLogin, currentUserAcco displayName: LocalePhoneNumber.formatPhoneNumber(participant.displayName || email), login: participant.login, isOptimisticPersonalDetail: true, - }, } : undefined; From d860aead63fed03eff837b6bd9e0237c179d2d4d Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 3 Oct 2023 10:36:09 +0700 Subject: [PATCH 6/7] fix duplicate option in offline mode --- src/libs/OptionsListUtils.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index 0b10bb4a1fd1..f9a5c72b2256 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1160,7 +1160,7 @@ function getOptions( if (includePersonalDetails) { // Next loop over all personal details removing any that are selectedUsers or recentChats _.each(allPersonalDetailsOptions, (personalDetailOption) => { - if (_.some(optionsToExclude, (optionToExclude) => optionToExclude.login === personalDetailOption.login) || personalDetailOption.isOptimisticPersonalDetail) { + if (_.some(optionsToExclude, (optionToExclude) => optionToExclude.login === personalDetailOption.login)) { return; } const {searchText, participantsList, isChatRoom} = personalDetailOption; @@ -1180,7 +1180,10 @@ function getOptions( let userToInvite = null; const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption; - const noOptionsMatchExactly = !_.find(personalDetailsOptions.concat(recentReportOptions), (option) => option.login === addSMSDomainIfPhoneNumber(searchValue).toLowerCase()); + const noOptionsMatchExactly = !_.find( + personalDetailsOptions.concat(recentReportOptions), + (option) => option.login === addSMSDomainIfPhoneNumber(searchValue).toLowerCase() || option.login === searchValue, + ); if ( searchValue && @@ -1249,7 +1252,7 @@ function getOptions( } return { - personalDetails: personalDetailsOptions, + personalDetails: _.filter(personalDetailsOptions, (personalDetailsOption) => !personalDetailsOption.isOptimisticPersonalDetail), recentReports: recentReportOptions, userToInvite: canInviteUser ? userToInvite : null, currentUserOption, From 47d2eced07b6232fcdc4eedfc705e0407def3340 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 3 Oct 2023 10:38:07 +0700 Subject: [PATCH 7/7] add toLowerCase --- src/libs/OptionsListUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/OptionsListUtils.js b/src/libs/OptionsListUtils.js index f9a5c72b2256..f5b2d2ffc5b8 100644 --- a/src/libs/OptionsListUtils.js +++ b/src/libs/OptionsListUtils.js @@ -1182,7 +1182,7 @@ function getOptions( const noOptions = recentReportOptions.length + personalDetailsOptions.length === 0 && !currentUserOption; const noOptionsMatchExactly = !_.find( personalDetailsOptions.concat(recentReportOptions), - (option) => option.login === addSMSDomainIfPhoneNumber(searchValue).toLowerCase() || option.login === searchValue, + (option) => option.login === addSMSDomainIfPhoneNumber(searchValue).toLowerCase() || option.login === searchValue.toLowerCase(), ); if (