From 4a5d40bc232ef142310219c96a4bada1860f23eb Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Wed, 11 Sep 2024 22:09:10 +0530 Subject: [PATCH 1/8] fix: Remove GBR from the account settings on initial signup. Signed-off-by: krishna2323 --- src/libs/UserUtils.ts | 13 ++++++++++++- .../Profile/Contacts/ContactMethodsPage.tsx | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index c5291a2864d79..f2fa9559d0ce8 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -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'; @@ -15,6 +17,14 @@ type AvatarSource = IconAsset | string; type LoginListIndicator = ValueOf | 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. * @@ -46,7 +56,8 @@ function hasLoginListError(loginList: OnyxEntry): boolean { * has an unvalidated contact method. */ function hasLoginListInfo(loginList: OnyxEntry): boolean { - return !Object.values(loginList ?? {}).every((field) => field.validatedDate); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing + return !Object.values(loginList ?? {}).every((field) => field.validatedDate || currentUserLogin === field.partnerUserID); } /** diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index 44c7a9b567cf5..27d1b0b6520c8 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -43,9 +43,9 @@ function ContactMethodsPage({loginList, session, route}: ContactMethodsPageProps // 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 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; @@ -62,7 +62,7 @@ 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 && sortedLoginNames.length === 1) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; } From 4d3f3c8486bda1c32b68a2bda7b510acd19b551a Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Wed, 11 Sep 2024 22:24:24 +0530 Subject: [PATCH 2/8] minor fix. Signed-off-by: krishna2323 --- src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index 27d1b0b6520c8..00c58f6c12795 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -62,7 +62,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 && !isDefaultContactMethod && sortedLoginNames.length === 1) { + } 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; } From 56d75cad283c39040ecc25ac52f84f418e39ef2e Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Thu, 12 Sep 2024 01:33:08 +0530 Subject: [PATCH 3/8] filter out logins without partnerUserID. Signed-off-by: krishna2323 --- src/libs/UserUtils.ts | 7 ++++++- .../Profile/Contacts/ContactMethodsPage.tsx | 13 +++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index f2fa9559d0ce8..25ff32eab1cad 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -56,8 +56,13 @@ function hasLoginListError(loginList: OnyxEntry): boolean { * has an unvalidated contact method. */ function hasLoginListInfo(loginList: OnyxEntry): boolean { + 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(loginList ?? {}).every((field) => field.validatedDate || currentUserLogin === field.partnerUserID); + return !Object.values(filteredLoginList ?? {}).every((field) => field.validatedDate || currentUserLogin === field.partnerUserID); } /** diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index 00c58f6c12795..55731a28e1565 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -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) => { + 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; - } let description = ''; if (session?.email === login?.partnerUserID) { From bc8c598ebebf8faf1f455b65648423887aa047d1 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sun, 15 Sep 2024 17:55:00 +0530 Subject: [PATCH 4/8] minor fix. Signed-off-by: krishna2323 --- src/libs/UserUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index 25ff32eab1cad..fc3bcd1ac3fe3 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -59,10 +59,10 @@ function hasLoginListInfo(loginList: OnyxEntry): boolean { 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; + return currentUserLogin !== login.partnerUserID && (login.partnerUserID || pendingAction); }); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return !Object.values(filteredLoginList ?? {}).every((field) => field.validatedDate || currentUserLogin === field.partnerUserID); + return !!filteredLoginList.length && filteredLoginList.every((field) => field.validatedDate || currentUserLogin === field.partnerUserID); } /** From dcf9a3e682c4c70b6833a0262ef932b92524019a Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 22 Oct 2024 16:53:00 +0530 Subject: [PATCH 5/8] minor fixes. Signed-off-by: krishna2323 --- src/libs/UserUtils.ts | 6 ++---- .../settings/Profile/Contacts/ContactMethodsPage.tsx | 10 +--------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index 49bddd670d530..f64f2965adc66 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -65,12 +65,10 @@ function hasLoginListError(loginList: OnyxEntry): boolean { */ function hasLoginListInfo(loginList: OnyxEntry): boolean { 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 currentUserLogin !== login.partnerUserID && (login.partnerUserID || pendingAction); + return session?.email !== login.partnerUserID; }); // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return !!filteredLoginList.length && filteredLoginList.every((field) => field.validatedDate || currentUserLogin === field.partnerUserID); + return !!filteredLoginList.length && filteredLoginList.every((field) => field.validatedDate || session?.email === field.partnerUserID); } /** diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index 44332bf7a4294..3db0822da15ba 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -38,17 +38,9 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) { const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); const {delegatorEmail} = useDelegateUserDetails(); - const filteredLoginNames = loginNames.filter((loginName) => { - 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 = filteredLoginNames.sort((loginName) => (loginList?.[loginName].partnerUserID === session?.email ? -1 : 1)); + const sortedLoginNames = loginNames.sort((loginName) => (loginList?.[loginName].partnerUserID === session?.email ? -1 : 1)); const loginMenuItems = sortedLoginNames.map((loginName) => { const login = loginList?.[loginName]; const isDefaultContactMethod = session?.email === login?.partnerUserID; From 2015a2814b1be31913180abb980df9c7d6f514f7 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 22 Oct 2024 17:33:28 +0530 Subject: [PATCH 6/8] remove .partnerUserID check. Signed-off-by: krishna2323 --- src/libs/UserUtils.ts | 3 ++- src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx | 7 ++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index f64f2965adc66..54f21a15551c2 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -67,8 +67,9 @@ function hasLoginListInfo(loginList: OnyxEntry): boolean { const filteredLoginList = Object.values(loginList ?? {}).filter((login) => { return session?.email !== login.partnerUserID; }); + // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return !!filteredLoginList.length && filteredLoginList.every((field) => field.validatedDate || session?.email === field.partnerUserID); + return !!filteredLoginList.length && !filteredLoginList.every((field) => field.validatedDate); } /** diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index 3db0822da15ba..e86170b721244 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -38,6 +38,11 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) { const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); const {delegatorEmail} = useDelegateUserDetails(); + const filteredLoginNames = loginNames.filter((loginName) => { + const login = loginList?.[loginName]; + return login?.partnerUserID === session?.email; + }); + // 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)); @@ -59,7 +64,7 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } else if (!login?.validatedDate && !isDefaultContactMethod) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; - } else if (!login?.validatedDate && isDefaultContactMethod && sortedLoginNames.length > 1) { + } else if (!login?.validatedDate && isDefaultContactMethod && filteredLoginNames.length > 1) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; } From 32aac082bd98f5eef86770f424ef3f106f32f75b Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 22 Oct 2024 21:56:25 +0530 Subject: [PATCH 7/8] minor updates. Signed-off-by: krishna2323 --- src/libs/UserUtils.ts | 7 +------ src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx | 3 +++ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/libs/UserUtils.ts b/src/libs/UserUtils.ts index 54f21a15551c2..85a3e076684c3 100644 --- a/src/libs/UserUtils.ts +++ b/src/libs/UserUtils.ts @@ -64,12 +64,7 @@ function hasLoginListError(loginList: OnyxEntry): boolean { * has an unvalidated contact method. */ function hasLoginListInfo(loginList: OnyxEntry): boolean { - const filteredLoginList = Object.values(loginList ?? {}).filter((login) => { - return session?.email !== login.partnerUserID; - }); - - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing - return !!filteredLoginList.length && !filteredLoginList.every((field) => field.validatedDate); + return Object.values(loginList ?? {}).some((login) => session?.email !== login.partnerUserID && !login.validatedDate); } /** diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index e86170b721244..30662e520c2ef 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -50,6 +50,9 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) { 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; + } let description = ''; if (session?.email === login?.partnerUserID) { From 42daf68762675fdcb60e7be60035e5b6bb6335dd Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sat, 26 Oct 2024 02:40:40 +0530 Subject: [PATCH 8/8] fix: show GBR for default login. Signed-off-by: krishna2323 --- src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx index 30662e520c2ef..92a246949c53f 100644 --- a/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx +++ b/src/pages/settings/Profile/Contacts/ContactMethodsPage.tsx @@ -38,11 +38,6 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) { const [isNoDelegateAccessMenuVisible, setIsNoDelegateAccessMenuVisible] = useState(false); const {delegatorEmail} = useDelegateUserDetails(); - const filteredLoginNames = loginNames.filter((loginName) => { - const login = loginList?.[loginName]; - return login?.partnerUserID === session?.email; - }); - // 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)); @@ -67,7 +62,7 @@ function ContactMethodsPage({route}: ContactMethodsPageProps) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } else if (!login?.validatedDate && !isDefaultContactMethod) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; - } else if (!login?.validatedDate && isDefaultContactMethod && filteredLoginNames.length > 1) { + } else if (!login?.validatedDate && isDefaultContactMethod && loginNames.length > 1) { indicator = CONST.BRICK_ROAD_INDICATOR_STATUS.INFO; }