fix(frontend): add defensive guards against undefined props in FeaturedProducts
Deploy Canina / deploy (push) Successful in 1m49s
Deploy Canina / deploy (push) Successful in 1m49s
This commit is contained in:
1 parent
b91885557e
commit
c68ff27621
12 files changed
+120444
-117804
No files matched your search
@@ -25,11 +25,15 @@ function ProductCard({ product }: { product: Product }) {
|
||||
|
||||
const compatibility = useMemo(() => {
|
||||
if (!activePet) return null;
|
||||
const sameSpecies = product.suitableFor === activePet.type || product.suitableFor === "هر دو";
|
||||
const helpsSymptom = (activePet.medicalConditions || []).some((s) => product.symptoms.includes(s));
|
||||
if (!sameSpecies) return { type: "alert", text: `مخصوص ${product.suitableFor}` };
|
||||
if (helpsSymptom) return { type: "success", text: `توصیه شده برای ${activePet.name}` };
|
||||
return { type: "neutral", text: `مناسب برای ${activePet.name}` };
|
||||
const petType = activePet.type || 'سگ';
|
||||
const sameSpecies = product.suitableFor === petType || product.suitableFor === "هر دو";
|
||||
const productSymptoms = Array.isArray(product.symptoms) ? product.symptoms : [];
|
||||
const petConditions = Array.isArray(activePet.medicalConditions) ? activePet.medicalConditions : [];
|
||||
const helpsSymptom = petConditions.some((s) => productSymptoms.includes(s));
|
||||
|
||||
if (!sameSpecies) return { type: "alert", text: `مخصوص ${product.suitableFor || 'پت'}` };
|
||||
if (helpsSymptom) return { type: "success", text: `توصیه شده برای ${activePet.name || 'پت شما'}` };
|
||||
return { type: "neutral", text: `مناسب برای ${activePet.name || 'پت شما'}` };
|
||||
}, [product, activePet]);
|
||||
|
||||
const isCatalogOnly = getText('CATALOG_ONLY_MODE', 'false') === 'true';
|
||||
@@ -113,13 +117,13 @@ function ProductCard({ product }: { product: Product }) {
|
||||
|
||||
{/* Short description */}
|
||||
<p className="text-xs text-medical-gray-500 leading-relaxed line-clamp-2 flex-1">
|
||||
{product.shortDescription || product.description}
|
||||
{product.shortDescription || product.description || ''}
|
||||
</p>
|
||||
|
||||
{/* Footer: Price + CTA */}
|
||||
<div className="flex items-center justify-between pt-3 border-t border-medical-gray-100">
|
||||
<div className="text-base font-black text-medical-gray-900 font-vazir whitespace-nowrap">
|
||||
{showPrices ? product.price : 'تماس بگیرید'}
|
||||
{showPrices ? (typeof product.price === 'string' || typeof product.price === 'number' ? String(product.price) : 'تماس بگیرید') : 'تماس بگیرید'}
|
||||
</div>
|
||||
{showPreorderBtn ? (
|
||||
<span className="text-[11px] font-black text-amber-600 bg-amber-50 px-3 py-1 rounded-full border border-amber-200">
|
||||
|
||||
Reference in new issue
Block a user