51 lines
1.3 KiB
JavaScript
51 lines
1.3 KiB
JavaScript
import DoctorsPage from "@/components/doctors";
|
|
import Layout from "@/components/layout/StLayout";
|
|
import { getStateInfo } from "@/lib/getStateInfo";
|
|
import axios from "axios";
|
|
|
|
// Data
|
|
import states from "@/data/state.json";
|
|
import cities from "@/data/city.json";
|
|
|
|
async function Doctors({ searchParams }) {
|
|
const { matchedCity, matchedState } = getStateInfo();
|
|
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
|
|
|
let doctors = null;
|
|
try {
|
|
const params = {};
|
|
const state = searchParams.state;
|
|
const city = searchParams.city;
|
|
console.log(state);
|
|
console.log(city);
|
|
|
|
if (matchedCity)
|
|
params.city = city
|
|
? cities.find((item) => item.name === city)?.id
|
|
: matchedCity?.id || null;
|
|
if (matchedState)
|
|
params.state = state
|
|
? states.find((item) => item.name === state)?.id
|
|
: matchedState?.id || null;
|
|
if (searchParams.search) params.name = searchParams.search;
|
|
|
|
const response = await axios.get(`${API_URL}/api/v1/doctors`, {
|
|
params,
|
|
});
|
|
doctors = response.data.data;
|
|
} catch (error) {}
|
|
|
|
return (
|
|
<Layout>
|
|
<DoctorsPage
|
|
list={doctors}
|
|
params={searchParams}
|
|
matchedCity={matchedCity}
|
|
matchedState={matchedState}
|
|
/>
|
|
</Layout>
|
|
);
|
|
}
|
|
|
|
export default Doctors;
|