diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 35235ca23893..6bedbce0d38a 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4666,7 +4666,7 @@ function getReportPreviewMessage( * At the moment, we only allow changing one transaction field at a time. */ function getModifiedExpenseOriginalMessage( - oldTransaction: OnyxInputOrEntry, + oldTransaction: OnyxEntry, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, policy: OnyxInputOrEntry, @@ -6662,7 +6662,7 @@ function buildOptimisticActionableTrackExpenseWhisper(iouAction: OptimisticIOURe */ function buildOptimisticModifiedExpenseReportAction( transactionThread: OnyxInputOrEntry, - oldTransaction: OnyxInputOrEntry, + oldTransaction: OnyxEntry, transactionChanges: TransactionChanges, isFromExpenseReport: boolean, policy: OnyxInputOrEntry, diff --git a/src/libs/TransactionUtils/index.ts b/src/libs/TransactionUtils/index.ts index 46345784248a..0a0e8c72d1e1 100644 --- a/src/libs/TransactionUtils/index.ts +++ b/src/libs/TransactionUtils/index.ts @@ -827,7 +827,7 @@ function getTagArrayFromName(tagName: string): string[] { * Return the tag from the transaction. When the tagIndex is passed, return the tag based on the index. * This "tag" field has no "modified" complement. */ -function getTag(transaction: OnyxInputOrEntry, tagIndex?: number): string { +function getTag(transaction: OnyxEntry>, tagIndex?: number): string { if (tagIndex !== undefined) { const tagsArray = getTagArrayFromName(transaction?.tag ?? ''); return tagsArray.at(tagIndex) ?? ''; @@ -836,7 +836,7 @@ function getTag(transaction: OnyxInputOrEntry, tagIndex?: number): return transaction?.tag ?? ''; } -function getTagForDisplay(transaction: OnyxEntry, tagIndex?: number): string { +function getTagForDisplay(transaction: OnyxEntry>, tagIndex?: number): string { return getCleanedTagName(getTag(transaction, tagIndex)); } diff --git a/src/pages/iou/SplitExpenseEditPage.tsx b/src/pages/iou/SplitExpenseEditPage.tsx index 88aeb0c037ee..2831382bbb23 100644 --- a/src/pages/iou/SplitExpenseEditPage.tsx +++ b/src/pages/iou/SplitExpenseEditPage.tsx @@ -16,12 +16,13 @@ import getNonEmptyStringOnyxID from '@libs/getNonEmptyStringOnyxID'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {SplitExpenseParamList} from '@libs/Navigation/types'; +import {hasEnabledOptions} from '@libs/OptionsListUtils'; import Parser from '@libs/Parser'; -import {getPolicy, getTagLists} from '@libs/PolicyUtils'; +import {getPolicy, getTagLists, hasDependentTags} from '@libs/PolicyUtils'; import type {TransactionDetails} from '@libs/ReportUtils'; import {getParsedComment, getReportOrDraftReport, getTransactionDetails} from '@libs/ReportUtils'; import {hasEnabledTags} from '@libs/TagsOptionsListUtils'; -import {getTag} from '@libs/TransactionUtils'; +import {getTag, getTagForDisplay} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -61,6 +62,53 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) { const shouldShowTag = !!policy?.areTagsEnabled && !!(transactionTag || hasEnabledTags(policyTagLists)); const shouldShowCategory = !!policy?.areCategoriesEnabled && !!policyCategories; + const tagList = policyTagLists.map(({name, orderWeight, tags}, index) => { + const tagForDisplay = getTagForDisplay(splitExpenseDraftTransactionDetails, index); + let shouldShow = false; + if (hasDependentTags(policy, policyTags)) { + if (index === 0) { + shouldShow = true; + } else { + const prevTagValue = getTagForDisplay(splitExpenseDraftTransactionDetails, index - 1); + shouldShow = !!prevTagValue; + } + } else { + shouldShow = !!tagForDisplay || hasEnabledOptions(tags); + } + + if (!shouldShow) { + return null; + } + + return ( + { + Navigation.navigate( + ROUTES.MONEY_REQUEST_STEP_TAG.getRoute( + CONST.IOU.ACTION.EDIT, + CONST.IOU.TYPE.SPLIT_EXPENSE, + orderWeight, + CONST.IOU.OPTIMISTIC_TRANSACTION_ID, + reportID, + Navigation.getActiveRoute(), + ), + ); + }} + style={[styles.moneyRequestMenuItem]} + /> + ); + }); + return ( @@ -116,29 +164,7 @@ function SplitExpenseEditPage({route}: SplitExpensePageProps) { titleStyle={styles.flex1} /> )} - {shouldShowTag && ( - { - Navigation.navigate( - ROUTES.MONEY_REQUEST_STEP_TAG.getRoute( - CONST.IOU.ACTION.EDIT, - CONST.IOU.TYPE.SPLIT_EXPENSE, - 0, - CONST.IOU.OPTIMISTIC_TRANSACTION_ID, - reportID, - Navigation.getActiveRoute(), - ), - ); - }} - style={[styles.moneyRequestMenuItem]} - titleStyle={styles.flex1} - /> - )} + {shouldShowTag && tagList}