import CustomButton from "@/components/customs/custom-button"; import Pagination from "@/components/customs/custom-pagination"; import Search from "@/components/customs/custom-search"; import Table from "@/components/customs/custom-table"; import DataWrapper from "@/components/customs/DataWrapper"; import { PATH } from "@/constant/config"; import { QUERY_KEY } from "@/constant/config/enum"; import { httpRequest } from "@/services"; import prescriptionServices, { PrescriptionItem, PrescriptionResponse, } from "@/services/prescriptionServices"; import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, } from "@radix-ui/react-tooltip"; import { useQuery } from "@tanstack/react-query"; import { Eye, Pencil, Pill, Trash2 } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; import { usePathname, useRouter, useSearchParams } from "next/navigation"; import React, { useMemo } from "react"; const MainPrescription = () => { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); const _page = searchParams.get("_page"); const _pageSize = searchParams.get("_pageSize"); const _keyword = searchParams.get("_keyword"); const prescriptionQuery = useQuery({ queryKey: [ QUERY_KEY.table_list_patientrescription, _page, _pageSize, _keyword, ], queryFn: async () => { const res = await httpRequest({ showMessageFailed: true, http: prescriptionServices.getPrescription({ Page: Number(_page || 1), PageSize: Number(_pageSize || 10), Search: _keyword || "", SortBy: "id", Desc: true, }), }); return ( res || { items: [], page: 1, pageSize: 10, total: 0, totalPages: 0, } ); }, }); const prescriptionData = useMemo(() => { return prescriptionQuery.data?.items || []; }, [prescriptionQuery.data]); const page = _page ? Number(_page) : 1; const pageSize = _pageSize ? Number(_pageSize) : 10; const updateQuery = (key: string, value?: string | number) => { const params = new URLSearchParams(searchParams.toString()); if (!value) { params.delete(key); } else { params.set(key, String(value)); } const queryString = params.toString(); router.push(queryString ? `${pathname}?${queryString}` : pathname); }; return (
{/* HEADER */}

Đơn thuốc

} href={PATH.CREATE_PRESCRIPTION} > Tạo mới
{/* SEARCH */}
updateQuery("_keyword", value)} placeholder="Tìm theo mã đơn thuốc" />
item.id} data={prescriptionData || []} column={[ // ================= ID / CODE ================= { title: "MÃ ĐƠN THUỐC", render: (item: any) => ( {item.prescriptionCode}

Chi tiết đơn thuốc

), }, // ================= NOTES ================= { title: "GHI CHÚ", render: (item: any) => {item.notes || "-"}, }, // ================= IMAGE ================= { title: "ẢNH ĐƠN THUỐC", render: (item: any) => item.prescriptionImg ? ( ) : ( Không có ảnh ), }, // ================= ITEMS COUNT ================= { title: "SỐ THUỐC", render: (item: any) => {item.items?.length || 0}, }, // ================= ACTION ================= { fixedRight: true, title: "ACTION", render: (item: any) => (
} href={`${PATH.PRESCRIPTION}/${item.id}`} />
), }, ]} /> updateQuery("_page", value)} onSetPageSize={(value) => updateQuery("_pageSize", value)} dependencies={[_pageSize, _keyword]} /> ); }; export default MainPrescription;