challenge-vtex-io-vitor-soares/react/components/Pix-bloco/Pix.tsx

40 lines
1.1 KiB
TypeScript

import React, { useEffect } from "react";
import { useProduct } from "vtex.product-context";
import styles from "./style.module.css";
const Pix = () => {
useEffect(() => {
const cepInput = document.querySelector(".vtex-address-form-4-x-input");
cepInput?.setAttribute("placeholder", "Digite seu CEP");
console.log(cepInput);
});
const productContextValue = useProduct();
const productPrice = productContextValue?.product?.priceRange?.sellingPrice?.lowPrice;
const discountValue = (Number(productPrice) * 10) / 100;
const totalValue = Number(productPrice) - Number(discountValue);
return (
<div className={styles["wrapper"]}>
<div className={styles["container-flex"]}>
<div className={styles["image"]}>
<img src="https://agenciamagma.vtexassets.com/arquivos/pix-logo-vitor-soares.png" alt="desconto" />
</div>
<div className={styles["discount"]}>
<p className={styles["value"]}>R${totalValue.toFixed(2)}</p>
<p className={styles["text"]}>10 % de desconto</p>
</div>
</div>
</div>
);
};
export default Pix;