-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #55264 from software-mansion-labs/fix/get-trip-tra…
…nsactions Remove the getTripTransactions method
- Loading branch information
Showing
6 changed files
with
64 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import {useOnyx} from 'react-native-onyx'; | ||
import ONYXKEYS from '@src/ONYXKEYS'; | ||
import type {Transaction} from '@src/types/onyx'; | ||
|
||
/** | ||
* Hook to fetch transactions associated with a specific `tripRoom` report. | ||
* | ||
* Since trip rooms and their transactions lack a direct connection, this hook | ||
* fetches all child reports and transactions from Onyx and filters them to derive | ||
* relevant transactions for the given trip room. | ||
* | ||
* @param reportID - The trip room's reportID. | ||
* @returns Transactions linked to the specified trip room. | ||
*/ | ||
function useTripTransactions(reportID: string | undefined): Transaction[] { | ||
const [tripTransactionReportIDs = []] = useOnyx(ONYXKEYS.COLLECTION.REPORT, { | ||
selector: (reports) => | ||
Object.values(reports ?? {}) | ||
.filter((report) => report && report.chatReportID === reportID) | ||
.map((report) => report?.reportID), | ||
}); | ||
const [tripTransactions = []] = useOnyx(ONYXKEYS.COLLECTION.TRANSACTION, { | ||
selector: (transactions) => { | ||
if (!tripTransactionReportIDs.length) { | ||
return []; | ||
} | ||
|
||
return Object.values(transactions ?? {}).filter((transaction): transaction is Transaction => !!transaction && tripTransactionReportIDs.includes(transaction.reportID)); | ||
}, | ||
}); | ||
|
||
return tripTransactions; | ||
} | ||
|
||
export default useTripTransactions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters