Skip to content

Commit

Permalink
Merge pull request #36415 from kubabutkiewicz/ts-migration/SettingIni…
Browse files Browse the repository at this point in the history
…tial-page

[TS migration] Migrate 'SettingsInitial' page to TypeScript
  • Loading branch information
bondydaa authored Feb 26, 2024
2 parents b4118ba + b1b7880 commit 5dc4c07
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 127 deletions.
17 changes: 9 additions & 8 deletions src/libs/UserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {ValueOf} from 'type-fest';
import * as defaultAvatars from '@components/Icon/DefaultAvatars';
import {ConciergeAvatar, FallbackAvatar, NotificationsAvatar} from '@components/Icon/Expensicons';
import CONST from '@src/CONST';
import type {LoginList} from '@src/types/onyx';
import type Login from '@src/types/onyx/Login';
import type IconAsset from '@src/types/utils/IconAsset';
import hashCode from './hashCode';
Expand All @@ -12,7 +13,7 @@ type AvatarRange = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

type AvatarSource = IconAsset | string;

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

/**
* Searches through given loginList for any contact method / login with an error.
Expand All @@ -35,31 +36,31 @@ type LoginListIndicator = ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | ''
* }
* }}
*/
function hasLoginListError(loginList: Record<string, Login>): boolean {
return Object.values(loginList).some((loginData) => Object.values(loginData.errorFields ?? {}).some((field) => Object.keys(field ?? {}).length > 0));
function hasLoginListError(loginList: OnyxEntry<LoginList>): boolean {
return Object.values(loginList ?? {}).some((loginData) => Object.values(loginData.errorFields ?? {}).some((field) => Object.keys(field ?? {}).length > 0));
}

/**
* Searches through given loginList for any contact method / login that requires
* an Info brick road status indicator. Currently this only applies if the user
* has an unvalidated contact method.
*/
function hasLoginListInfo(loginList: Record<string, Login>): boolean {
return !Object.values(loginList).every((field) => field.validatedDate);
function hasLoginListInfo(loginList: OnyxEntry<LoginList>): boolean {
return !Object.values(loginList ?? {}).every((field) => field.validatedDate);
}

/**
* Gets the appropriate brick road indicator status for a given loginList.
* Error status is higher priority, so we check for that first.
*/
function getLoginListBrickRoadIndicator(loginList: Record<string, Login>): LoginListIndicator {
function getLoginListBrickRoadIndicator(loginList: OnyxEntry<LoginList>): LoginListIndicator {
if (hasLoginListError(loginList)) {
return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
}
if (hasLoginListInfo(loginList)) {
return CONST.BRICK_ROAD_INDICATOR_STATUS.INFO;
}
return '';
return undefined;
}

/**
Expand Down Expand Up @@ -227,4 +228,4 @@ export {
hashText,
isDefaultAvatar,
};
export type {AvatarSource};
export type {AvatarSource, LoginListIndicator};
Loading

0 comments on commit 5dc4c07

Please sign in to comment.