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

@@ -33,7 +33,14 @@ async function getData(id) {
export default async function Footer({ lang }){
const data = await getData(lang === 'fa' ? 1 : 2);
const data = await getData(lang === 'fa' ? 1 : 2);
// Add safety checks for data structure
if (!data || typeof data !== 'object') {
console.error('Footer: Invalid data received from API');
return null;
}
return (
<div className="flex flex-col ">
<div className="h-14 bg-zinc-900 flex items-center wrapper w-full">
@@ -50,7 +57,7 @@ export default async function Footer({ lang }){
<div className='flex flex-col pr-'>
<div className='flex'>
<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
<g clip-path="url(#clip0_205_1259)">
<g clipPath="url(#clip0_205_1259)">
<path d="M15.0726 31.9931C14.9787 31.9192 14.9173 31.8778 14.8642 31.8274C14.365 31.3594 13.7893 31.028 13.1376 30.8182C11.8833 30.4136 10.6097 30.0526 9.43958 29.4265C4.54034 26.8046 1.64442 22.7579 0.996899 17.2291C0.474323 12.7655 1.76316 8.78366 4.68876 5.3769C7.09592 2.57349 10.1589 0.82904 13.808 0.233289C18.603 -0.54885 22.9085 0.635058 26.6052 3.79468C29.546 6.30884 31.2856 9.53128 31.8406 13.3667C32.9265 20.8726 28.3628 28.0976 21.1178 30.3743C20.6166 30.5317 20.1175 30.698 19.6184 30.863C19.0192 31.0612 18.496 31.3863 18.0341 31.8143C17.9734 31.8702 17.9106 31.9234 17.8243 32C17.8015 31.913 17.778 31.8647 17.7787 31.8178C17.7987 30.8354 17.7594 29.8462 17.8574 28.8714C18.0079 27.3748 18.6837 26.0984 19.7889 25.0802C20.6829 24.2566 21.5983 23.4517 22.5482 22.6951C27.7159 18.5801 27.2003 10.5115 21.5382 7.09927C17.1146 4.43323 11.4367 5.5985 8.48486 9.77773C5.50058 14.0039 6.46704 19.7978 10.6242 22.9326C11.6797 23.7285 12.6634 24.6425 13.5739 25.6034C14.6205 26.708 15.063 28.11 15.103 29.6274C15.1216 30.326 15.1085 31.0253 15.1071 31.7239C15.1071 31.7977 15.0892 31.8709 15.0733 31.9931H15.0726Z" fill="#FAFAFA"/>
<path className="fill-red-400" d="M16.4351 22.6694C12.4326 22.6604 9.16181 19.4083 9.18321 15.4244C9.20461 11.3004 12.563 8.1339 16.5655 8.1767C20.4611 8.21812 23.7111 11.4965 23.7042 15.4382C23.6966 19.4242 20.4252 22.6791 16.4351 22.6694Z" fill="#FAFAFA"/>
</g>
@@ -60,13 +67,13 @@ export default async function Footer({ lang }){
</clipPath>
</defs>
</svg>
<span className='text-b-1 text-2xl pr-2 pb-2 font-[4]'>{ data.footerHead[0].body }</span>
<span className='text-b-1 text-2xl pr-2 pb-2 font-[4]'>{ data.footerHead?.[0]?.body || '' }</span>
</div>
<p className='text-n-1 font-[5] py-10 text-justify max-w-md'>
{ data.footerDesc[0].body }
{ data.footerDesc?.[0]?.body || '' }
</p>
<div className='flex'>
<span className='text-b-1 font-[4] pl-8'>{ data.footerFollow[0].body }</span>
<span className='text-b-1 font-[4] pl-8'>{ data.footerFollow?.[0]?.body || '' }</span>
<svg className='ml-4' width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.1401 2.96004L7.11012 5.96004C1.04012 7.99004 1.04012 11.3 7.11012 13.32L9.79012 14.21L10.6801 16.89C12.7001 22.96 16.0201 22.96 18.0401 16.89L21.0501 7.87004C22.3901 3.82004 20.1901 1.61004 16.1401 2.96004ZM16.4601 8.34004L12.6601 12.16C12.5101 12.31 12.3201 12.38 12.1301 12.38C11.9401 12.38 11.7501 12.31 11.6001 12.16C11.3101 11.87 11.3101 11.39 11.6001 11.1L15.4001 7.28004C15.6901 6.99004 16.1701 6.99004 16.4601 7.28004C16.7501 7.57004 16.7501 8.05004 16.4601 8.34004Z" fill="#FAFAFA"/>
</svg>
@@ -77,7 +84,7 @@ export default async function Footer({ lang }){
</div>
<div className='flex'>
<div className='flex flex-col pl-20'>
<span className='font-[4] text-lg pb-6 text-b-1'>{ data.footerService[0].body }</span>
<span className='font-[4] text-lg pb-6 text-b-1'>{ data.footerService?.[0]?.body || '' }</span>
<span className='font-[5] text-n-1'> لیست خدمات</span>
<span className='font-[5] text-n-1'> لیست خدمات</span>
<span className='font-[5] text-n-1'> لیست خدمات</span>
@@ -85,7 +92,7 @@ export default async function Footer({ lang }){
<span className='font-[5] text-n-1'> لیست خدمات</span>
</div>
<div className='flex flex-col'>
<span className='font-[4] text-lg pb-6 text-n-1'> { data.footerService[0].body }</span>
<span className='font-[4] text-lg pb-6 text-n-1'> { data.footerService?.[0]?.body || '' }</span>
<span className='font-[5] text-n-1'> لیست محصولات</span>
<span className='font-[5] text-n-1'> لیست محصولات</span>
<span className='font-[5] text-n-1'> لیست محصولات</span>
@@ -94,26 +101,26 @@ export default async function Footer({ lang }){
</div>
</div>
<div className='flex flex-col text-white'>
<span className=' font-[4] text-xl pb-6'>{ data.footerContact[0].body }</span>
<span className=' font-[4] text-xl pb-6'>{ data.footerContact?.[0]?.body || '' }</span>
<div className='flex items-center font-[5]'>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12.75 15.375H5.25C3 15.375 1.5 14.25 1.5 11.625V6.375C1.5 3.75 3 2.625 5.25 2.625H12.75C15 2.625 16.5 3.75 16.5 6.375V11.625C16.5 14.25 15 15.375 12.75 15.375Z" stroke="#FAFAFA" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
<path opacity="0.4" d="M12.75 6.75L10.4025 8.625C9.63 9.24 8.3625 9.24 7.59 8.625L5.25 6.75" stroke="#FAFAFA" stroke-width="1.5" stroke-miterlimit="10" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span className='pr-4'> { data.footerEmail[0].body } </span>
<span className='pr-4'> { data.footerEmail?.[0]?.body || '' } </span>
</div>
<div className='flex items-center py-2 font-[5]'>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M16.4775 13.7475C16.4775 14.0175 16.4175 14.295 16.29 14.565C16.1625 14.835 15.9975 15.09 15.78 15.33C15.4125 15.735 15.0075 16.0275 14.55 16.215C14.1 16.4025 13.6125 16.5 13.0875 16.5C12.3225 16.5 11.505 16.32 10.6425 15.9525C9.78 15.585 8.9175 15.09 8.0625 14.4675C7.2 13.8375 6.3825 13.14 5.6025 12.3675C4.83 11.5875 4.1325 10.77 3.51 9.915C2.895 9.06 2.4 8.205 2.04 7.3575C1.68 6.5025 1.5 5.685 1.5 4.905C1.5 4.395 1.59 3.9075 1.77 3.4575C1.95 3 2.235 2.58 2.6325 2.205C3.1125 1.7325 3.6375 1.5 4.1925 1.5C4.4025 1.5 4.6125 1.545 4.8 1.635C4.995 1.725 5.1675 1.86 5.3025 2.055L7.0425 4.5075C7.1775 4.695 7.275 4.8675 7.3425 5.0325C7.41 5.19 7.4475 5.3475 7.4475 5.49C7.4475 5.67 7.395 5.85 7.29 6.0225C7.1925 6.195 7.05 6.375 6.87 6.555L6.3 7.1475C6.2175 7.23 6.18 7.3275 6.18 7.4475C6.18 7.5075 6.1875 7.56 6.2025 7.62C6.225 7.68 6.2475 7.725 6.2625 7.77C6.3975 8.0175 6.63 8.34 6.96 8.73C7.2975 9.12 7.6575 9.5175 8.0475 9.915C8.4525 10.3125 8.8425 10.68 9.24 11.0175C9.63 11.3475 9.9525 11.5725 10.2075 11.7075C10.245 11.7225 10.29 11.745 10.3425 11.7675C10.4025 11.79 10.4625 11.7975 10.53 11.7975C10.6575 11.7975 10.755 11.7525 10.8375 11.67L11.4075 11.1075C11.595 10.92 11.775 10.7775 11.9475 10.6875C12.12 10.5825 12.2925 10.53 12.48 10.53C12.6225 10.53 12.7725 10.56 12.9375 10.6275C13.1025 10.695 13.275 10.7925 13.4625 10.92L15.945 12.6825C16.14 12.8175 16.275 12.975 16.3575 13.1625C16.4325 13.35 16.4775 13.5375 16.4775 13.7475Z" stroke="#FAFAFA" stroke-width="1.5" stroke-miterlimit="10"/>
</svg>
<span className='pr-4'> { data.footerPhone[0].body } </span>
<span className='pr-4'> { data.footerPhone?.[0]?.body || '' } </span>
</div>
<div className='flex items-center font-[5]'>
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path opacity="0.4" d="M9.00016 10.0726C10.2925 10.0726 11.3402 9.02492 11.3402 7.73258C11.3402 6.44023 10.2925 5.39258 9.00016 5.39258C7.70781 5.39258 6.66016 6.44023 6.66016 7.73258C6.66016 9.02492 7.70781 10.0726 9.00016 10.0726Z" stroke="#FAFAFA" stroke-width="1.5"/>
<path d="M2.71478 6.3675C4.19228 -0.127498 13.8148 -0.119998 15.2848 6.375C16.1473 10.185 13.7773 13.41 11.6998 15.405C10.1923 16.86 7.80728 16.86 6.29228 15.405C4.22228 13.41 1.85228 10.1775 2.71478 6.3675Z" stroke="#FAFAFA" stroke-width="1.5"/>
</svg>
<span className='pr-4'>{ data.footerAddress[0].body }</span>
<span className='pr-4'>{ data.footerAddress?.[0]?.body || '' }</span>
</div>
</div>
@@ -121,4 +128,4 @@ export default async function Footer({ lang }){
</div>
)
}
}