challenge-vtex-io-eleonora-otz/react/components/Pix/Pix.tsx

42 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-01-31 17:21:27 +00:00
import React, { useEffect } from "react";
2023-01-30 15:09:57 +00:00
import { useProduct } from "vtex.product-context";
import styles from "./style.module.css";
const Pix = () => {
2023-01-31 17:21:27 +00:00
useEffect(() => {
const cepInput = document.querySelector(".vtex-address-form-4-x-input");
cepInput?.setAttribute("placeholder", "Digite seu CEP");
});
2023-01-30 15:09:57 +00:00
const productValue = useProduct();
const priceProduct =
productValue?.product?.priceRange?.sellingPrice?.lowPrice;
const descountValue = (Number(priceProduct) * 10) / 100;
const totalValue = Number(priceProduct) - Number(descountValue);
return (
<div className={styles["pix-container"]}>
<div className={styles["pix-content"]}>
<div className={styles["pix-image"]}>
<img
src="https://agenciamagma.vtexassets.com/arquivos/pix-eleonoraotz.png"
alt="10% de desconto no Pix"
/>
</div>
<div className={styles["pix-descount"]}>
<p className={styles["pix-value"]}>
R$ {totalValue.toFixed(2).replace(".", ",")}
</p>
<p className={styles["pix-text"]}>10 % de desconto</p>
</div>
</div>
</div>
);
};
export default Pix;