From 59da2720cb8608b25cce1a6724724d640238e373 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Ch=C3=A1vez?= Date: Tue, 5 Mar 2024 17:02:26 -0600 Subject: [PATCH] Revert "fix: Unable to select members after adding them to the workspace" --- package-lock.json | 8 +++---- package.json | 2 +- src/libs/ReportUtils.ts | 14 +++++++++++ src/libs/actions/User.ts | 23 ++----------------- .../Contacts/ContactMethodDetailsPage.tsx | 19 ++++----------- src/pages/workspace/WorkspaceMembersPage.tsx | 5 ++-- 6 files changed, 28 insertions(+), 43 deletions(-) diff --git a/package-lock.json b/package-lock.json index 975cf94ad4f1..2d9d9815fbda 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.10", + "react-native-onyx": "2.0.7", "react-native-pager-view": "6.2.2", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", @@ -44783,9 +44783,9 @@ } }, "node_modules/react-native-onyx": { - "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==", + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/react-native-onyx/-/react-native-onyx-2.0.7.tgz", + "integrity": "sha512-UGMUTSFxYEzNn3wuCGzaf0t6D5XwcE+3J2pYj7wPlbskdcHVLijZZEwgSSDBF7hgNfCuZ+ImetskPNktnf9hkg==", "dependencies": { "ascii-table": "0.0.9", "fast-equals": "^4.0.3", diff --git a/package.json b/package.json index cd2754b2c8f3..37f47be90e86 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.10", + "react-native-onyx": "2.0.7", "react-native-pager-view": "6.2.2", "react-native-pdf": "6.7.3", "react-native-performance": "^5.1.0", diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 2bfcb6712109..d51fc9521838 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4549,6 +4549,19 @@ 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 */ @@ -5232,6 +5245,7 @@ export { isDM, isSelfDM, getPolicy, + getPolicyExpenseChatReportIDByOwner, getWorkspaceChats, shouldDisableRename, hasSingleParticipant, diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 7b146f7447bb..9b5ea5f172b2 100644 --- a/src/libs/actions/User.ts +++ b/src/libs/actions/User.ts @@ -33,7 +33,7 @@ import playSoundExcludingMobile from '@libs/Sound/playSoundExcludingMobile'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; -import type {BlockedFromConcierge, FrequentlyUsedEmoji, Policy} from '@src/types/onyx'; +import type {BlockedFromConcierge, FrequentlyUsedEmoji} 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'; @@ -775,7 +775,7 @@ function generateStatementPDF(period: string) { /** * Sets a contact method / secondary login as the user's "Default" contact method. */ -function setContactMethodAsDefault(newDefaultContactMethod: string, policies: OnyxCollection>) { +function setContactMethodAsDefault(newDefaultContactMethod: string) { const oldDefaultContactMethod = currentEmail; const optimisticData: OnyxUpdate[] = [ { @@ -868,25 +868,6 @@ function setContactMethodAsDefault(newDefaultContactMethod: string, policies: On }, ]; - Object.values(policies ?? {}).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, }; diff --git a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx index 18589beb6353..7de22da728dd 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodDetailsPage.tsx @@ -28,7 +28,7 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; import type SCREENS from '@src/SCREENS'; -import type {LoginList, Policy, SecurityGroup, Session as TSession} from '@src/types/onyx'; +import type {LoginList, SecurityGroup, Session as TSession} from '@src/types/onyx'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; import ValidateCodeForm from './ValidateCodeForm'; import type {ValidateCodeFormHandle} from './ValidateCodeForm/BaseValidateCodeForm'; @@ -48,14 +48,11 @@ type ContactMethodDetailsPageOnyxProps = { /** Indicated whether the report data is loading */ isLoadingReportData: OnyxEntry; - - /** The list of this user's policies */ - policies: OnyxCollection>; }; type ContactMethodDetailsPageProps = ContactMethodDetailsPageOnyxProps & StackScreenProps; -function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, securityGroups, isLoadingReportData = true, route, policies}: ContactMethodDetailsPageProps) { +function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, securityGroups, isLoadingReportData = true, route}: ContactMethodDetailsPageProps) { const {formatPhoneNumber, translate} = useLocalize(); const theme = useTheme(); const themeStyles = useThemeStyles(); @@ -91,8 +88,8 @@ function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, s * Attempt to set this contact method as user's "Default contact method" */ const setAsDefault = useCallback(() => { - User.setContactMethodAsDefault(contactMethod, policies); - }, [contactMethod, policies]); + User.setContactMethodAsDefault(contactMethod); + }, [contactMethod]); /** * Checks if the user is allowed to change their default contact method. This should only be allowed if: @@ -305,12 +302,4 @@ export default withOnyx ({ - id: data?.id ?? '', - ownerAccountID: data?.ownerAccountID, - owner: data?.owner ?? '', - }), - }, })(ContactMethodDetailsPage); diff --git a/src/pages/workspace/WorkspaceMembersPage.tsx b/src/pages/workspace/WorkspaceMembersPage.tsx index b43659a776d9..718f2b6d9ad2 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -113,8 +113,9 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se */ const validateSelection = useCallback(() => { const newErrors: Errors = {}; + const ownerAccountID = PersonalDetailsUtils.getAccountIDsByLogins(policy?.owner ? [policy.owner] : [])[0]; selectedEmployees.forEach((member) => { - if (member !== policy?.ownerAccountID && member !== session?.accountID) { + if (member !== ownerAccountID && member !== session?.accountID) { return; } newErrors[member] = translate('workspace.people.error.cannotRemove'); @@ -325,7 +326,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se isSelected, isDisabled: accountID === session?.accountID || - accountID === policy?.ownerAccountID || + details.login === policy?.owner || policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !isEmptyObject(policyMember.errors), text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),