Skip to content

Commit 2bb6997

Browse files
committed
use snapshots data for amount
1 parent 9c3780a commit 2bb6997

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

src/components/Search/SearchPageHeader.tsx

+18-8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import variables from '@styles/variables';
2424
import CONST from '@src/CONST';
2525
import ONYXKEYS from '@src/ONYXKEYS';
2626
import ROUTES from '@src/ROUTES';
27+
import {SearchReport, SearchTransaction} from '@src/types/onyx/SearchResults';
2728
import type DeepValueOf from '@src/types/utils/DeepValueOf';
2829
import {useSearchContext} from './SearchContext';
2930
import SearchPageHeaderInput from './SearchPageHeaderInput';
@@ -57,7 +58,7 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
5758
const [isDownloadErrorModalVisible, setIsDownloadErrorModalVisible] = useState(false);
5859

5960
const {status, hash} = queryJSON;
60-
61+
const [allSnapshots] = useOnyx(`${ONYXKEYS.COLLECTION.SNAPSHOT}${hash}`);
6162
const selectedTransactionsKeys = Object.keys(selectedTransactions ?? {});
6263

6364
const handleDeleteExpenses = () => {
@@ -136,7 +137,9 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
136137
const transactionIDList = selectedReports.length ? undefined : Object.keys(selectedTransactions);
137138
const items = selectedReports.length ? selectedReports : Object.values(selectedTransactions);
138139

139-
for (const item of items) {
140+
let updatedSelectedTransactions: SearchTransaction[] = [];
141+
let updatedSelectedReports: SearchReport[] = [];
142+
items.forEach((item, index) => {
140143
const policyID = item.policyID;
141144
const lastPolicyPaymentMethod = policyID ? lastPaymentMethods?.[policyID] : null;
142145

@@ -146,23 +149,30 @@ function SearchPageHeader({queryJSON}: SearchPageHeaderProps) {
146149
}
147150

148151
const hasVBBA = PolicyUtils.hasVBBA(policyID);
149-
150152
if (lastPolicyPaymentMethod !== CONST.IOU.PAYMENT_TYPE.ELSEWHERE && !hasVBBA) {
151153
Navigation.navigate(ROUTES.SEARCH_REPORT.getRoute({reportID: item.reportID, backTo: activeRoute}));
152154
return;
153155
}
154-
}
156+
157+
// We need to compute the amount for the report or the transaction, by getting the snapshot data
158+
if (selectedReports.length === 0) {
159+
const itemSnapshotData = (allSnapshots?.data?.[`${ONYXKEYS.COLLECTION.TRANSACTION}${transactionIDList![index]}`] ?? {}) as SearchTransaction;
160+
updatedSelectedTransactions.push(itemSnapshotData);
161+
} else {
162+
const itemSnapshotData = (allSnapshots?.data?.[`${ONYXKEYS.COLLECTION.REPORT}${item.reportID}`] ?? {}) as SearchReport;
163+
updatedSelectedReports.push(itemSnapshotData);
164+
}
165+
});
155166

156167
const paymentData = (
157168
selectedReports.length
158-
? selectedReports.map((report) => ({reportID: report.reportID, amount: report.total, paymentType: lastPaymentMethods[report.policyID]}))
159-
: Object.values(selectedTransactions).map((transaction) => ({
169+
? updatedSelectedReports.map((report) => ({reportID: report.reportID, amount: report.total, paymentType: lastPaymentMethods[report.policyID]}))
170+
: updatedSelectedTransactions.map((transaction) => ({
160171
reportID: transaction.reportID,
161-
amount: transaction.amount,
172+
amount: Math.abs(transaction.amount),
162173
paymentType: lastPaymentMethods[transaction.policyID],
163174
}))
164175
) as PaymentData[];
165-
166176
SearchActions.payMoneyRequestOnSearch(hash, paymentData, transactionIDList);
167177
},
168178
});

0 commit comments

Comments
 (0)