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/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index b2fb456681cf..284c56ce2c1e 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4523,19 +4523,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 */ @@ -5219,7 +5206,6 @@ export { isDM, isSelfDM, getPolicy, - getPolicyExpenseChatReportIDByOwner, getWorkspaceChats, shouldDisableRename, hasSingleParticipant, diff --git a/src/libs/actions/User.ts b/src/libs/actions/User.ts index 5d089ed6e393..a14e752b1015 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} from '@src/types/onyx'; +import type {BlockedFromConcierge, 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'; @@ -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) { +function setContactMethodAsDefault(newDefaultContactMethod: string, policies: OnyxCollection>) { const oldDefaultContactMethod = currentEmail; const optimisticData: OnyxUpdate[] = [ { @@ -868,6 +868,25 @@ function setContactMethodAsDefault(newDefaultContactMethod: string) { }, ]; + 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 7de22da728dd..18589beb6353 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, SecurityGroup, Session as TSession} from '@src/types/onyx'; +import type {LoginList, Policy, 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,11 +48,14 @@ 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}: ContactMethodDetailsPageProps) { +function ContactMethodDetailsPage({loginList, session, myDomainSecurityGroups, securityGroups, isLoadingReportData = true, route, policies}: ContactMethodDetailsPageProps) { const {formatPhoneNumber, translate} = useLocalize(); const theme = useTheme(); const themeStyles = useThemeStyles(); @@ -88,8 +91,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); - }, [contactMethod]); + User.setContactMethodAsDefault(contactMethod, policies); + }, [contactMethod, policies]); /** * Checks if the user is allowed to change their default contact method. This should only be allowed if: @@ -302,4 +305,12 @@ 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 718f2b6d9ad2..b43659a776d9 100644 --- a/src/pages/workspace/WorkspaceMembersPage.tsx +++ b/src/pages/workspace/WorkspaceMembersPage.tsx @@ -113,9 +113,8 @@ 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 !== ownerAccountID && member !== session?.accountID) { + if (member !== policy?.ownerAccountID && member !== session?.accountID) { return; } newErrors[member] = translate('workspace.people.error.cannotRemove'); @@ -326,7 +325,7 @@ function WorkspaceMembersPage({policyMembers, personalDetails, route, policy, se isSelected, isDisabled: accountID === session?.accountID || - details.login === policy?.owner || + accountID === policy?.ownerAccountID || policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !isEmptyObject(policyMember.errors), text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),