challenge-vtex-io-gabriel-l.../react/components/PixComponents/index.tsx

36 lines
927 B
TypeScript
Raw Normal View History

2023-02-10 15:35:03 +00:00
import React, { useEffect, useState } from "react";
import { useProduct } from "vtex.product-context";
import PixImage from "./PixImage";
import Style from "./styles.css";
2023-02-10 20:48:04 +00:00
import "./globalStyles.css";
2023-02-10 15:35:03 +00:00
const PixComponents = () => {
const [pixValue, setPixValue] = useState(0);
const productInfo = useProduct();
const productLowPrice =
productInfo?.product?.priceRange.sellingPrice.lowPrice;
useEffect(() => {
if (productLowPrice) {
setPixValue(productLowPrice * 0.9);
}
}, []);
return (
<div>
<div className={Style.pixDiv}>
<div className={Style.pixImgDiv}>
<PixImage />
</div>
<div>
<div className={Style.priceNormal}>
R$ {pixValue.toFixed(2).replace(".", ",")}
</div>
<span className={Style.priceDiscount}>10 % de desconto</span>
</div>
</div>
</div>
);
};
export default PixComponents;