feat: TASK-111 - add prescription and household supplement filters to ArchivePage
This commit is contained in:
1 parent
db3c18a433
commit
72c126b9ca
4 files changed
+49
-5
No files matched your search
@@ -229,6 +229,7 @@ export default function ArchivePage({
|
||||
initialSymptoms?: string
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const [prescriptionFilter, setPrescriptionFilter] = useState<"all" | "prescription" | "otc">("all");
|
||||
const [selectedCategory, setSelectedCategory] = useState(initialCategory);
|
||||
const [selectedPet, setSelectedPet] = useState<PetType | "all">(initialPetType as any);
|
||||
const [activeSymptoms, setActiveSymptoms] = useState<string[]>(initialSymptoms ? initialSymptoms.split(',') : []);
|
||||
@@ -343,6 +344,13 @@ export default function ArchivePage({
|
||||
result = result.filter(p => p.symptoms && p.symptoms.some(s => activeSymptoms.includes(s)));
|
||||
}
|
||||
|
||||
// Filter by prescription requirement (OTC vs Prescription)
|
||||
if (prescriptionFilter === "prescription") {
|
||||
result = result.filter(p => p.requiresRx || p.category === "special-care");
|
||||
} else if (prescriptionFilter === "otc") {
|
||||
result = result.filter(p => !p.requiresRx && p.category !== "special-care");
|
||||
}
|
||||
|
||||
setFilteredProducts(result);
|
||||
setMeta(res.meta);
|
||||
} catch (error) {
|
||||
@@ -355,7 +363,7 @@ export default function ArchivePage({
|
||||
|
||||
useEffect(() => {
|
||||
fetchProducts();
|
||||
}, [selectedCategory, selectedPet, searchQuery, activeSymptoms]);
|
||||
}, [selectedCategory, selectedPet, searchQuery, activeSymptoms, prescriptionFilter]);
|
||||
|
||||
const toggleSymptom = (s: string) => {
|
||||
setActiveSymptoms(prev => prev.includes(s) ? prev.filter(item => item !== s) : [...prev, s]);
|
||||
@@ -418,6 +426,27 @@ export default function ArchivePage({
|
||||
</div>
|
||||
|
||||
<div className="space-y-6">
|
||||
{/* Prescription / Household Filter */}
|
||||
<div>
|
||||
<span className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block mb-3">نوع دسترسی و نسخه</span>
|
||||
<div className="flex flex-col gap-2">
|
||||
{[
|
||||
{ id: "all", label: "همه داروها و مکملها" },
|
||||
{ id: "otc", label: "مکملهای خانگی (بدون نیاز به نسخه)" },
|
||||
{ id: "prescription", label: "داروها و مکملهای تخصصی (با نسخه)" },
|
||||
].map(type => (
|
||||
<button
|
||||
key={type.id}
|
||||
onClick={() => setPrescriptionFilter(type.id as any)}
|
||||
className={`w-full py-2 px-3 rounded-xl text-xs font-bold border transition-all text-right flex items-center justify-between ${prescriptionFilter === type.id ? 'bg-canina-blue border-canina-blue text-white shadow-md' : 'bg-white border-medical-gray-200 text-medical-gray-600 hover:bg-medical-gray-50'}`}
|
||||
>
|
||||
<span>{type.label}</span>
|
||||
{prescriptionFilter === type.id && <Sparkles className="w-3.5 h-3.5 text-amber-300" />}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Pet Type */}
|
||||
<div>
|
||||
<span className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block mb-3">نوع پت</span>
|
||||
|
||||
@@ -50,6 +50,7 @@ export interface Product {
|
||||
symptoms: string[];
|
||||
suitableFor: PetType;
|
||||
specialBadge?: string;
|
||||
requiresRx?: boolean;
|
||||
contraindications?: string[];
|
||||
onSetOfAction?: string;
|
||||
expectedResults?: { icon: string; text: string }[];
|
||||
|
||||
Reference in new issue
Block a user