Skip to content

Commit 5b572d4

Browse files
committed
fix: expense - user avatar is shown in report in which expense is not added
1 parent 89dd3c5 commit 5b572d4

2 files changed

Lines changed: 61 additions & 1 deletion

File tree

src/libs/SearchUIUtils.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1160,7 +1160,7 @@ function getReportSections(
11601160
action: getAction(data, allViolations, key, currentSearch, actions),
11611161
groupedBy: CONST.SEARCH.GROUP_BY.REPORTS,
11621162
keyForList: reportItem.reportID,
1163-
from: data.personalDetailsList?.[reportItem.accountID ?? CONST.DEFAULT_NUMBER_ID],
1163+
from: transactions.length > 0 ? data.personalDetailsList[data?.[reportKey as ReportKey]?.accountID ?? CONST.DEFAULT_NUMBER_ID] : emptyPersonalDetails,
11641164
to: !shouldShowBlankTo && reportItem.managerID ? data.personalDetailsList?.[reportItem.managerID] : emptyPersonalDetails,
11651165
transactions,
11661166
...(reportPendingAction ? {pendingAction: reportPendingAction} : {}),
@@ -1205,8 +1205,10 @@ function getReportSections(
12051205
};
12061206
if (reportIDToTransactions[reportKey]?.transactions) {
12071207
reportIDToTransactions[reportKey].transactions.push(transaction);
1208+
reportIDToTransactions[reportKey].from = data.personalDetailsList[data?.[reportKey as ReportKey]?.accountID ?? CONST.DEFAULT_NUMBER_ID];
12081209
} else if (reportIDToTransactions[reportKey]) {
12091210
reportIDToTransactions[reportKey].transactions = [transaction];
1211+
reportIDToTransactions[reportKey].from = data.personalDetailsList[data?.[reportKey as ReportKey]?.accountID ?? CONST.DEFAULT_NUMBER_ID];
12101212
}
12111213
}
12121214
}

tests/unit/Search/SearchUIUtilsTest.ts

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const reportID = '123456789';
2727
const reportID2 = '11111';
2828
const reportID3 = '99999';
2929
const reportID4 = '6155022250251839';
30+
const reportID5 = '22222';
3031
const transactionID = '1';
3132
const transactionID2 = '2';
3233
const transactionID3 = '3';
@@ -231,6 +232,27 @@ const searchResults: OnyxTypes.SearchResults = {
231232
created: '2025-03-05 16:34:27',
232233
type: 'chat',
233234
},
235+
[`report_${reportID5}`]: {
236+
accountID: adminAccountID,
237+
action: 'view',
238+
chatReportID: '1706144653204915',
239+
created: '2024-12-21 13:05:20',
240+
currency: 'USD',
241+
isOneTransactionReport: true,
242+
isPolicyExpenseChat: false,
243+
isWaitingOnBankAccount: false,
244+
managerID: adminAccountID,
245+
nonReimbursableTotal: 0,
246+
ownerAccountID: adminAccountID,
247+
policyID,
248+
reportID: reportID5,
249+
reportName: 'Expense Report #123',
250+
stateNum: 0,
251+
statusNum: 0,
252+
total: 0,
253+
type: 'expense',
254+
unheldTotal: 0,
255+
},
234256
[`transactions_${transactionID}`]: {
235257
accountID: adminAccountID,
236258
action: 'view',
@@ -953,6 +975,42 @@ const transactionReportGroupListItems = [
953975
},
954976
transactions: [transactionsListItems.at(2), transactionsListItems.at(3)],
955977
},
978+
{
979+
groupedBy: 'reports',
980+
accountID: 18439984,
981+
action: 'view',
982+
chatReportID: '1706144653204915',
983+
created: '2024-12-21 13:05:20',
984+
currency: 'USD',
985+
from: {
986+
accountID: CONST.REPORT.OWNER_ACCOUNT_ID_FAKE,
987+
avatar: '',
988+
displayName: undefined,
989+
login: undefined,
990+
},
991+
isOneTransactionReport: true,
992+
isPolicyExpenseChat: false,
993+
isWaitingOnBankAccount: false,
994+
keyForList: reportID5,
995+
managerID: 18439984,
996+
nonReimbursableTotal: 0,
997+
ownerAccountID: 18439984,
998+
policyID: 'A1B2C3',
999+
reportID: reportID5,
1000+
reportName: 'Expense Report #123',
1001+
stateNum: 0,
1002+
statusNum: 0,
1003+
to: {
1004+
accountID: 0,
1005+
avatar: '',
1006+
displayName: undefined,
1007+
login: undefined,
1008+
},
1009+
total: 0,
1010+
transactions: [],
1011+
type: 'expense',
1012+
unheldTotal: 0,
1013+
},
9561014
] as TransactionReportGroupListItemType[];
9571015

9581016
describe('SearchUIUtils', () => {

0 commit comments

Comments
 (0)