@@ -10,6 +10,7 @@ import ScrollView from '@components/ScrollView';
1010import useLocalize from '@hooks/useLocalize' ;
1111import useOnyx from '@hooks/useOnyx' ;
1212import usePolicy from '@hooks/usePolicy' ;
13+ import usePrevious from '@hooks/usePrevious' ;
1314import useThemeStyles from '@hooks/useThemeStyles' ;
1415import { removeSplitExpenseField , updateSplitExpenseField } from '@libs/actions/IOU' ;
1516import { convertToDisplayString } from '@libs/CurrencyUtils' ;
@@ -22,8 +23,8 @@ import {getTagLists} from '@libs/PolicyUtils';
2223import { isSplitAction } from '@libs/ReportSecondaryActionUtils' ;
2324import type { TransactionDetails } from '@libs/ReportUtils' ;
2425import { getParsedComment , getReportOrDraftReport , getTransactionDetails } from '@libs/ReportUtils' ;
25- import { hasEnabledTags } from '@libs/TagsOptionsListUtils' ;
26- import { getTag } from '@libs/TransactionUtils' ;
26+ import { getTagVisibility , hasEnabledTags } from '@libs/TagsOptionsListUtils' ;
27+ import { getTag , getTagForDisplay } from '@libs/TransactionUtils' ;
2728import CONST from '@src/CONST' ;
2829import ONYXKEYS from '@src/ONYXKEYS' ;
2930import ROUTES from '@src/ROUTES' ;
@@ -56,13 +57,29 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {
5657 const currentAmount = transactionDetailsAmount >= 0 ? Math . abs ( Number ( splitExpenseDraftTransactionDetails ?. amount ) ) : Number ( splitExpenseDraftTransactionDetails ?. amount ) ;
5758 const currentDescription = getParsedComment ( Parser . htmlToMarkdown ( splitExpenseDraftTransactionDetails ?. comment ?? '' ) ) ;
5859
60+ const shouldShowCategory = ! ! policy ?. areCategoriesEnabled && ! ! policyCategories ;
61+
5962 const transactionTag = getTag ( splitExpenseDraftTransaction ) ;
6063 const policyTagLists = useMemo ( ( ) => getTagLists ( policyTags ) , [ policyTags ] ) ;
6164
62- const shouldShowTag = ! ! policy ?. areTagsEnabled && ! ! ( transactionTag || hasEnabledTags ( policyTagLists ) ) ;
63- const shouldShowCategory = ! ! policy ?. areCategoriesEnabled && ! ! policyCategories ;
6465 const isSplitAvailable = report && transaction && isSplitAction ( report , [ transaction ] , policy ) ;
6566
67+ const isCategoryRequired = ! ! policy ?. requiresCategory ;
68+
69+ const shouldShowTags = ! ! policy ?. areTagsEnabled && ! ! ( transactionTag || hasEnabledTags ( policyTagLists ) ) ;
70+ const tagVisibility = useMemo (
71+ ( ) =>
72+ getTagVisibility ( {
73+ shouldShowTags,
74+ policy,
75+ policyTags,
76+ transaction : splitExpenseDraftTransaction ,
77+ } ) ,
78+ [ shouldShowTags , policy , policyTags , splitExpenseDraftTransaction ] ,
79+ ) ;
80+
81+ const previousTagsVisibility = usePrevious ( tagVisibility . map ( ( v ) => v . shouldShow ) ) ?? [ ] ;
82+
6683 return (
6784 < ScreenWrapper testID = { SplitExpenseEditPage . displayName } >
6885 < FullPageNotFoundView shouldShow = { ! reportID || isEmptyObject ( splitExpenseDraftTransaction ) || ! isSplitAvailable } >
@@ -103,6 +120,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {
103120 description = { translate ( 'common.category' ) }
104121 title = { splitExpenseDraftTransactionDetails ?. category }
105122 numberOfLinesTitle = { 2 }
123+ rightLabel = { isCategoryRequired ? translate ( 'common.required' ) : '' }
106124 onPress = { ( ) => {
107125 Navigation . navigate (
108126 ROUTES . MONEY_REQUEST_STEP_CATEGORY . getRoute (
@@ -118,29 +136,45 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) {
118136 titleStyle = { styles . flex1 }
119137 />
120138 ) }
121- { shouldShowTag && (
122- < MenuItemWithTopDescription
123- shouldShowRightIcon
124- key = { translate ( 'workspace.common.tags' ) }
125- description = { translate ( 'workspace.common.tags' ) }
126- title = { transactionTag }
127- numberOfLinesTitle = { 2 }
128- onPress = { ( ) => {
129- Navigation . navigate (
130- ROUTES . MONEY_REQUEST_STEP_TAG . getRoute (
131- CONST . IOU . ACTION . EDIT ,
132- CONST . IOU . TYPE . SPLIT_EXPENSE ,
133- 0 ,
134- CONST . IOU . OPTIMISTIC_TRANSACTION_ID ,
135- reportID ,
136- Navigation . getActiveRoute ( ) ,
137- ) ,
138- ) ;
139- } }
140- style = { [ styles . moneyRequestMenuItem ] }
141- titleStyle = { styles . flex1 }
142- />
143- ) }
139+ { shouldShowTags &&
140+ policyTagLists . map ( ( { name} , index ) => {
141+ const tagVisibilityItem = tagVisibility . at ( index ) ;
142+ const shouldShow = tagVisibilityItem ?. shouldShow ?? false ;
143+ const isTagRequired = tagVisibilityItem ?. isTagRequired ?? false ;
144+ const prevShouldShow = previousTagsVisibility . at ( index ) ?? false ;
145+
146+ if ( ! shouldShow ) {
147+ return null ;
148+ }
149+
150+ return (
151+ < MenuItemWithTopDescription
152+ shouldShowRightIcon
153+ key = { name }
154+ highlighted = { ! getTagForDisplay ( splitExpenseDraftTransaction , index ) && ! prevShouldShow }
155+ title = { getTagForDisplay ( splitExpenseDraftTransaction , index ) }
156+ description = { name }
157+ shouldShowBasicTitle
158+ shouldShowDescriptionOnTop
159+ numberOfLinesTitle = { 2 }
160+ rightLabel = { isTagRequired ? translate ( 'common.required' ) : '' }
161+ onPress = { ( ) => {
162+ Navigation . navigate (
163+ ROUTES . MONEY_REQUEST_STEP_TAG . getRoute (
164+ CONST . IOU . ACTION . EDIT ,
165+ CONST . IOU . TYPE . SPLIT_EXPENSE ,
166+ index ,
167+ CONST . IOU . OPTIMISTIC_TRANSACTION_ID ,
168+ reportID ,
169+ Navigation . getActiveRoute ( ) ,
170+ ) ,
171+ ) ;
172+ } }
173+ style = { [ styles . moneyRequestMenuItem ] }
174+ titleStyle = { styles . flex1 }
175+ />
176+ ) ;
177+ } ) }
144178 < MenuItemWithTopDescription
145179 shouldShowRightIcon
146180 key = { translate ( 'common.date' ) }
0 commit comments