fix(frontend): enhance species badges, smart symptom matching, and sync charity total
This commit is contained in:
1 parent
330d960502
commit
30fb8f3e83
18 files changed
+16952
-14903
No files matched your search
@@ -4,6 +4,7 @@ import { toPersian } from "../lib/utils";
|
||||
import { Product, PetType } from "../lib/data/products";
|
||||
import { usePetStore } from "../lib/store/usePetStore";
|
||||
import { productService } from "../lib/services/productService";
|
||||
import { isSuitableForDog, isSuitableForCat, isSuitableForBoth, isSpeciesCompatible, matchesMedicalSymptom } from "../lib/petCompatibility";
|
||||
import Link from "next/link";
|
||||
import { motion, AnimatePresence } from "motion/react";
|
||||
import { ProductCardSkeleton } from "./Skeleton";
|
||||
@@ -87,13 +88,15 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
setTimeout(() => setIsAdding(false), 400);
|
||||
};
|
||||
|
||||
const forDog = isSuitableForDog(product.suitableFor);
|
||||
const forCat = isSuitableForCat(product.suitableFor);
|
||||
const forBoth = isSuitableForBoth(product.suitableFor) || (forDog && forCat);
|
||||
|
||||
const compatibility = useMemo(() => {
|
||||
if (!activePet) return null;
|
||||
|
||||
const sameSpecies = product.suitableFor === activePet.type || product.suitableFor === "هر دو";
|
||||
const matchedSymptom = (activePet.medicalConditions || []).find(mc =>
|
||||
(product.symptoms || []).some(s => mc.includes(s) || s.includes(mc))
|
||||
);
|
||||
const sameSpecies = isSpeciesCompatible(product.suitableFor, activePet.type);
|
||||
const matchedSymptom = matchesMedicalSymptom(activePet.medicalConditions, product.symptoms, product.benefits);
|
||||
|
||||
if (!sameSpecies) return { type: 'alert', text: `مخصوص ${product.suitableFor}` };
|
||||
if (matchedSymptom) return { type: 'success', text: `توصیه شده برای ${matchedSymptom} ${activePet.name}` };
|
||||
@@ -124,7 +127,24 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
<div className={`absolute top-14 right-4 z-10 text-3xs font-black uppercase tracking-widest px-3 py-1 rounded-full shadow-md flex items-center gap-1 ${compatibility.type === 'alert' ? 'bg-amber-100 text-amber-700' :
|
||||
compatibility.type === 'success' ? 'bg-green-100 text-green-700' : 'bg-medical-gray-100 text-medical-gray-600'
|
||||
}`}>
|
||||
{compatibility.type === 'alert' ? <AlertCircle className="w-2.5 h-2.5" /> : compatibility.type === 'success' ? <Heart className="w-2.5 h-2.5" /> : <Sparkles className="w-2.5 h-2.5" />}
|
||||
{compatibility.type === 'alert' ? (
|
||||
forBoth ? (
|
||||
<span className="flex items-center gap-0.5">
|
||||
<Dog className="w-2.5 h-2.5" />
|
||||
<Cat className="w-2.5 h-2.5" />
|
||||
</span>
|
||||
) : forCat ? (
|
||||
<Cat className="w-2.5 h-2.5" />
|
||||
) : forDog ? (
|
||||
<Dog className="w-2.5 h-2.5" />
|
||||
) : (
|
||||
<AlertCircle className="w-2.5 h-2.5" />
|
||||
)
|
||||
) : compatibility.type === 'success' ? (
|
||||
<Heart className="w-2.5 h-2.5" />
|
||||
) : (
|
||||
<Sparkles className="w-2.5 h-2.5" />
|
||||
)}
|
||||
{compatibility.text}
|
||||
</div>
|
||||
)}
|
||||
@@ -138,13 +158,13 @@ const ArchiveProductCard: React.FC<{ product: Product }> = ({ product }) => {
|
||||
imgClassName="w-full h-full object-contain"
|
||||
/>
|
||||
<div className="absolute bottom-4 left-4 flex gap-2">
|
||||
{(product.suitableFor === "سگ" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
{forDog && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm" title="مناسب برای سگ">
|
||||
<Dog className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
{(product.suitableFor === "گربه" || product.suitableFor === "هر دو") && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm">
|
||||
{forCat && (
|
||||
<div className="w-7 h-7 bg-white rounded-lg flex items-center justify-center text-medical-gray-400 border border-medical-gray-100 shadow-sm" title="مناسب برای گربه">
|
||||
<Cat className="w-4 h-4" />
|
||||
</div>
|
||||
)}
|
||||
|
||||
Reference in new issue
Block a user