From 242e81ffbfbd1f8b0e6af0b3f44bae3ebb1bf0c4 Mon Sep 17 00:00:00 2001 From: hamid zarghami Date: Tue, 17 Feb 2026 12:34:54 +0330 Subject: [PATCH] Delete bill --- src/pages/bill/List.tsx | 24 +++++++++++++++++++----- src/pages/bill/hooks/useBillData.ts | 6 ++++++ src/pages/bill/service/Service.ts | 11 ++++++++++- 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/pages/bill/List.tsx b/src/pages/bill/List.tsx index 7c8f278..4adb3a6 100644 --- a/src/pages/bill/List.tsx +++ b/src/pages/bill/List.tsx @@ -1,5 +1,5 @@ import { FC, Fragment, useState } from 'react' -import { useGetBills } from './hooks/useBillData' +import { useDeleteBill, useGetBills } from './hooks/useBillData' import Td from '../../components/Td' import PageLoading from '../../components/PageLoading' import { BillItemType } from './types/Types' @@ -9,11 +9,13 @@ import { useTranslation } from 'react-i18next' import { Link } from 'react-router-dom' import { Pages } from '../../config/Pages' import { Eye } from 'iconsax-react' +import TrashWithConfrim from '../../components/TrashWithConfrim' const BillsList: FC = () => { const { t } = useTranslation('global') const [page, setPage] = useState(1) - const { data, isLoading } = useGetBills(page) + const { data, isLoading, refetch } = useGetBills(page) + const { mutate: deleteBill, isPending } = useDeleteBill() const getBillTypeLabel = (type: BillItemType['type']) => { return type === 'water_bill' ? t('bill.water_bill') : t('bill.monthly_charge') @@ -49,9 +51,21 @@ const BillsList: FC = () => { - - - +
+ + + + { + deleteBill(item.id, { + onSuccess: () => { + refetch() + } + }) + }} + /> +
))} diff --git a/src/pages/bill/hooks/useBillData.ts b/src/pages/bill/hooks/useBillData.ts index 1f0dca0..90ba0fc 100644 --- a/src/pages/bill/hooks/useBillData.ts +++ b/src/pages/bill/hooks/useBillData.ts @@ -25,3 +25,9 @@ export const useGetBills = (page: number = 1) => { queryFn: () => api.getBills(page), }); }; + +export const useDeleteBill = () => { + return useMutation({ + mutationFn: api.deleteBill, + }); +}; diff --git a/src/pages/bill/service/Service.ts b/src/pages/bill/service/Service.ts index 127d0fa..dc419b7 100644 --- a/src/pages/bill/service/Service.ts +++ b/src/pages/bill/service/Service.ts @@ -1,5 +1,9 @@ import axios from "../../../config/axios"; -import { CreateBillType, CreateBillChargeType, CreateBillWithExcelType } from "../types/Types"; +import { + CreateBillType, + CreateBillChargeType, + CreateBillWithExcelType, +} from "../types/Types"; export const createBill = async (params: CreateBillType) => { const { data } = await axios.post("/bills/water", params); @@ -26,3 +30,8 @@ export const createBillWithExcel = async (params: CreateBillWithExcelType) => { }); return data; }; + +export const deleteBill = async (id: string) => { + const { data } = await axios.delete(`/bills/${id}`); + return data; +};