diff --git a/CHANGELOG.md b/CHANGELOG.md index 496279d8..21629b55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +## [2.18.1] - 2024-12-27 + +### Fixed + +- Fix the display of bank invoice information when it isn't the first payment of the first transaction. + ## [2.18.0] - 2024-08-27 ### Added diff --git a/manifest.json b/manifest.json index e26389a5..a1ae3943 100644 --- a/manifest.json +++ b/manifest.json @@ -4,9 +4,7 @@ "version": "2.18.0", "title": "Order Placed", "description": "", - "registries": [ - "smartcheckout" - ], + "registries": ["smartcheckout"], "scripts": { "postreleasy": "vtex publish --public" }, diff --git a/react/Notices.tsx b/react/Notices.tsx index ec9bc987..ab0410bb 100644 --- a/react/Notices.tsx +++ b/react/Notices.tsx @@ -20,9 +20,52 @@ const Notices: FC = () => { return null } + const sortTransactions = (transactions: Transaction[]) => { + return transactions.slice().sort((a, b) => { + const hasBankInvoiceA = a.payments.some((p) => p.group === 'bankInvoice') + const hasBankInvoiceB = b.payments.some((p) => p.group === 'bankInvoice') + + if (hasBankInvoiceA === hasBankInvoiceB) { + return 0 + } + + if (hasBankInvoiceA) { + return -1 + } + + if (hasBankInvoiceB) { + return 1 + } + + } + + const sortPayments = (payments: Payment[]) => { + return payments + .slice() + .sort( + (a, b) => + Number(b.group === 'bankInvoice') - Number(a.group === 'bankInvoice') + ) + } + + const updatedOrders = orders.map((order) => ({ + ...order, + paymentData: { + ...order.paymentData, + transactions: sortTransactions(order.paymentData.transactions).map( + (transaction) => { + return { + ...transaction, + payments: sortPayments(transaction.payments), + } + } + ), + }, + })) + const numOrders = orders.length const isSplitOrder = numOrders > 1 - const bankInvoice = orders + const bankInvoice = updatedOrders .map(getPaymentInfoFromOrder) .find( (paymentInfo) =>