challenge-vtex-io-rafael-sa.../react/components/PixPrice/PixPrice.tsx

42 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

import React, { useEffect } from "react";
2023-01-27 20:19:50 +00:00
import { useProduct } from "vtex.product-context";
import styles from "./styles.module.css";
const PixPrice = () => {
useEffect(() => {
2023-01-30 19:05:21 +00:00
const inputCep = document.querySelector(".vtex-address-form-4-x-input");
2023-01-29 18:04:57 +00:00
2023-01-30 19:05:21 +00:00
inputCep?.setAttribute("placeholder", "Digite seu CEP");
});
2023-01-27 20:19:50 +00:00
const productContextValue = useProduct();
const productPrice =
productContextValue?.product?.priceRange?.sellingPrice?.lowPrice;
const descount = (Number(productPrice) * 10) / 100;
const total = Number(productPrice) - Number(descount);
2023-01-27 20:19:50 +00:00
return (
<div className={styles["pixPrice-container"]}>
<div className={styles["pixPrice-content"]}>
<div className={styles["pixPrice-img"]}>
<img
src="https://agenciamagma.vtexassets.com/arquivos/pixRafaelSampaio.png"
alt=""
/>
</div>
<div className={styles["pixPrice-descount"]}>
<p className={styles["pixPrice-value"]}>
R$ {total.toFixed(2).replace(".", ",")}
</p>
2023-01-27 20:19:50 +00:00
<p className={styles["pixPrice-text"]}>10 % de desconto</p>
</div>
</div>
</div>
);
};
export default PixPrice;