feat(specialties): show per-city doctor count on /specialties
Fetch active specialties with number_of_doctors from GET /api/v1/specialties/doctor-counts (scoped to the current city via matchedCity.id) instead of the static specialties.json, so each specialty card shows the real doctor count. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,30 @@
|
||||
"use client";
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import List from "./list";
|
||||
import SmSearch from "../searchHead/smSearch";
|
||||
import HeadPageList from "@/app/component/head";
|
||||
import specialtiesData from "@/data/specialties.json";
|
||||
import { searchOnList } from "@/helper";
|
||||
import { request } from "@/services/response";
|
||||
|
||||
function SpecialtiesPage() {
|
||||
const [filteredSpecialties, setFilteredSpecialties] =
|
||||
useState(specialtiesData);
|
||||
function SpecialtiesPage({ cityId }) {
|
||||
const [all, setAll] = useState(specialtiesData);
|
||||
const [filtered, setFiltered] = useState(specialtiesData);
|
||||
|
||||
useEffect(() => {
|
||||
request
|
||||
.getSpecialtyDoctorCounts(cityId)
|
||||
.then((res) => {
|
||||
const items = res?.data?.data ?? [];
|
||||
setAll(items);
|
||||
setFiltered(items);
|
||||
})
|
||||
.catch(() => {});
|
||||
}, [cityId]);
|
||||
|
||||
const handleSearch = (value) =>
|
||||
setFilteredSpecialties(searchOnList(specialtiesData, value, "name"));
|
||||
setFiltered(searchOnList(all, value, "name"));
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -21,12 +33,12 @@ function SpecialtiesPage() {
|
||||
detail="تخصص مورد نظرتان را جستجو کرده و یا از لیست زیر انتخاب نمایید:"
|
||||
>
|
||||
<SmSearch
|
||||
data={specialtiesData}
|
||||
data={all}
|
||||
placeholder="جستجوی تخصص"
|
||||
handleSearch={handleSearch}
|
||||
/>
|
||||
</HeadPageList>
|
||||
<List specialties={filteredSpecialties} />
|
||||
<List specialties={filtered} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user