fix: add safety checks for data structure in Hero, Production, Products components; update SVG attribute for Header component

This commit is contained in:
2026-04-28 21:52:21 +03:30
parent 4c307f7a92
commit a3ed2599ed
8 changed files with 104 additions and 75 deletions

View File

@@ -14,21 +14,28 @@ async function getData(id) {
export default async function Products({ lang }){
const data = await getData(lang === 'fa' ? 1 : 2);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
console.error('Products: Invalid data received from API');
return null;
}
return(
<div className="relative flex flex-col">
<Image alt="" src={productbg} className="absolute top-0 w-full object-cover h-[500px] md:h-96 lg:h-fit"/>
<div className="flex flex-col z-10 text-white font-[5] pt-8 lg:pt-16 w-full items-center ">
<span>{data.productsSuper[0].body}</span>
<span className="font-[4] text-3xl lg:text-4xl pt-4">{data.productsHead[0].body}</span>
<p className="max-w-4xl text-center pt-6 px-8 text-sm sm:text-md lg:pt-12">{data.productsDesc[0].body}</p>
<span>{data.productsSuper?.[0]?.body || ''}</span>
<span className="font-[4] text-3xl lg:text-4xl pt-4">{data.productsHead?.[0]?.body || ''}</span>
<p className="max-w-4xl text-center pt-6 px-8 text-sm sm:text-md lg:pt-12">{data.productsDesc?.[0]?.body || ''}</p>
</div>
<div className="flex justify-center z-10 py-16 overflow-x-scroll">
{
data.productImages.map((image, index) => (
<ProductCard key={index} image={image.body} desc={data.productDescs[index].body} />
))
data.productImages?.map((image, index) => (
<ProductCard key={index} image={image?.body || ''} desc={data.productDescs?.[index]?.body || ''} />
)) || []
}
</div>
</div>
)
}
}