From 2d0909a6e7a3dd8c7017f28fc9ae4e62c52e21ab Mon Sep 17 00:00:00 2001 From: c3024 Date: Sat, 29 Jun 2024 11:08:31 +0530 Subject: [PATCH 1/2] get from,to from txn based on accountIDs in report --- src/components/SelectionList/Search/ReportListItem.tsx | 7 +++++-- src/types/onyx/SearchResults.ts | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index f9e8e1951d9a..defe5f6ba3f3 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -86,8 +86,11 @@ function ReportListItem({ return null; } - const participantFrom = reportItem.transactions[0].from; - const participantTo = reportItem.transactions[0].to; + // We get the from and to details from the first transaction. The first transaction's from and to need not be the same + // as the report's accountID and managerID. + + const participantFrom = reportItem.transactions[0].from?.accountID === reportItem?.accountID ? reportItem.transactions[0].from : reportItem.transactions[0].to; + const participantTo = reportItem.transactions[0].to?.accountID === reportItem?.managerID ? reportItem.transactions[0].to : reportItem.transactions[0].from; // These values should come as part of the item via SearchUtils.getSections() but ReportListItem is not yet 100% handled // This will be simplified in future once sorting of ReportListItem is done diff --git a/src/types/onyx/SearchResults.ts b/src/types/onyx/SearchResults.ts index 3932752f4325..31e9c2664ae4 100644 --- a/src/types/onyx/SearchResults.ts +++ b/src/types/onyx/SearchResults.ts @@ -112,6 +112,12 @@ type SearchReport = { /** The action that can be performed for the report */ action?: string; + + /** The net report sender ID */ + accountID?: number; + + /** The net report recipient ID */ + managerID?: number; }; /** Model of transaction search result */ From 68c6031e08252d6cef0a395559f63227431f9aeb Mon Sep 17 00:00:00 2001 From: c3024 Date: Wed, 3 Jul 2024 12:03:58 +0530 Subject: [PATCH 2/2] add `from` and `to` to `reportIDToTransaction` --- src/components/SelectionList/Search/ReportListItem.tsx | 7 ++----- src/components/SelectionList/types.ts | 6 ++++++ src/libs/SearchUtils.ts | 4 +++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/SelectionList/Search/ReportListItem.tsx b/src/components/SelectionList/Search/ReportListItem.tsx index defe5f6ba3f3..ff2976cbc7ef 100644 --- a/src/components/SelectionList/Search/ReportListItem.tsx +++ b/src/components/SelectionList/Search/ReportListItem.tsx @@ -86,11 +86,8 @@ function ReportListItem({ return null; } - // We get the from and to details from the first transaction. The first transaction's from and to need not be the same - // as the report's accountID and managerID. - - const participantFrom = reportItem.transactions[0].from?.accountID === reportItem?.accountID ? reportItem.transactions[0].from : reportItem.transactions[0].to; - const participantTo = reportItem.transactions[0].to?.accountID === reportItem?.managerID ? reportItem.transactions[0].to : reportItem.transactions[0].from; + const participantFrom = reportItem.from; + const participantTo = reportItem.to; // These values should come as part of the item via SearchUtils.getSections() but ReportListItem is not yet 100% handled // This will be simplified in future once sorting of ReportListItem is done diff --git a/src/components/SelectionList/types.ts b/src/components/SelectionList/types.ts index fc369adf5169..6f9a582d4f7e 100644 --- a/src/components/SelectionList/types.ts +++ b/src/components/SelectionList/types.ts @@ -176,6 +176,12 @@ type TransactionListItemType = ListItem & type ReportListItemType = ListItem & SearchReport & { + /** The personal details of the user requesting money */ + from: SearchAccountDetails; + + /** The personal details of the user paying the request */ + to: SearchAccountDetails; + transactions: TransactionListItemType[]; }; diff --git a/src/libs/SearchUtils.ts b/src/libs/SearchUtils.ts index 460a686766a7..646289bb7bd6 100644 --- a/src/libs/SearchUtils.ts +++ b/src/libs/SearchUtils.ts @@ -161,6 +161,8 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx reportIDToTransactions[reportKey] = { ...value, + from: data.personalDetailsList?.[value.accountID], + to: data.personalDetailsList?.[value.managerID], transactions, }; } else if (key.startsWith(ONYXKEYS.COLLECTION.TRANSACTION)) { @@ -194,7 +196,7 @@ function getReportSections(data: OnyxTypes.SearchResults['data'], metadata: Onyx if (reportIDToTransactions[reportKey]?.transactions) { reportIDToTransactions[reportKey].transactions.push(transaction); } else { - reportIDToTransactions[reportKey] = {transactions: [transaction]}; + reportIDToTransactions[reportKey].transactions = [transaction]; } } }