From 707faaa700c54d1c1a63c28033b65f6e17d27c4a Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 16 Feb 2024 23:29:28 +0700 Subject: [PATCH 1/3] fix: Unable to select members after adding them to the workspace --- src/libs/ReportUtils.ts | 14 -------------- src/pages/workspace/WorkspaceMembersPage.js | 5 ++--- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 4990fc26746d..13e858f69951 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4389,19 +4389,6 @@ function getReportOfflinePendingActionAndErrors(report: OnyxEntry): Repo return {reportPendingAction, reportErrors}; } -function getPolicyExpenseChatReportIDByOwner(policyOwner: string): string | null { - const policyWithOwner = Object.values(allPolicies ?? {}).find((policy) => policy?.owner === policyOwner); - if (!policyWithOwner) { - return null; - } - - const expenseChat = Object.values(allReports ?? {}).find((report) => isPolicyExpenseChat(report) && report?.policyID === policyWithOwner.id); - if (!expenseChat) { - return null; - } - return expenseChat.reportID; -} - /** * Check if the report can create the request with type is iouType */ @@ -5069,7 +5056,6 @@ export { getReportOfflinePendingActionAndErrors, isDM, getPolicy, - getPolicyExpenseChatReportIDByOwner, getWorkspaceChats, shouldDisableRename, hasSingleParticipant, diff --git a/src/pages/workspace/WorkspaceMembersPage.js b/src/pages/workspace/WorkspaceMembersPage.js index c88b3d56cb20..d84b7b57efaa 100644 --- a/src/pages/workspace/WorkspaceMembersPage.js +++ b/src/pages/workspace/WorkspaceMembersPage.js @@ -132,9 +132,8 @@ function WorkspaceMembersPage(props) { */ const validateSelection = useCallback(() => { const newErrors = {}; - const ownerAccountID = _.first(PersonalDetailsUtils.getAccountIDsByLogins(props.policy.owner ? [props.policy.owner] : [])); _.each(selectedEmployees, (member) => { - if (member !== ownerAccountID && member !== props.session.accountID) { + if (member !== props.policy.ownerAccountID && member !== props.session.accountID) { return; } newErrors[member] = props.translate('workspace.people.error.cannotRemove'); @@ -365,7 +364,7 @@ function WorkspaceMembersPage(props) { isSelected: _.contains(selectedEmployees, accountID), isDisabled: accountID === props.session.accountID || - details.login === props.policy.owner || + accountID === props.policy.ownerAccountID || policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !_.isEmpty(policyMember.errors), text: props.formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)), From 6c4a680d0c8801232010f3d67393ef7657c326ca Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 21 Feb 2024 11:46:57 +0700 Subject: [PATCH 2/3] fix: update owner optimistically --- src/libs/actions/User.ts | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 54efe4ba4d8e..f81f852bb24d 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -32,7 +32,7 @@ import playSound, {SOUNDS} from '@libs/Sound'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {FrequentlyUsedEmoji} from '@src/types/onyx'; +import type {FrequentlyUsedEmoji, Policy} from '@src/types/onyx'; import type Login from '@src/types/onyx/Login'; import type {OnyxServerUpdate} from '@src/types/onyx/OnyxUpdatesFromServer'; import type OnyxPersonalDetails from '@src/types/onyx/PersonalDetails'; @@ -70,6 +70,14 @@ Onyx.connect({ }, }); +let allPolicies: OnyxCollection; + +Onyx.connect({ + key: ONYXKEYS.COLLECTION.POLICY, + waitForCollectionCallback: true, + callback: (value) => (allPolicies = value), +}); + /** * Attempt to close the user's accountt */ @@ -855,6 +863,25 @@ function setContactMethodAsDefault(newDefaultContactMethod: string) { }, ]; + Object.values(allPolicies ?? {}).forEach((policy) => { + if (policy?.ownerAccountID !== currentUserAccountID) { + return; + } + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, + value: { + owner: newDefaultContactMethod, + }, + }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`, + value: { + owner: policy.owner, + }, + }); + }); const parameters: SetContactMethodAsDefaultParams = { partnerUserID: newDefaultContactMethod, }; From 27e2b6470f64a00c064d611e2992455d0007246c Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 4 Mar 2024 10:13:02 +0700 Subject: [PATCH 3/3] bump rn-onyx version 2.0.10 --- package-lock.json | 8 ++++---- package.json | 2 +- .../Profile/Contacts/ContactMethodDetailsPage.tsx | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index 80d3d1c6e911..44cabdeb2cb7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -97,7 +97,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.7", + "react-native-onyx": "2.0.10", "react-native-pager-view": "6.2.2", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", @@ -44483,9 +44483,9 @@ } }, "node_modules/react-native-onyx": { - "version": "2.0.7", - "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.7.tgz", - "integrity": "sha512-UGMUTSFxYEzNn3wuCGzaf0t6D5XwcE+3J2pYj7wPlbskdcHVLijZZEwgSSDBF7hgNfCuZ+ImetskPNktnf9hkg==", + "version": "2.0.10", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.10.tgz", + "integrity": "sha512-XHJdKBZnUyoRKrBgZlv/p6ehuFvqXqwqQlapmVwwIU40KQQes58gPy+8HnRndT3CdAeElVWZnw/BUMtiD/F3Xw==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", diff --git a/package.json b/package.json index c927c41134db..5ce77f47aedc 100644 --- a/package.json +++ b/package.json @@ -146,7 +146,7 @@ "react-native-linear-gradient": "^2.8.1", "react-native-localize": "^2.2.6", "react-native-modal": "^13.0.0", - "react-native-onyx": "2.0.7", + "react-native-onyx": "2.0.10", "react-native-pager-view": "6.2.2", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", diff --git a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx index 46bdace7292d..18589beb6353 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx @@ -308,9 +308,9 @@ export default withOnyx ({ - id: data?.id ?? '', - ownerAccountID: data?.ownerAccountID, - owner: data?.owner ?? '', - }), + id: data?.id ?? '', + ownerAccountID: data?.ownerAccountID, + owner: data?.owner ?? '', + }), }, })(ContactMethodDetailsPage);