Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash from AvatarWithIndicator error checking methods #10652

Merged
merged 4 commits into from
Aug 29, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/libs/PolicyUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,28 @@ import ONYXKEYS from '../ONYXKEYS';
* Checks if we have any errors stored within the POLICY_MEMBER_LIST. Determines whether we should show a red brick road error or not.
* Data structure: {email: {role:'user', errors: []}, email2: {role:'admin', errors: [{1231312313: 'Unable to do X'}]}, ...}
*
* @param {Object} policyMemberList
* @param {Object} [policyMemberList]
* @returns {Boolean}
*/
function hasPolicyMemberError(policyMemberList) {
if (!policyMemberList) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary since it works OK to pass undefined to _.some()

image

return false;
}
return _.some(policyMemberList, member => !_.isEmpty(member.errors));
}

/**
* Check if the policy has any errors, and if it doesn't, then check if it has any error fields.
*
* @param {Object} policy
* @param {Object} [policy]
* @param {Object} policy.errors
* @param {Object} policy.errorFields
* @return {Boolean}
*/
function hasPolicyError(policy) {
if (!policy) {
return false;
}
return !_.isEmpty(policy.errors)
? true
: _.some(policy.errorFields, fieldErrors => !_.isEmpty(fieldErrors));
Expand All @@ -31,10 +37,13 @@ function hasPolicyError(policy) {
/**
* Checks if we have any errors stored within the policy custom units.
*
* @param {Object} policy
* @param {Object} [policy]
* @returns {Boolean}
*/
function hasCustomUnitsError(policy) {
if (!policy) {
return false;
}
return !_.isEmpty(_.pick(policy.customUnits, 'errors'));
}

Expand Down