// Generated with util/create-component.js import React, { memo, useEffect, useRef, useState } from "react"; import { getPriceString, isValidSpecValue } from "../../../utils/functions"; import Link from "../../shared/Link"; import Button from "../../UI/Button"; import { Caret } from "../../UI/Icon"; import { ISpareProductListProps } from "./SpareProductList.types"; const SpareProductList = ({ mainTitle, parentCategory, productCategory, contentList, defaultCollapsed = false, Image, NewTabLink, }: ISpareProductListProps) => { const firstSpareProductRef = useRef(null); const [lengthOfContentList, setLengthOfContentList] = useState( contentList.length ); const [isCollapsed, setIsCollapsed] = useState( lengthOfContentList > 1 && defaultCollapsed ); useEffect(() => { setIsCollapsed(defaultCollapsed); }, [defaultCollapsed]); useEffect(() => { setLengthOfContentList(contentList.length); }, [contentList]); return (
*
{mainTitle}
{contentList.map( ( { productTitle, content, modelName, goodsName, brandName, imageUrl = "./static/images/image_in_preparation.png", price, }, index ) => { if (isCollapsed && index >= 1) { return; } if ( parentCategory === "" || price === "" || modelName === "" || brandName === "" ) { return null; } return (
{Image ? ( {`spareProduct_${brandName}_${modelName}_${goodsName}`} ) : ( {`spareProduct_${brandName}_${modelName}_${goodsName}`} )}

{isValidSpecValue(brandName) && brandName}

{isValidSpecValue(goodsName) && goodsName}{" "} {isValidSpecValue(modelName) && modelName}

{isValidSpecValue(price) && getPriceString(price)}

{productTitle}

); } )}
{isCollapsed && ( )}
); }; export default memo(SpareProductList);