add support for displaying taxes

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux 2021-08-10 16:04:24 +03:00
parent 2943168803
commit 894f133739
No known key found for this signature in database
GPG Key ID: AF9E9BD6548AD52E
3 changed files with 12 additions and 3 deletions

View File

@ -26,6 +26,12 @@ const CheckoutSidebarView: FC = () => {
currencyCode: data.currency.code, currencyCode: data.currency.code,
} }
) )
const { price: taxes } = usePrice(
data && {
amount: Number(data.taxes),
currencyCode: data.currency.code,
}
)
return ( return (
<SidebarLayout <SidebarLayout
@ -68,7 +74,7 @@ const CheckoutSidebarView: FC = () => {
</li> </li>
<li className="flex justify-between py-1"> <li className="flex justify-between py-1">
<span>Taxes</span> <span>Taxes</span>
<span>Calculated at checkout</span> <span>{data.taxes ? taxes : 'Calculated at checkout'}</span>
</li> </li>
<li className="flex justify-between py-1"> <li className="flex justify-between py-1">
<span>Shipping</span> <span>Shipping</span>

View File

@ -81,6 +81,8 @@ export type Cart = {
totalPrice: number totalPrice: number
// Discounts that have been applied on the cart. // Discounts that have been applied on the cart.
discounts?: Discount[] discounts?: Discount[]
// The total for taxes
taxes?: number
} }
/** /**

View File

@ -203,8 +203,8 @@ export function normalizeProduct(productNode: CatalogItemProduct): Product {
export function normalizeCart(cart: ReactionCart): Cart { export function normalizeCart(cart: ReactionCart): Cart {
return { return {
id: cart._id, id: cart._id,
customerId: '', customerId: cart.account?._id ?? '',
email: '', email: cart.account?.emailRecords[0].address ?? '',
createdAt: cart.createdAt, createdAt: cart.createdAt,
currency: { currency: {
code: cart.checkout?.summary?.total?.currency.code ?? '', code: cart.checkout?.summary?.total?.currency.code ?? '',
@ -218,6 +218,7 @@ export function normalizeCart(cart: ReactionCart): Cart {
subtotalPrice: +(cart.checkout?.summary?.itemTotal?.amount ?? 0), subtotalPrice: +(cart.checkout?.summary?.itemTotal?.amount ?? 0),
totalPrice: cart.checkout?.summary?.total?.amount ?? 0, totalPrice: cart.checkout?.summary?.total?.amount ?? 0,
discounts: [], discounts: [],
taxes: cart.checkout?.summary?.taxTotal?.amount,
} }
} }