From 4fd9ad5239e3b74a460e238e055eedd616c07571 Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Tue, 25 Apr 2023 00:22:32 +0700
Subject: [PATCH 1/3] fix: RBR not show on error workspace in workspace list
 page

---
 src/libs/PolicyUtils.js                   | 12 ++++++++++++
 src/pages/workspace/WorkspacesListPage.js |  6 +++++-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js
index 632fddcf1182..985634439a71 100644
--- a/src/libs/PolicyUtils.js
+++ b/src/libs/PolicyUtils.js
@@ -29,6 +29,17 @@ function hasPolicyError(policy) {
         : _.some(lodashGet(policy, 'errorFields', {}), fieldErrors => !_.isEmpty(fieldErrors));
 }
 
+/**
+ * Check if the policy has any error fields.
+ *
+ * @param {Object} policy
+ * @param {Object} policy.errorFields
+ * @return {Boolean}
+ */
+function hasPolicyErrorFields(policy) {
+    return _.some(lodashGet(policy, 'errorFields', {}), fieldErrors => !_.isEmpty(fieldErrors));
+}
+
 /**
  * Checks if we have any errors stored within the policy custom units.
  *
@@ -88,6 +99,7 @@ function isExpensifyTeam(email) {
 export {
     hasPolicyMemberError,
     hasPolicyError,
+    hasPolicyErrorFields,
     hasCustomUnitsError,
     getPolicyBrickRoadIndicatorStatus,
     shouldShowPolicy,
diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js
index 34a4c8ada779..1d45a84aa679 100755
--- a/src/pages/workspace/WorkspacesListPage.js
+++ b/src/pages/workspace/WorkspacesListPage.js
@@ -131,7 +131,11 @@ class WorkspacesListPage extends Component {
                 action: () => Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policy.id)),
                 iconFill: themeColors.textLight,
                 fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
-                brickRoadIndicator: reimbursementAccountBrickRoadIndicator || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, this.props.policyMembers),
+                brickRoadIndicator:
+                    PolicyUtils.hasPolicyErrorFields(policy)
+                    || reimbursementAccountBrickRoadIndicator
+                    || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, this.props.policyMembers)
+                        ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : null,
                 pendingAction: policy.pendingAction,
                 errors: policy.errors,
                 dismissError: () => dismissWorkspaceError(policy.id, policy.pendingAction),

From 70a9407680b6faced8b35c2769dbe68a562aa224 Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Fri, 28 Apr 2023 11:48:45 +0700
Subject: [PATCH 2/3] add errorFields check to getPolicyBrickRoadIndicator

---
 src/libs/PolicyUtils.js                   | 2 +-
 src/pages/workspace/WorkspacesListPage.js | 6 +-----
 2 files changed, 2 insertions(+), 6 deletions(-)

diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js
index 985634439a71..0834154a2349 100644
--- a/src/libs/PolicyUtils.js
+++ b/src/libs/PolicyUtils.js
@@ -60,7 +60,7 @@ function hasCustomUnitsError(policy) {
  */
 function getPolicyBrickRoadIndicatorStatus(policy, policyMembers) {
     const policyMemberList = lodashGet(policyMembers, `${ONYXKEYS.COLLECTION.POLICY_MEMBER_LIST}${policy.id}`, {});
-    if (hasPolicyMemberError(policyMemberList) || hasCustomUnitsError(policy)) {
+    if (hasPolicyMemberError(policyMemberList) || hasCustomUnitsError(policy) || hasPolicyErrorFields(policy)) {
         return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR;
     }
     return '';
diff --git a/src/pages/workspace/WorkspacesListPage.js b/src/pages/workspace/WorkspacesListPage.js
index 1d45a84aa679..34a4c8ada779 100755
--- a/src/pages/workspace/WorkspacesListPage.js
+++ b/src/pages/workspace/WorkspacesListPage.js
@@ -131,11 +131,7 @@ class WorkspacesListPage extends Component {
                 action: () => Navigation.navigate(ROUTES.getWorkspaceInitialRoute(policy.id)),
                 iconFill: themeColors.textLight,
                 fallbackIcon: Expensicons.FallbackWorkspaceAvatar,
-                brickRoadIndicator:
-                    PolicyUtils.hasPolicyErrorFields(policy)
-                    || reimbursementAccountBrickRoadIndicator
-                    || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, this.props.policyMembers)
-                        ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : null,
+                brickRoadIndicator: reimbursementAccountBrickRoadIndicator || PolicyUtils.getPolicyBrickRoadIndicatorStatus(policy, this.props.policyMembers),
                 pendingAction: policy.pendingAction,
                 errors: policy.errors,
                 dismissError: () => dismissWorkspaceError(policy.id, policy.pendingAction),

From 70d4734aa4329165cbc37f69990fbce8d7654517 Mon Sep 17 00:00:00 2001
From: tienifr <christianwen18@gmail.com>
Date: Fri, 28 Apr 2023 11:49:59 +0700
Subject: [PATCH 3/3] refactor to reuse hasPolicyErrorFields

---
 src/libs/PolicyUtils.js | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/libs/PolicyUtils.js b/src/libs/PolicyUtils.js
index 0834154a2349..6828ddae662d 100644
--- a/src/libs/PolicyUtils.js
+++ b/src/libs/PolicyUtils.js
@@ -16,28 +16,28 @@ function hasPolicyMemberError(policyMemberList) {
 }
 
 /**
- * Check if the policy has any errors, and if it doesn't, then check if it has any error fields.
+ * Check if the policy has any error fields.
  *
  * @param {Object} policy
- * @param {Object} policy.errors
  * @param {Object} policy.errorFields
  * @return {Boolean}
  */
-function hasPolicyError(policy) {
-    return !_.isEmpty(lodashGet(policy, 'errors', {}))
-        ? true
-        : _.some(lodashGet(policy, 'errorFields', {}), fieldErrors => !_.isEmpty(fieldErrors));
+function hasPolicyErrorFields(policy) {
+    return _.some(lodashGet(policy, 'errorFields', {}), fieldErrors => !_.isEmpty(fieldErrors));
 }
 
 /**
- * Check if the policy has any error fields.
+ * 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.errors
  * @param {Object} policy.errorFields
  * @return {Boolean}
  */
-function hasPolicyErrorFields(policy) {
-    return _.some(lodashGet(policy, 'errorFields', {}), fieldErrors => !_.isEmpty(fieldErrors));
+function hasPolicyError(policy) {
+    return !_.isEmpty(lodashGet(policy, 'errors', {}))
+        ? true
+        : hasPolicyErrorFields(policy);
 }
 
 /**
@@ -51,7 +51,7 @@ function hasCustomUnitsError(policy) {
 }
 
 /**
- * Get the brick road indicator status for a policy. The policy has an error status if there is a policy member error or a policy error.
+ * Get the brick road indicator status for a policy. The policy has an error status if there is a policy member error, a custom unit error or a field error.
  *
  * @param {Object} policy
  * @param {String} policy.id
