challenge-vtex-io-Patrick-R.../react/components/Pixdiscount/pix-discount.tsx

30 lines
642 B
TypeScript
Raw Normal View History

2023-01-29 16:14:48 +00:00
import React from "react";
import { useProduct } from "vtex.product-context";
export function PixDiscount() {
const productContext = useProduct();
const price =
productContext?.selectedItem?.sellers[0]?.commertialOffer?.Price;
console.log(productContext);
function discount() {
if (price) {
const discountedPrice = price - price * 0.1;
return discountedPrice.toLocaleString("pt-BR", {
style: "currency",
currency: "BRL",
});
} else {
return "...";
}
}
return (
<div>
<img src="" alt="" />
{discount()}
<span>10% de desconto</span>
</div>
);
}