Skip to content

Commit e743c03

Browse files
Extract getStatusBadgeBackgroundColor helper to eliminate duplicated logic
Moves the isUnreported + conditional background color logic into a shared helper in ReportUtils, fixing the inconsistency where UserInfoAndActionButtonRow was missing the !isDeleted guard that StatusCell had. Co-authored-by: Jayesh Mangwani <jayeshmangwani@users.noreply.github.com>
1 parent c81b0ab commit e743c03

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

src/components/Search/SearchList/ListItem/StatusCell.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import StatusBadge from '@components/StatusBadge';
44
import useLocalize from '@hooks/useLocalize';
55
import useTheme from '@hooks/useTheme';
66
import useThemeStyles from '@hooks/useThemeStyles';
7-
import {getReportStatusColorStyle, getReportStatusTranslation} from '@libs/ReportUtils';
7+
import {getReportStatusColorStyle, getReportStatusTranslation, getStatusBadgeBackgroundColor} from '@libs/ReportUtils';
88

99
type StatusCellProps = {
1010
/** The stateNum of the report */
@@ -35,8 +35,7 @@ function StatusCell({stateNum, statusNum, isPending, isDeleted, isSelected}: Sta
3535
return null;
3636
}
3737

38-
const isUnreported = (stateNum === undefined || statusNum === undefined) && !isDeleted;
39-
const backgroundColor = isSelected && isUnreported ? theme.buttonHoveredBG : reportStatusColorStyle.backgroundColor;
38+
const backgroundColor = getStatusBadgeBackgroundColor(theme, stateNum, statusNum, isDeleted, isSelected);
4039

4140
return (
4241
<View style={[styles.w100, styles.justifyContentCenter, isPending && styles.offlineFeedbackPending]}>

src/components/Search/SearchList/ListItem/UserInfoAndActionButtonRow.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import StatusBadge from '@components/StatusBadge';
99
import useLocalize from '@hooks/useLocalize';
1010
import useTheme from '@hooks/useTheme';
1111
import useThemeStyles from '@hooks/useThemeStyles';
12-
import {getReportStatusColorStyle, getReportStatusTranslation} from '@libs/ReportUtils';
12+
import {getReportStatusColorStyle, getReportStatusTranslation, getStatusBadgeBackgroundColor} from '@libs/ReportUtils';
1313
import CONST from '@src/CONST';
1414
import type {ExpenseReportListItemType, TransactionListItemType, TransactionReportGroupListItemType} from './types';
1515
import UserInfoCellsWithArrow from './UserInfoCellsWithArrow';
@@ -34,8 +34,7 @@ function UserInfoAndActionButtonRow({
3434
const {translate} = useLocalize();
3535
const statusText = getReportStatusTranslation({stateNum, statusNum, translate});
3636
const reportStatusColorStyle = getReportStatusColorStyle(theme, stateNum, statusNum);
37-
const isUnreported = stateNum === undefined || statusNum === undefined;
38-
const badgeBackgroundColor = isSelected && isUnreported ? theme.buttonHoveredBG : reportStatusColorStyle?.backgroundColor;
37+
const badgeBackgroundColor = getStatusBadgeBackgroundColor(theme, stateNum, statusNum, undefined, isSelected);
3938
const participantFromDisplayName = item.formattedFrom ?? item?.from?.displayName ?? '';
4039
return (
4140
<View style={[styles.pt0, styles.flexRow, styles.alignItemsCenter, shouldShowUserInfo ? styles.justifyContentBetween : styles.justifyContentEnd, styles.gap2, containerStyles]}>

src/libs/ReportUtils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13251,6 +13251,12 @@ function getReportStatusColorStyle(theme: ThemeColors, stateNum?: number, status
1325113251
return undefined;
1325213252
}
1325313253

13254+
function getStatusBadgeBackgroundColor(theme: ThemeColors, stateNum?: number, statusNum?: number, isDeleted?: boolean, isSelected?: boolean): ColorValue | undefined {
13255+
const reportStatusColorStyle = getReportStatusColorStyle(theme, stateNum, statusNum, isDeleted);
13256+
const isUnreported = (stateNum === undefined || statusNum === undefined) && !isDeleted;
13257+
return isSelected && isUnreported ? theme.buttonHoveredBG : reportStatusColorStyle?.backgroundColor;
13258+
}
13259+
1325413260
/**
1325513261
* Checks if a workspace member is leaving a workspace room
1325613262
* This is used to determine if we need to show special handling when a workspace member leaves a room
@@ -13727,6 +13733,7 @@ export {
1372713733
isMoneyRequestReportEligibleForMerge,
1372813734
getReportStatusTranslation,
1372913735
getReportStatusColorStyle,
13736+
getStatusBadgeBackgroundColor,
1373013737
getMovedActionMessage,
1373113738
excludeParticipantsForDisplay,
1373213739
getReceiptUploadErrorReason,

0 commit comments

Comments
 (0)