import { factory_api } from "@/features/pharm/lib/api"; import { type FactoryListDataRes, type PharmType, } from "@/features/pharm/lib/data"; import AddedPharm from "@/features/pharm/ui/AddedPharm"; import DeletePharm from "@/features/pharm/ui/DeletePharm"; import { userStore } from "@/shared/hooks/user"; import formatDate from "@/shared/lib/formatDate"; import { Button } from "@/shared/ui/button"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, } from "@/shared/ui/dialog"; import { Input } from "@/shared/ui/input"; import Pagination from "@/shared/ui/pagination"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/shared/ui/table"; import { useQuery } from "@tanstack/react-query"; import { Edit, Loader2, Plus, Trash } from "lucide-react"; import { useState } from "react"; const PharmList = () => { const { user: getme } = userStore(); const [currentPage, setCurrentPage] = useState(1); const [nameFilter, setNameFilter] = useState(""); const limit = 20; const { data, isLoading, isError } = useQuery({ queryKey: ["factory_list", currentPage, nameFilter], queryFn: () => factory_api.list({ limit, offset: (currentPage - 1) * limit, name: nameFilter, }), select(data) { return data.data.data; }, }); const totalPages = data ? Math.ceil(data?.count / limit) : 1; const [editingPlan, setEditingPlan] = useState(null); const [dialogOpen, setDialogOpen] = useState(false); const [openDelete, setOpenDelete] = useState(false); const [pillDelete, setPillDelete] = useState(null); const handleDelete = (id: FactoryListDataRes) => { setOpenDelete(true); setPillDelete(id); }; return (

Farmasevtikalar ro'yxati

setNameFilter(e.target.value)} /> {editingPlan ? "Farmasevtikani tahrirlash" : "Yangi farmasevtika qo'shish"}
{isLoading && (
)} {isError && (
Ma'lumotlarni olishda xatolik yuz berdi.
)} {!isLoading && !isError && ( ID Nomi Qo'shilgan sanasi Amallar {data && data.results.length > 0 ? ( data?.results.map((plan) => ( {plan.id} {plan.name} {formatDate.format(plan.created_at, "DD-MM-YYYY")} {getme?.is_superuser && ( )} )) ) : ( Farmasevtika topilmadi. )}
)}
); }; export default PharmList;