move the logic outside return import ProductTag from "@/common/ProductTag"; import SpTag…
- User
move the logic outside return
import ProductTag from "@/common/ProductTag"; import SpTag from "@/common/SpTag"; import { Card, Col, Divider, Row, Skeleton, Typography } from "antd"; import { useTranslation } from "next-i18next"; import Image from "next/image"; import { useEffect, useState } from "react";
const { Paragraph } = Typography; const ImgPlaceholder = "/images/products/placeholder.png";
interface IProductCardComponent { productTitle?: string; productDescription?: string; salePrice?: number; listPrice?: number; productImage?: string; productAlt?: string; topTagText?: string; topTagState?: string; bottomTagText?: string; bottomTagState?: string; hasTopTag?: boolean; hasDiscount?: boolean; hasBottomTag?: boolean; }
const ProductCardComponent = ({ productTitle, productDescription, salePrice = 0, listPrice = 0, productImage = ImgPlaceholder, productAlt, topTagText, topTagState, bottomTagText, bottomTagState, hasTopTag, hasDiscount, hasBottomTag, }: IProductCardComponent) => { const tabbyCost = 300; const discountAmount = (((listPrice - salePrice) / listPrice) * 100).toFixed( 2 );
const { t } = useTranslation();
const [loading, setLoading] = useState(true);
useEffect(() => { setTimeout(() => { setLoading(false); }, 1000); }, []);
return ( <>
{loading ? (
) : ( <> {hasTopTag && (
)}
)}
{productTitle}
{productDescription}
{hasDiscount ? salePrice : listPrice} {t("home.riyal")}
{hasDiscount ? ( <>
{listPrice} {t("home.riyal")}
{t("home.discount")} %{Math.ceil(+discountAmount)}
) : (
{listPrice > tabbyCost ? (listPrice / 4).toFixed(2) +
${t("home.a\_month")}: ""})}
{hasBottomTag && (
)}
); };
export default ProductCardComponent;
- Assistant
- User
move the logic outside return
return ( <>
{loading ? (
) : ( <> {hasTopTag && (
)}
)}
{productTitle}
{productDescription}
{hasDiscount ? salePrice : listPrice} {t("home.riyal")}
{hasDiscount ? ( <>
{listPrice} {t("home.riyal")}
{t("home.discount")} %{Math.ceil(+discountAmount)}
) : (
{listPrice > tabbyCost ? (listPrice / 4).toFixed(2) +
${t("home.a\_month")}: ""})}
{hasBottomTag && (
)}
);
- Assistant