Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: display of bank invoice information #199

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@
"version": "2.18.0",
"title": "Order Placed",
"description": "",
"registries": [
"smartcheckout"
],
"registries": ["smartcheckout"],
"scripts": {
"postreleasy": "vtex publish --public"
},
Expand Down
45 changes: 44 additions & 1 deletion react/Notices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (hasBankInvoiceA) {
return -1
}

if (hasBankInvoiceB) {
return 1
}
}

return 0
})
iago1501 marked this conversation as resolved.
Show resolved Hide resolved
}

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) =>
Expand Down
Loading