Skip to content

Commit

Permalink
Merge pull request #28686 from Expensify/aldo_fix-contact-method-regr…
Browse files Browse the repository at this point in the history
…ession

[CP Staging] Fix LoginList types

(cherry picked from commit 278a57e)
  • Loading branch information
mountiny authored and OSBotify committed Oct 3, 2023
1 parent 5832965 commit e3163a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
11 changes: 5 additions & 6 deletions src/libs/UserUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,24 @@ type LoginListIndicator = ValueOf<typeof CONST.BRICK_ROAD_INDICATOR_STATUS> | ''
* }
* }}
*/
function hasLoginListError(loginList: Login): boolean {
const errorFields = loginList?.errorFields ?? {};
return Object.values(errorFields).some((field) => Object.keys(field ?? {}).length > 0);
function hasLoginListError(loginList: Record<string, Login>): 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: Login): boolean {
return !loginList.validatedDate;
function hasLoginListInfo(loginList: Record<string, Login>): 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: Login): LoginListIndicator {
function getLoginListBrickRoadIndicator(loginList: Record<string, Login>): LoginListIndicator {
if (hasLoginListError(loginList)) {
return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
}
Expand Down
14 changes: 8 additions & 6 deletions src/pages/settings/InitialSettingsPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,15 @@ const propTypes = {
walletTerms: walletTermsPropTypes,

/** Login list for the user that is signed in */
loginList: PropTypes.shape({
/** Date login was validated, used to show brickroad info status */
validatedDate: PropTypes.string,
loginList: PropTypes.objectOf(
PropTypes.shape({
/** Date login was validated, used to show brickroad info status */
validatedDate: PropTypes.string,

/** Field-specific server side errors keyed by microtime */
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
}),
/** Field-specific server side errors keyed by microtime */
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
}),
),

/** Members keyed by accountID for all policies */
allPolicyMembers: PropTypes.objectOf(PropTypes.objectOf(policyMemberPropType)),
Expand Down
14 changes: 8 additions & 6 deletions src/pages/settings/Profile/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ const propTypes = {
/* Onyx Props */

/** Login list for the user that is signed in */
loginList: PropTypes.shape({
/** Date login was validated, used to show brickroad info status */
validatedDate: PropTypes.string,
loginList: PropTypes.objectOf(
PropTypes.shape({
/** Date login was validated, used to show brickroad info status */
validatedDate: PropTypes.string,

/** Field-specific server side errors keyed by microtime */
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
}),
/** Field-specific server side errors keyed by microtime */
errorFields: PropTypes.objectOf(PropTypes.objectOf(PropTypes.string)),
}),
),

user: userPropTypes,

Expand Down

0 comments on commit e3163a6

Please sign in to comment.