Skip to content

Commit

Permalink
update all policy employee list too
Browse files Browse the repository at this point in the history
  • Loading branch information
bernhardoj committed Jul 11, 2024
1 parent a285736 commit bd11b4f
Showing 1 changed file with 36 additions and 16 deletions.
52 changes: 36 additions & 16 deletions src/libs/actions/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -859,32 +859,52 @@ function setContactMethodAsDefault(newDefaultContactMethod: string, policies: On
];

Object.values(policies ?? {}).forEach((policy) => {
if (policy?.ownerAccountID !== currentUserAccountID) {
if (!policy) {
return;
}
const currentEmployee = policy.employeeList?.[oldDefaultContactMethod] ?? {role: 'admin'};
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
owner: newDefaultContactMethod,

let optimisticPolicyDataValue;
let failurePolicyDataValue;

if (policy.employeeList) {
const currentEmployee = policy.employeeList[oldDefaultContactMethod];
optimisticPolicyDataValue = {
employeeList: {
[oldDefaultContactMethod]: null,
[newDefaultContactMethod]: currentEmployee,
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
owner: policy.owner,
};
failurePolicyDataValue = {
employeeList: {
[oldDefaultContactMethod]: currentEmployee,
[newDefaultContactMethod]: null,
},
},
});
};
}

if (policy.ownerAccountID === currentUserAccountID) {
optimisticPolicyDataValue = {
...optimisticPolicyDataValue,
owner: newDefaultContactMethod,
};
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

0 comments on commit bd11b4f

Please sign in to comment.