11import { Str } from 'expensify-common' ;
22import type { OnyxEntry } from 'react-native-onyx' ;
3- import Onyx from 'react-native-onyx' ;
43import type { ValueOf } from 'type-fest' ;
54import * as defaultAvatars from '@components/Icon/DefaultAvatars' ;
65import { ConciergeAvatar , NotificationsAvatar } from '@components/Icon/Expensicons' ;
76import CONST from '@src/CONST' ;
8- import ONYXKEYS from '@src/ONYXKEYS' ;
9- import type { Account , LoginList , PrivatePersonalDetails , Session , VacationDelegate } from '@src/types/onyx' ;
7+ import type { LoginList , PrivatePersonalDetails , VacationDelegate } from '@src/types/onyx' ;
108import type Login from '@src/types/onyx/Login' ;
119import { isEmptyObject } from '@src/types/utils/EmptyObject' ;
1210import type IconAsset from '@src/types/utils/IconAsset' ;
@@ -18,22 +16,6 @@ type AvatarSource = IconAsset | string;
1816
1917type LoginListIndicator = ValueOf < typeof CONST . BRICK_ROAD_INDICATOR_STATUS > | undefined ;
2018
21- let account : OnyxEntry < Account > ;
22- Onyx . connect ( {
23- key : ONYXKEYS . ACCOUNT ,
24- callback : ( value ) => {
25- account = value ?? { } ;
26- } ,
27- } ) ;
28-
29- let session : OnyxEntry < Session > ;
30- Onyx . connect ( {
31- key : ONYXKEYS . SESSION ,
32- callback : ( value ) => {
33- session = value ?? { } ;
34- } ,
35- } ) ;
36-
3719/**
3820 * Searches through given loginList for any contact method / login with an error.
3921 *
@@ -64,30 +46,30 @@ function hasLoginListError(loginList: OnyxEntry<LoginList>): boolean {
6446 * an Info brick road status indicator. Currently this only applies if the user
6547 * has an unvalidated contact method.
6648 */
67- function hasLoginListInfo ( loginList : OnyxEntry < LoginList > ) : boolean {
68- return Object . values ( loginList ?? { } ) . some ( ( login ) => session ?. email !== login . partnerUserID && ! login . validatedDate ) ;
49+ function hasLoginListInfo ( loginList : OnyxEntry < LoginList > , email : string | undefined ) : boolean {
50+ return Object . values ( loginList ?? { } ) . some ( ( login ) => email !== login . partnerUserID && ! login . validatedDate ) ;
6951}
7052
7153/**
7254 * Checks if the current user has a validated the primary contact method
7355 */
74- function isCurrentUserValidated ( loginList : OnyxEntry < LoginList > ) : boolean {
75- if ( ! loginList || ! session ?. email ) {
56+ function isCurrentUserValidated ( loginList : OnyxEntry < LoginList > , email : string | undefined ) : boolean {
57+ if ( ! loginList || ! email ) {
7658 return false ;
7759 }
7860
79- return ! ! loginList ?. [ session . email ] ?. validatedDate ;
61+ return ! ! loginList ?. [ email ] ?. validatedDate ;
8062}
8163
8264/**
8365 * Gets the appropriate brick road indicator status for a given loginList.
8466 * Error status is higher priority, so we check for that first.
8567 */
86- function getLoginListBrickRoadIndicator ( loginList : OnyxEntry < LoginList > ) : LoginListIndicator {
68+ function getLoginListBrickRoadIndicator ( loginList : OnyxEntry < LoginList > , email : string | undefined ) : LoginListIndicator {
8769 if ( hasLoginListError ( loginList ) ) {
8870 return CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR ;
8971 }
90- if ( hasLoginListInfo ( loginList ) ) {
72+ if ( hasLoginListInfo ( loginList , email ) ) {
9173 return CONST . BRICK_ROAD_INDICATOR_STATUS . INFO ;
9274 }
9375
@@ -102,12 +84,13 @@ function getProfilePageBrickRoadIndicator(
10284 loginList : OnyxEntry < LoginList > ,
10385 privatePersonalDetails : OnyxEntry < PrivatePersonalDetails > ,
10486 vacationDelegate : OnyxEntry < VacationDelegate > ,
87+ email : string | undefined ,
10588) : LoginListIndicator {
10689 const hasPhoneNumberError = ! ! privatePersonalDetails ?. errorFields ?. phoneNumber ;
10790 if ( hasLoginListError ( loginList ) || hasPhoneNumberError || ! isEmptyObject ( vacationDelegate ?. errors ) ) {
10891 return CONST . BRICK_ROAD_INDICATOR_STATUS . ERROR ;
10992 }
110- if ( hasLoginListInfo ( loginList ) ) {
93+ if ( hasLoginListInfo ( loginList , email ) ) {
11194 return CONST . BRICK_ROAD_INDICATOR_STATUS . INFO ;
11295 }
11396
@@ -262,8 +245,8 @@ function getSecondaryPhoneLogin(loginList: OnyxEntry<Login>): string | undefined
262245/**
263246 * Gets the contact method
264247 */
265- function getContactMethod ( ) : string {
266- return account ?. primaryLogin ?? session ?. email ?? '' ;
248+ function getContactMethod ( primaryLogin : string | undefined , email : string | undefined ) : string {
249+ return primaryLogin ?? email ?? '' ;
267250}
268251
269252export {
0 commit comments