Skip to content

Commit

Permalink
Merge pull request #45234 from bernhardoj/fix/44705-hidden-member-app…
Browse files Browse the repository at this point in the history
…ears-after-change-default-contact-method
  • Loading branch information
blimpich authored Jul 15, 2024
2 parents c8bd2bb + bd11b4f commit 1f28763
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 15 deletions.
57 changes: 43 additions & 14 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ function generateStatementPDF(period: string) {
/**
* Sets a contact method / secondary login as the user's "Default" contact method.
*/
function setContactMethodAsDefault(newDefaultContactMethod: string, policies: OnyxCollection<Pick<Policy, 'id' | 'ownerAccountID' | 'owner'>>) {
function setContactMethodAsDefault(newDefaultContactMethod: string, policies: OnyxCollection<Pick<Policy, 'id' | 'ownerAccountID' | 'owner' | 'employeeList'>>) {
const oldDefaultContactMethod = currentEmail;
const optimisticData: OnyxUpdate[] = [
{
Expand Down Expand Up @@ -859,23 +859,52 @@ function setContactMethodAsDefault(newDefaultContactMethod: string, policies: On
];

Object.values(policies ?? {}).forEach((policy) => {
if (policy?.ownerAccountID !== currentUserAccountID) {
if (!policy) {
return;
}
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {

let optimisticPolicyDataValue;
let failurePolicyDataValue;

if (policy.employeeList) {
const currentEmployee = policy.employeeList[oldDefaultContactMethod];
optimisticPolicyDataValue = {
employeeList: {
[oldDefaultContactMethod]: null,
[newDefaultContactMethod]: currentEmployee,
},
};
failurePolicyDataValue = {
employeeList: {
[oldDefaultContactMethod]: currentEmployee,
[newDefaultContactMethod]: null,
},
};
}

if (policy.ownerAccountID === currentUserAccountID) {
optimisticPolicyDataValue = {
...optimisticPolicyDataValue,
owner: newDefaultContactMethod,
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
};
failurePolicyDataValue = {
...failurePolicyDataValue,
owner: policy.owner,
},
});
};
}

if (optimisticPolicyDataValue && failurePolicyDataValue) {
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: optimisticPolicyDataValue,
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: failurePolicyDataValue,
});
}
});
const parameters: SetContactMethodAsDefaultParams = {
partnerUserID: newDefaultContactMethod,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@ import isLoadingOnyxValue from '@src/types/utils/isLoadingOnyxValue';
import ValidateCodeForm from './ValidateCodeForm';
import type {ValidateCodeFormHandle} from './ValidateCodeForm/BaseValidateCodeForm';

const policiesSelector = (policy: OnyxEntry<Policy>): Pick<Policy, 'id' | 'ownerAccountID' | 'owner'> => ({
const policiesSelector = (policy: OnyxEntry<Policy>): Pick<Policy, 'id' | 'ownerAccountID' | 'owner' | 'employeeList'> => ({
id: policy?.id ?? '-1',
ownerAccountID: policy?.ownerAccountID,
owner: policy?.owner ?? '',
employeeList: policy?.employeeList,
});

type ContactMethodDetailsPageProps = StackScreenProps<SettingsNavigatorParamList, typeof SCREENS.SETTINGS.PROFILE.CONTACT_METHOD_DETAILS>;
Expand Down

0 comments on commit 1f28763

Please sign in to comment.