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

@@ -18,14 +18,20 @@ async function getData(id) {
export default async function About({lang}) {
const data = await getData(lang === 'fa' ? 1 : 2);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
console.error('About: Invalid data received from API');
return null;
}
return(
<div className='grid lg:grid-cols-3 grid-cols-1 grid-rows-3 gap-2 font-[5] my-16 mx-8 lg:mx-28'>
<div className='flex justify-between items-center p-8'>
<div className='flex flex-col w-full'>
<span>{ data.aboutSuper[0].body }</span>
<span className='font-[4] text-3xl lg:text-4xl pt-2'>{ data.aboutHead[0].body }</span>
<span>{ data.aboutSuper?.[0]?.body || '' }</span>
<span className='font-[4] text-3xl lg:text-4xl pt-2'>{ data.aboutHead?.[0]?.body || '' }</span>
</div>
<svg className='' width="128" height="74" viewBox="0 0 128 74" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M80.5657 36.6117C80.5657 46.6722 83.2246 55.7663 87.5075 62.3363C91.7923 68.9091 97.6768 72.9235 104.133 72.9235C110.589 72.9235 116.473 68.9091 120.758 62.3363C125.041 55.7663 127.7 46.6722 127.7 36.6117C127.7 26.5513 125.041 17.4572 120.758 10.8872C116.473 4.31441 110.589 0.3 104.133 0.3C97.6768 0.3 91.7923 4.31441 87.5075 10.8872C83.2246 17.4572 80.5657 26.5513 80.5657 36.6117Z" stroke="url(#paint0_linear_124_2568)" stroke-width="0.6"/>
@@ -53,16 +59,16 @@ export default async function About({lang}) {
</svg>
</div>
<div className='row-span-2 flex flex-col justify-between py-10 px-8 bg-zinc-100 rounded-xl h-full'>
<span className='font-[4] text-xl'>{ data.about1Head[0].body }</span>
<p className='text-zinc-600 py-4'> { data.about1Desc[0].body }
<span className='font-[4] text-xl'>{ data.about1Head?.[0]?.body || '' }</span>
<p className='text-zinc-600 py-4'> { data.about1Desc?.[0]?.body || '' }
</p>
<Image alt="" src={PicAbout} className=''/>
</div>
<Image alt="" src={ data.about1Image[0].body } width={800} height={800} className='row-span-3 h-full w-full object-cover rounded-xl'/>
<Image alt="" src={ data.about1Image?.[0]?.body || '' } width={800} height={800} className='row-span-3 h-full w-full object-cover rounded-xl'/>
<div className='row-span-2 flex flex-col justify-between py-10 px-8 bg-zinc-100 rounded-xl h-full'>
<span className='font-[4] text-xl'>{ data.about2Head[0].body }</span>
<p className='text-zinc-600 py-4'> { data.about2Desc[0].body }
<span className='font-[4] text-xl'>{ data.about2Head?.[0]?.body || '' }</span>
<p className='text-zinc-600 py-4'> { data.about2Desc?.[0]?.body || '' }
</p>
<Link href="#products" className='hidden lg:flex items-center bg-red-700 font-[4] w-fit p-2 '>
<span className='text-md text-zinc-50'> بیشتر بدانید</span>
@@ -73,8 +79,8 @@ export default async function About({lang}) {
</div>
</Link>
</div>
<Image alt="" src={ data.about2Image[0].body } width={800} height={800} className='max-h-48 object-cover rounded-xl w-full h-full'/>
<Image alt="" src={ data.about2Image?.[0]?.body || '' } width={800} height={800} className='max-h-48 object-cover rounded-xl w-full h-full'/>
</div>
)
}
}