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: Remove GBR from the account settings on initial signup. #49004

Merged
merged 11 commits into from
Oct 30, 2024
18 changes: 17 additions & 1 deletion src/libs/UserUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {Str} from 'expensify-common';
import type {OnyxEntry} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import * as defaultAvatars from '@components/Icon/DefaultAvatars';
import {ConciergeAvatar, NotificationsAvatar} from '@components/Icon/Expensicons';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {LoginList} from '@src/types/onyx';
import type Login from '@src/types/onyx/Login';
import type IconAsset from '@src/types/utils/IconAsset';
Expand All @@ -15,6 +17,14 @@ type AvatarSource = IconAsset | string;

type LoginListIndicator = ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | undefined;

let currentUserLogin: string | undefined;
Onyx.connect({
key: ONYXKEYS.SESSION,
callback: (value) => {
currentUserLogin = value?.email;
},
});

/**
* Searches through given loginList for any contact method / login with an error.
*
Expand Down Expand Up @@ -46,7 +56,13 @@ function hasLoginListError(loginList: OnyxEntry<LoginList>): boolean {
* has an unvalidated contact method.
*/
function hasLoginListInfo(loginList: OnyxEntry<LoginList>): boolean {
return !Object.values(loginList ?? {}).every((field) => field.validatedDate);
const filteredLoginList = Object.values(loginList ?? {}).filter((login) => {
const pendingAction = login?.pendingFields?.deletedLogin ?? login?.pendingFields?.addedLogin ?? undefined;
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return login.partnerUserID || pendingAction;
});
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return !Object.values(filteredLoginList ?? {}).every((field) => field.validatedDate || currentUserLogin === field.partnerUserID);
Copy link
Contributor

Choose a reason for hiding this comment

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

If the above filter is necessary, then filteredLoginList will be an array, so Object.values isn't needed. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

}

/**
Expand Down
19 changes: 13 additions & 6 deletions src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,21 @@ function ContactMethodsPage({loginList, session, route}: ContactMethodsPageProps
const loginNames = Object.keys(loginList ?? {});
const navigateBackTo = route?.params?.backTo;

const filteredLoginNames = loginNames.filter((loginName) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is filter needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to filter out the temporary validation email to avoid showing the GBR when there is only one contact method. For example, when logging in with a phone number and adding a new contact method, the default contact method is added without the SMS domain.

Monosnap.screencast.2024-09-15.17-47-33.mp4

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you for your detailed explanation! I just asked in another PR whether this behavior is normal. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ntdiary, can you please re-test these, I have made the necessary changes.

Copy link
Contributor

@ntdiary ntdiary Oct 22, 2024

Choose a reason for hiding this comment

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

image

Extra key in the loginList is no longer being added now. :)

const login = loginList?.[loginName];
const pendingAction = login?.pendingFields?.deletedLogin ?? login?.pendingFields?.addedLogin ?? undefined;

// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
return login?.partnerUserID || pendingAction;
});

// Sort the login names by placing the one corresponding to the default contact method as the first item before displaying the contact methods.
// The default contact method is determined by checking against the session email (the current login).
const sortedLoginNames = loginNames.sort((loginName) => (loginList?.[loginName].partnerUserID === session?.email ? -1 : 1));

const sortedLoginNames = filteredLoginNames.sort((loginName) => (loginList?.[loginName].partnerUserID === session?.email ? -1 : 1));
const loginMenuItems = sortedLoginNames.map((loginName) => {
const login = loginList?.[loginName];
const isDefaultContactMethod = session?.email === login?.partnerUserID;
const pendingAction = login?.pendingFields?.deletedLogin ?? login?.pendingFields?.addedLogin ?? undefined;
if (!login?.partnerUserID && !pendingAction) {
return null;
}
Krishna2323 marked this conversation as resolved.
Show resolved Hide resolved

let description = '';
if (session?.email === login?.partnerUserID) {
Expand All @@ -62,7 +67,9 @@ function ContactMethodsPage({loginList, session, route}: ContactMethodsPageProps
let indicator;
if (Object.values(login?.errorFields ?? {}).some((errorField) => !isEmptyObject(errorField))) {
indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
} else if (!login?.validatedDate) {
} else if (!login?.validatedDate && !isDefaultContactMethod) {
indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO;
} else if (!login?.validatedDate && isDefaultContactMethod && sortedLoginNames.length > 1) {
indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO;
}

Expand Down
Loading