refactor(shop): remove prescription vs OTC filter from shop archive
This commit is contained in:
1 parent
0132cce0cb
commit
5f58ba8258
3 files changed
+615
-645
No files matched your search
@@ -245,7 +245,6 @@ export default function ArchivePage({
|
||||
}) {
|
||||
const router = useRouter();
|
||||
const getText = useSettingsStore(state => state.getText);
|
||||
const [prescriptionFilter, setPrescriptionFilter] = useState<"all" | "prescription" | "otc">("all");
|
||||
const [selectedCategory, setSelectedCategory] = useState(initialCategory);
|
||||
const [selectedPet, setSelectedPet] = useState<PetType | "all">((initialPetType as PetType) || "all");
|
||||
const [activeSymptoms, setActiveSymptoms] = useState<string[]>(initialSymptoms ? initialSymptoms.split(',') : []);
|
||||
@@ -338,14 +337,13 @@ export default function ArchivePage({
|
||||
if (selectedPet && selectedPet !== "all") params.set('petType', selectedPet);
|
||||
if (searchQuery) params.set('search', searchQuery);
|
||||
if (activeSymptoms.length > 0) params.set('symptoms', activeSymptoms.join(','));
|
||||
if (prescriptionFilter !== "all") params.set('rx', prescriptionFilter);
|
||||
|
||||
const queryString = params.toString();
|
||||
const newUrl = `/shop${queryString ? `?${queryString}` : ''}`;
|
||||
if (typeof window !== 'undefined' && window.location.pathname + window.location.search !== newUrl) {
|
||||
router.replace(newUrl, { scroll: false });
|
||||
}
|
||||
}, [selectedCategory, selectedPet, searchQuery, activeSymptoms, prescriptionFilter, router]);
|
||||
}, [selectedCategory, selectedPet, searchQuery, activeSymptoms, router]);
|
||||
|
||||
const fetchProducts = useCallback(async () => {
|
||||
setIsUpdating(true);
|
||||
@@ -365,13 +363,6 @@ 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 => Boolean(p.requiresRx) || p.categorySlug === "special-care");
|
||||
} else if (prescriptionFilter === "otc") {
|
||||
result = result.filter(p => !p.requiresRx && p.categorySlug !== "special-care");
|
||||
}
|
||||
|
||||
setFilteredProducts(result);
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch products:", error);
|
||||
@@ -379,7 +370,7 @@ export default function ArchivePage({
|
||||
} finally {
|
||||
setIsUpdating(false);
|
||||
}
|
||||
}, [selectedCategory, selectedPet, searchQuery, sortBy, sortOrder, activeSymptoms, prescriptionFilter]);
|
||||
}, [selectedCategory, selectedPet, searchQuery, sortBy, sortOrder, activeSymptoms]);
|
||||
|
||||
useEffect(() => {
|
||||
Promise.resolve().then(() => fetchProducts());
|
||||
@@ -459,27 +450,6 @@ 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 "all" | "prescription" | "otc")}
|
||||
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>
|
||||
|
||||
Reference in new issue
Block a user