Skip to content

Commit

Permalink
Merge pull request #10652 from Expensify/neil-fix-policy-utils
Browse files Browse the repository at this point in the history
Fix crash from AvatarWithIndicator error checking methods

(cherry picked from commit 6989ea8)
  • Loading branch information
tgolen authored and OSBotify committed Aug 29, 2022
1 parent 5aaef55 commit 0b47836
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/components/AvatarWithIndicator.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,20 @@ const AvatarWithIndicator = (props) => {
isLarge ? styles.statusIndicatorLarge : styles.statusIndicator,
];

// If a policy was just deleted from Onyx, then Onyx will pass a null value to the props, and
// those should be cleaned out before doing any error checking
const cleanPolicies = _.filter(props.policies, policy => policy);
const cleanPolicyMembers = _.filter(props.policiesMemberList, member => member);

// All of the error-checking methods are put into an array. This is so that using _.some() will return
// early as soon as the first error is returned. This makes the error checking very efficient since
// we only care if a single error exists anywhere.
const errorCheckingMethods = [
() => !_.isEmpty(props.userWallet.errors),
() => PaymentMethods.hasPaymentMethodError(props.bankAccountList, props.cardList),
() => _.some(props.policies, PolicyUtils.hasPolicyError),
() => _.some(props.policies, PolicyUtils.hasCustomUnitsError),
() => _.some(props.policiesMemberList, PolicyUtils.hasPolicyMemberError),
() => _.some(cleanPolicies, PolicyUtils.hasPolicyError),
() => _.some(cleanPolicies, PolicyUtils.hasCustomUnitsError),
() => _.some(cleanPolicyMembers, PolicyUtils.hasPolicyMemberError),
];
const shouldShowIndicator = _.some(errorCheckingMethods, errorCheckingMethod => errorCheckingMethod());

Expand Down

0 comments on commit 0b47836

Please sign in to comment.