import { type FC, useState } from 'react' import { useGetWarranties, useDeleteWarranty } from './hooks/useWarrantyData' import { type Warranty } from './types/Types' import PageLoading from '@/components/PageLoading' import Error from '@/components/Error' import PaginationUi from '@/components/PaginationUi' import Td from '@/components/Td' import TrashWithConfrim from '@/components/TrashWithConfrim' import Button from '@/components/Button' import { useNavigate } from 'react-router-dom' import { Pages } from '@/config/Pages' const WarrantyList: FC = () => { const navigate = useNavigate() const [currentPage, setCurrentPage] = useState(1); const { data: warrantiesData, isLoading, error, refetch } = useGetWarranties(currentPage) const deleteWarrantyMutation = useDeleteWarranty(); if (isLoading) { return (
); } if (error) { return (
); } const handleDeleteWarranty = async (warrantyId: string) => { await deleteWarrantyMutation.mutateAsync(warrantyId); refetch() }; const warranties = warrantiesData?.results?.warranties || []; const pager = warrantiesData?.results?.pager; return (
{warranties.length === 0 ? ( ) : ( warranties.map((warranty: Warranty) => ( )) )}
هیچ گارانتی یافت نشد
{warranty.name}
{warranty.status}
handleDeleteWarranty(warranty._id.toString())} isLoading={deleteWarrantyMutation.isPending} />
{ setCurrentPage(page); }} />
) } export default WarrantyList