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

@@ -71,6 +71,12 @@ export default async function Hero({lang}){
const data = await getData(lang === 'fa' ? 1 : 2);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
console.error('Hero: Invalid data received from API');
return null;
}
return (
<div className="flex flex-col w-full lg:py-8 items-center overflow-hidden">
<div className="relative flex justify-center pb-60 lg:pb-0">
@@ -79,11 +85,11 @@ export default async function Hero({lang}){
<p className="font-[5] max-w-sm text-justify text-zinc-600">اولین و تنها تولید کننده ی آلیاژهای منیزیم به صورت شمش و بیلت در سال ۱۳۹۶ در استان قم واقع در شهرک صنعتی شکوهیه شروع به فعالیت نمود.</p>
</div>*/}
<h1 className="col-span-2 text-3xl sm:text-4xl md:text-5xl lg:text-7xl font-[1] leading-normal w-full text-center pt-8">
{data.title1[0].body} <br/> {data.title2[0].body}
{data.title1?.[0]?.body || ''} <br/> {data.title2?.[0]?.body || ''}
</h1>
</div>
<div className="relative flex justify-center w-fit mb-[-15px] lg:mx-[290px]">
<MG lang={lang} props={data.mgprops}/>
<MG lang={lang} props={data.mgprops || []}/>
<div className="hidden lg:inline absolute bottom-32 right-[-140px]">
<svg width="234" height="191" viewBox="0 0 234 191" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M13.6311 176.663C13.4447 176.866 13.4588 177.183 13.6625 177.369C13.8663 177.555 14.1825 177.541 14.3689 177.337L13.6311 176.663ZM175 1L175 0.5L174.78 0.5L174.631 0.662518L175 1ZM233 1.5L233.5 1.5L233.5 0.500003L233 0.500003L233 1.5ZM14.3689 177.337L175.369 1.33748L174.631 0.662518L13.6311 176.663L14.3689 177.337ZM175 1.5L233 1.5L233 0.500003L175 0.5L175 1.5Z" fill="black"/>
@@ -93,12 +99,12 @@ export default async function Hero({lang}){
<Image alt="" src={bg} width={700} priority={true} />
<div className="absolute top-[-220px] left-[-100px] lg:top-0 lg:left-[-350px] flex flex-col items-center h-full justify-center pl-32 font-[5]">
<div className="flex flex-col items-center">
<span className="text-2xl lg:text-4xl font-[4] pb-2">{ data.stat1[0].body }</span>
<span className="text-zinc-700">{ data.statlabel1[0].body }</span>
<span className="text-2xl lg:text-4xl font-[4] pb-2">{ data.stat1?.[0]?.body || '' }</span>
<span className="text-zinc-700">{ data.statlabel1?.[0]?.body || '' }</span>
</div>
<div className="flex flex-col items-center pt-8">
<span className="text-2xl lg:text-4xl font-[4] pb-2">{ data.stat2[0].body }</span>
<span className="text-zinc-700">{ data.statlabel2[0].body }</span>
<span className="text-2xl lg:text-4xl font-[4] pb-2">{ data.stat2?.[0]?.body || '' }</span>
<span className="text-zinc-700">{ data.statlabel2?.[0]?.body || '' }</span>
</div>
</div>
</div>
@@ -114,4 +120,4 @@ export default async function Hero({lang}){
</div>
</div>
)
}
}