From 6db0aa7ad753f460d93242f7385ca5cfef870484 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Tue, 6 Feb 2024 07:45:51 +0700
Subject: [PATCH 01/12] fix auto select category and tag

---
 ...oraryForRefactorRequestConfirmationList.js | 20 +++++++++++++++++--
 .../step/IOURequestStepConfirmation.js        |  2 +-
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index be5cec7a2c0d..f13e2bc651c8 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -477,6 +477,22 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         IOU.setMoneyRequestMerchant_temporaryForRefactor(transaction.transactionID, distanceMerchant);
     }, [hasRoute, distance, unit, rate, currency, translate, toLocaleDigit, isDistanceRequest, transaction]);
 
+    useEffect(() => {
+        const enabledCategories = _.filter(policyCategories, (category) => category.enabled);
+        if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1) {
+            return;
+        }
+        IOU.setMoneyRequestCategory_temporaryForRefactor(transaction.transactionID, enabledCategories[0].name);
+    }, [iouCategory, shouldShowCategories, policyCategories, transaction]);
+
+    useEffect(() => {
+        const enabledTags = _.filter(policyTagList, (tag) => tag.enabled);
+        if (iouTag || !shouldShowTags || enabledTags.length !== 1) {
+            return;
+        }
+        IOU.setMoneyRequestTag(transaction.transactionID, enabledTags[0].name);
+    }, [shouldShowTags, policyTagList, iouTag, transaction]);
+
     /**
      * @param {Object} option
      */
@@ -885,10 +901,10 @@ export default compose(
             key: ONYXKEYS.SESSION,
         },
         policyCategories: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${'76EBA6DE3ECECC33'}`,
         },
         policyTags: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${'76EBA6DE3ECECC33'}`,
         },
         mileageRate: {
             key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js
index 0f1c2b27ad2e..13a57073667f 100644
--- a/src/pages/iou/request/step/IOURequestStepConfirmation.js
+++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js
@@ -399,7 +399,7 @@ export default compose(
             key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
         },
         policyCategories: {
-            key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
+            key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${"76EBA6DE3ECECC33"}`,
         },
         policyTags: {
             key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,

From 61f9d38188051c61398ae88c7f916c4150a5964d Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Tue, 6 Feb 2024 08:27:11 +0700
Subject: [PATCH 02/12] fix remove hardcode

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js       | 4 ++--
 src/pages/iou/request/step/IOURequestStepConfirmation.js      | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index f13e2bc651c8..19ae722237ff 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -901,10 +901,10 @@ export default compose(
             key: ONYXKEYS.SESSION,
         },
         policyCategories: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${'76EBA6DE3ECECC33'}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`,
         },
         policyTags: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${'76EBA6DE3ECECC33'}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
         },
         mileageRate: {
             key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js
index 13a57073667f..0eb9cc9c84e6 100644
--- a/src/pages/iou/request/step/IOURequestStepConfirmation.js
+++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js
@@ -399,7 +399,7 @@ export default compose(
             key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
         },
         policyCategories: {
-            key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${"76EBA6DE3ECECC33"}`,
+            key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report.policyID}`,
         },
         policyTags: {
             key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,

From 142587c87f015fdc03464ce9ddc9534d9dbaa12f Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Tue, 6 Feb 2024 08:28:31 +0700
Subject: [PATCH 03/12] fix typo

---
 src/pages/iou/request/step/IOURequestStepConfirmation.js | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pages/iou/request/step/IOURequestStepConfirmation.js b/src/pages/iou/request/step/IOURequestStepConfirmation.js
index 0eb9cc9c84e6..0f1c2b27ad2e 100644
--- a/src/pages/iou/request/step/IOURequestStepConfirmation.js
+++ b/src/pages/iou/request/step/IOURequestStepConfirmation.js
@@ -399,7 +399,7 @@ export default compose(
             key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY}${report ? report.policyID : '0'}`,
         },
         policyCategories: {
-            key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report.policyID}`,
+            key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${report ? report.policyID : '0'}`,
         },
         policyTags: {
             key: ({report}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${report ? report.policyID : '0'}`,

From 5a3120b07ee9c8236f1bdf8ea71deaec90af7f49 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Wed, 7 Feb 2024 17:59:27 +0700
Subject: [PATCH 04/12] fix add comment

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js         | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index 19ae722237ff..54802f9fb6fb 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -477,6 +477,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         IOU.setMoneyRequestMerchant_temporaryForRefactor(transaction.transactionID, distanceMerchant);
     }, [hasRoute, distance, unit, rate, currency, translate, toLocaleDigit, isDistanceRequest, transaction]);
 
+    // Auto select the category if there is only one enabled category
     useEffect(() => {
         const enabledCategories = _.filter(policyCategories, (category) => category.enabled);
         if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1) {
@@ -485,6 +486,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         IOU.setMoneyRequestCategory_temporaryForRefactor(transaction.transactionID, enabledCategories[0].name);
     }, [iouCategory, shouldShowCategories, policyCategories, transaction]);
 
+    // Auto select the tag if there is only one enabled tag
     useEffect(() => {
         const enabledTags = _.filter(policyTagList, (tag) => tag.enabled);
         if (iouTag || !shouldShowTags || enabledTags.length !== 1) {

From 6241f859dabd9c70909c71d1b3c38a11dab48056 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Mon, 19 Feb 2024 14:49:56 +0700
Subject: [PATCH 05/12] fix handle multiple tags

---
 ...oraryForRefactorRequestConfirmationList.js | 33 ++++++++++++-------
 1 file changed, 21 insertions(+), 12 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index 25692e07ff99..e93f4bdf8783 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -481,23 +481,29 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         IOU.setMoneyRequestMerchant(transaction.transactionID, distanceMerchant, true);
     }, [isDistanceRequestWithPendingRoute, hasRoute, distance, unit, rate, currency, translate, toLocaleDigit, isDistanceRequest, transaction]);
 
-    // Auto select the category if there is only one enabled category
+    // Auto select the category if there is only one enabled category and it is required
     useEffect(() => {
         const enabledCategories = _.filter(policyCategories, (category) => category.enabled);
-        if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1) {
+        if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1 || !isCategoryRequired) {
             return;
         }
         IOU.setMoneyRequestCategory_temporaryForRefactor(transaction.transactionID, enabledCategories[0].name);
-    }, [iouCategory, shouldShowCategories, policyCategories, transaction]);
+    }, [iouCategory, shouldShowCategories, policyCategories, transaction, isCategoryRequired]);
 
-    // Auto select the tag if there is only one enabled tag
+    // Auto select the tag if there is only one enabled tag and it is required
     useEffect(() => {
-        const enabledTags = _.filter(policyTagList, (tag) => tag.enabled);
-        if (iouTag || !shouldShowTags || enabledTags.length !== 1) {
-            return;
+        let updatedTagsString = '';
+        policyTagLists.forEach((tagList, index) => {
+            const enabledTags = _.filter(tagList.tags, (tag) => tag.enabled);
+            if (enabledTags.length !== 1 || !tagList.required || TransactionUtils.getTag(transaction, index)) {
+                return;
+            }
+            updatedTagsString = IOUUtils.insertTagIntoReportTagsString(updatedTagsString, enabledTags[0].name, index);
+        });
+        if (updatedTagsString !== TransactionUtils.getTag(transaction) && updatedTagsString) {
+            IOU.setMoneyRequestTag(transaction.transactionID, updatedTagsString);
         }
-        IOU.setMoneyRequestTag(transaction.transactionID, enabledTags[0].name);
-    }, [shouldShowTags, policyTagList, iouTag, transaction]);
+    }, [policyTagLists, transaction]);
 
     /**
      * @param {Object} option
@@ -554,17 +560,20 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
                 const decimals = CurrencyUtils.getCurrencyDecimals(iouCurrencyCode);
                 if (isDistanceRequest && !isDistanceRequestWithPendingRoute && !MoneyRequestUtils.validateAmount(String(iouAmount), decimals)) {
                     setFormError('common.error.invalidAmount');
+                    console.log('333333333333333333 step 2', {selectedParticipants});
                     return;
                 }
 
                 if (isEditingSplitBill && TransactionUtils.areRequiredFieldsEmpty(transaction)) {
                     setDidConfirmSplit(true);
                     setFormError('iou.error.genericSmartscanFailureMessage');
+                    console.log('333333333333333333 step 3', {selectedParticipants});
                     return;
                 }
 
                 playSound(SOUNDS.DONE);
                 setDidConfirm(true);
+                console.log('111111111111111111111111');
                 onConfirm(selectedParticipants);
             }
         },
@@ -938,17 +947,17 @@ export default compose(
             key: ONYXKEYS.SESSION,
         },
         policyCategories: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${'062D53707053B5B9'}`,
         },
         policyTags: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${'062D53707053B5B9'}`,
         },
         mileageRate: {
             key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
             selector: DistanceRequestUtils.getDefaultMileageRate,
         },
         policy: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${'062D53707053B5B9'}`,
         },
         policyTaxRates: {
             key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${policyID}`,

From 7c5fa7f0faf8c393b79db9d8544e2e321d0e989b Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Mon, 19 Feb 2024 14:50:59 +0700
Subject: [PATCH 06/12] fix remove hardcode

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js     | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index e93f4bdf8783..0f968780073a 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -947,17 +947,17 @@ export default compose(
             key: ONYXKEYS.SESSION,
         },
         policyCategories: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${'062D53707053B5B9'}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyID}`,
         },
         policyTags: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${'062D53707053B5B9'}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAGS}${policyID}`,
         },
         mileageRate: {
             key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
             selector: DistanceRequestUtils.getDefaultMileageRate,
         },
         policy: {
-            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${'062D53707053B5B9'}`,
+            key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
         },
         policyTaxRates: {
             key: ({policyID}) => `${ONYXKEYS.COLLECTION.POLICY_TAX_RATE}${policyID}`,

From 7729a29ec0bf3d184a3ae56c5e97945d95e9b386 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Mon, 19 Feb 2024 14:51:51 +0700
Subject: [PATCH 07/12] fix remove console log

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js        | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index 0f968780073a..8131bc5a6710 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -560,20 +560,17 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
                 const decimals = CurrencyUtils.getCurrencyDecimals(iouCurrencyCode);
                 if (isDistanceRequest && !isDistanceRequestWithPendingRoute && !MoneyRequestUtils.validateAmount(String(iouAmount), decimals)) {
                     setFormError('common.error.invalidAmount');
-                    console.log('333333333333333333 step 2', {selectedParticipants});
                     return;
                 }
 
                 if (isEditingSplitBill && TransactionUtils.areRequiredFieldsEmpty(transaction)) {
                     setDidConfirmSplit(true);
                     setFormError('iou.error.genericSmartscanFailureMessage');
-                    console.log('333333333333333333 step 3', {selectedParticipants});
                     return;
                 }
 
                 playSound(SOUNDS.DONE);
                 setDidConfirm(true);
-                console.log('111111111111111111111111');
                 onConfirm(selectedParticipants);
             }
         },

From b7f38fc66b95955f21c47015fb27974d5c47b5fc Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Thu, 22 Feb 2024 14:17:08 +0700
Subject: [PATCH 08/12] fix required field

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js      | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index 8131bc5a6710..29cfb34583eb 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -493,9 +493,10 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
     // Auto select the tag if there is only one enabled tag and it is required
     useEffect(() => {
         let updatedTagsString = '';
+        const isMultipleLevelsTags = policyTagLists && policyTagLists.length > 1;
         policyTagLists.forEach((tagList, index) => {
             const enabledTags = _.filter(tagList.tags, (tag) => tag.enabled);
-            if (enabledTags.length !== 1 || !tagList.required || TransactionUtils.getTag(transaction, index)) {
+            if (enabledTags.length !== 1 || isMultipleLevelsTags ? !tagList.required : !isTagRequired || TransactionUtils.getTag(transaction, index)) {
                 return;
             }
             updatedTagsString = IOUUtils.insertTagIntoReportTagsString(updatedTagsString, enabledTags[0].name, index);
@@ -503,7 +504,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         if (updatedTagsString !== TransactionUtils.getTag(transaction) && updatedTagsString) {
             IOU.setMoneyRequestTag(transaction.transactionID, updatedTagsString);
         }
-    }, [policyTagLists, transaction]);
+    }, [policyTagLists, transaction, policyTags, isTagRequired]);
 
     /**
      * @param {Object} option

From 3085c9b6f0f71c327d3cb87d20d9d19a7dd66d47 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Tue, 27 Feb 2024 18:01:55 +0700
Subject: [PATCH 09/12] fix issue when updating tag in OD

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js   | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index 42a7618e3e13..67f994e61f89 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -487,19 +487,19 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         if (iouCategory || !shouldShowCategories || enabledCategories.length !== 1 || !isCategoryRequired) {
             return;
         }
-        IOU.setMoneyRequestCategory_temporaryForRefactor(transaction.transactionID, enabledCategories[0].name);
+        IOU.setMoneyRequestCategory(transaction.transactionID, enabledCategories[0].name);
     }, [iouCategory, shouldShowCategories, policyCategories, transaction, isCategoryRequired]);
 
     // Auto select the tag if there is only one enabled tag and it is required
     useEffect(() => {
-        let updatedTagsString = '';
+        let updatedTagsString = TransactionUtils.getTag(transaction);
         const isMultipleLevelsTags = policyTagLists && policyTagLists.length > 1;
         policyTagLists.forEach((tagList, index) => {
             const enabledTags = _.filter(tagList.tags, (tag) => tag.enabled);
-            if (enabledTags.length !== 1 || isMultipleLevelsTags ? !tagList.required : !isTagRequired || TransactionUtils.getTag(transaction, index)) {
+            if (enabledTags.length !== 1 || (isMultipleLevelsTags ? !tagList.required : !isTagRequired) || TransactionUtils.getTag(transaction, index)) {
                 return;
             }
-            updatedTagsString = IOUUtils.insertTagIntoReportTagsString(updatedTagsString, enabledTags[0].name, index);
+            updatedTagsString = IOUUtils.insertTagIntoTransactionTagsString(updatedTagsString, enabledTags[0] ? enabledTags[0].name : '', index);
         });
         if (updatedTagsString !== TransactionUtils.getTag(transaction) && updatedTagsString) {
             IOU.setMoneyRequestTag(transaction.transactionID, updatedTagsString);

From 2be9fa8c574e43eeb206a632f7978445b38c545f Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Mon, 4 Mar 2024 01:55:12 +0700
Subject: [PATCH 10/12] fix use required filed in both single tag and multiple
 tags

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js       | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index c41069f7b979..a37a5fdb0efa 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -1,5 +1,6 @@
 import {useIsFocused} from '@react-navigation/native';
 import {format} from 'date-fns';
+import {isUndefined} from 'lodash';
 import lodashGet from 'lodash/get';
 import PropTypes from 'prop-types';
 import React, {Fragment, useCallback, useEffect, useMemo, useReducer, useRef, useState} from 'react';
@@ -493,10 +494,9 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
     // Auto select the tag if there is only one enabled tag and it is required
     useEffect(() => {
         let updatedTagsString = TransactionUtils.getTag(transaction);
-        const isMultipleLevelsTags = policyTagLists && policyTagLists.length > 1;
         policyTagLists.forEach((tagList, index) => {
             const enabledTags = _.filter(tagList.tags, (tag) => tag.enabled);
-            if (enabledTags.length !== 1 || (isMultipleLevelsTags ? !tagList.required : !isTagRequired) || TransactionUtils.getTag(transaction, index)) {
+            if (isUndefined(tagList.required) || enabledTags.length !== 1 || !tagList.required || TransactionUtils.getTag(transaction, index)) {
                 return;
             }
             updatedTagsString = IOUUtils.insertTagIntoTransactionTagsString(updatedTagsString, enabledTags[0] ? enabledTags[0].name : '', index);

From 8e43ae299f0b75ae7a2b310118e3b04ae1f1fe8d Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Tue, 5 Mar 2024 09:31:14 +0700
Subject: [PATCH 11/12] fix create isTagListRequired

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js      | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index a37a5fdb0efa..ea38d13cbbb7 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -496,7 +496,8 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         let updatedTagsString = TransactionUtils.getTag(transaction);
         policyTagLists.forEach((tagList, index) => {
             const enabledTags = _.filter(tagList.tags, (tag) => tag.enabled);
-            if (isUndefined(tagList.required) || enabledTags.length !== 1 || !tagList.required || TransactionUtils.getTag(transaction, index)) {
+            const isTagListRequired = isUndefined(tagList.required) ? false : tagList.required && canUseViolations;
+            if (!isTagListRequired || enabledTags.length !== 1 || TransactionUtils.getTag(transaction, index)) {
                 return;
             }
             updatedTagsString = IOUUtils.insertTagIntoTransactionTagsString(updatedTagsString, enabledTags[0] ? enabledTags[0].name : '', index);
@@ -504,7 +505,7 @@ function MoneyTemporaryForRefactorRequestConfirmationList({
         if (updatedTagsString !== TransactionUtils.getTag(transaction) && updatedTagsString) {
             IOU.setMoneyRequestTag(transaction.transactionID, updatedTagsString);
         }
-    }, [policyTagLists, transaction, policyTags, isTagRequired]);
+    }, [policyTagLists, transaction, policyTags, isTagRequired, canUseViolations]);
 
     /**
      * @param {Object} option

From 0854392809bc2b2b97e4f8d2996623cb1e0d4091 Mon Sep 17 00:00:00 2001
From: dukenv0307 <dukenv0307@gmail.com>
Date: Tue, 5 Mar 2024 19:03:42 +0700
Subject: [PATCH 12/12] fix lint after merge main

---
 .../MoneyTemporaryForRefactorRequestConfirmationList.js         | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
index 20497269b3cc..ef78b24feb8d 100755
--- a/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
+++ b/src/components/MoneyTemporaryForRefactorRequestConfirmationList.js
@@ -1,7 +1,7 @@
 import {useIsFocused} from '@react-navigation/native';
 import {format} from 'date-fns';
-import {isUndefined} from 'lodash';
 import Str from 'expensify-common/lib/str';
+import {isUndefined} from 'lodash';
 import lodashGet from 'lodash/get';
 import PropTypes from 'prop-types';
 import React, {useCallback, useEffect, useMemo, useReducer, useRef, useState} from 'react';
