refactor: update appointment handling to improve data flow and display, including status management and detail views
This commit is contained in:
@@ -7,7 +7,7 @@ import { request } from "@/services/response";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
function Turns({ user, setIsTurnsDetails, loading }) {
|
||||
const [isDone, setIsDone] = useState(true);
|
||||
const [status, setStatus] = useState(undefined);
|
||||
const [appointments, setAppointments] = useState([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [page, setPage] = useState(1);
|
||||
@@ -31,16 +31,27 @@ function Turns({ user, setIsTurnsDetails, loading }) {
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await request.getMyAppointments(userId, {
|
||||
const params = {
|
||||
page,
|
||||
limit: 10,
|
||||
});
|
||||
};
|
||||
|
||||
if (status) {
|
||||
params.status = status;
|
||||
}
|
||||
|
||||
const response = await request.getMyAppointments(userId, params);
|
||||
|
||||
if (response?.data) {
|
||||
setAppointments(response.data);
|
||||
if (response.page) {
|
||||
setTotalPages(response.page.totalPages);
|
||||
setTotalPages(response.page.totalPages || 1);
|
||||
} else {
|
||||
setTotalPages(1);
|
||||
}
|
||||
} else {
|
||||
setAppointments([]);
|
||||
setTotalPages(1);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error fetching appointments:", error);
|
||||
@@ -50,18 +61,23 @@ function Turns({ user, setIsTurnsDetails, loading }) {
|
||||
};
|
||||
|
||||
fetchAppointments();
|
||||
}, [page]);
|
||||
}, [page, status]);
|
||||
|
||||
const handlePageChange = (event, value) => {
|
||||
setPage(value);
|
||||
};
|
||||
|
||||
const handleStatusChange = (newStatus) => {
|
||||
setStatus(newStatus);
|
||||
setPage(1); // Reset to first page when status changes
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="opacity-page">
|
||||
<p className="text-[#3B3B3B] hidden md:flex text-[16px] font-bold">
|
||||
تاریخچه نوبت ها
|
||||
</p>
|
||||
<Head isDone={isDone} setIsDone={setIsDone} />
|
||||
<Head status={status} setStatus={handleStatusChange} />
|
||||
<List
|
||||
loading={isLoading}
|
||||
setIsTurnsDetails={setIsTurnsDetails}
|
||||
|
||||
Reference in New Issue
Block a user