Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix hidden member appears in the WS members after changing default contact method #45234

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion 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 @@ -862,18 +862,27 @@ function setContactMethodAsDefault(newDefaultContactMethod: string, policies: On
if (policy?.ownerAccountID !== currentUserAccountID) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to update other policies employee list?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think so. Updated!

const currentEmployee = policy.employeeList?.[oldDefaultContactMethod] ?? {role: 'admin'};
optimisticData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
owner: newDefaultContactMethod,
employeeList: {
[oldDefaultContactMethod]: null,
[newDefaultContactMethod]: currentEmployee,
},
},
});
failureData.push({
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policy.id}`,
value: {
owner: policy.owner,
employeeList: {
[oldDefaultContactMethod]: currentEmployee,
[newDefaultContactMethod]: null,
},
},
});
});
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
Loading