delete invoice

This commit is contained in:
hamid zarghami
2025-10-23 17:54:30 +03:30
parent f49a8641fc
commit 45a4a9e561
3 changed files with 36 additions and 4 deletions
+22 -1
View File
@@ -3,7 +3,7 @@ import { useTranslation } from 'react-i18next'
import Tabs from '../../components/Tabs' import Tabs from '../../components/Tabs'
import { Edit, FolderOpen, WalletCheck, WalletMinus, WalletRemove, WalletSearch } from 'iconsax-react' import { Edit, FolderOpen, WalletCheck, WalletMinus, WalletRemove, WalletSearch } from 'iconsax-react'
import Td from '../../components/Td' import Td from '../../components/Td'
import { useGetInvoices } from './hooks/useReceiptData' import { useDeleteInvoice, useGetInvoices } from './hooks/useReceiptData'
import PageLoading from '../../components/PageLoading' import PageLoading from '../../components/PageLoading'
import { InvoiceStatus, InvoiceUserItemType, ReceiptItemType } from './types/ReceiptTypes' import { InvoiceStatus, InvoiceUserItemType, ReceiptItemType } from './types/ReceiptTypes'
import { NumberFormat } from '../../config/func' import { NumberFormat } from '../../config/func'
@@ -14,6 +14,9 @@ import { Link, useSearchParams } from 'react-router-dom'
import moment from 'moment-jalaali' import moment from 'moment-jalaali'
import Pagination from '../../components/Pagination' import Pagination from '../../components/Pagination'
import { Pages } from '../../config/Pages' import { Pages } from '../../config/Pages'
import TrashWithConfrim from '../../components/TrashWithConfrim'
import { ErrorType } from '../../helpers/types'
import { toast } from 'react-toastify'
const ReceiptsList: FC = () => { const ReceiptsList: FC = () => {
@@ -26,7 +29,19 @@ const ReceiptsList: FC = () => {
const [date, setDate] = useState<string>('') const [date, setDate] = useState<string>('')
const [endDate, setEndDate] = useState<string>('') const [endDate, setEndDate] = useState<string>('')
const getInvoices = useGetInvoices(activeTab, customerId, search, date, endDate, page) const getInvoices = useGetInvoices(activeTab, customerId, search, date, endDate, page)
const deleteInvoice = useDeleteInvoice()
const handleDeleteInvoice = (id: string) => {
deleteInvoice.mutate(id, {
onSuccess: () => {
toast.success(t('success'))
getInvoices.refetch()
},
onError: (error: ErrorType) => {
toast.error(error.response?.data?.error?.message[0])
}
})
}
useEffect(() => { useEffect(() => {
const urlCustomerId = searchParams.get('user') const urlCustomerId = searchParams.get('user')
if (urlCustomerId) { if (urlCustomerId) {
@@ -161,9 +176,15 @@ const ReceiptsList: FC = () => {
{item.maxRecurringCycles} {item.maxRecurringCycles}
</Td> </Td>
<Td text={''}> <Td text={''}>
<div className='flex gap-2'>
<Link to={Pages.receipts.detail + item.id}> <Link to={Pages.receipts.detail + item.id}>
<Edit size={20} color='#888' /> <Edit size={20} color='#888' />
</Link> </Link>
<TrashWithConfrim
onDelete={() => handleDeleteInvoice(item.id)}
isLoading={deleteInvoice.isPending}
/>
</div>
</Td> </Td>
</tr> </tr>
) )
@@ -36,3 +36,9 @@ export const useUpdateInvoice = () => {
api.updateInvoice(id, params), api.updateInvoice(id, params),
}); });
}; };
export const useDeleteInvoice = () => {
return useMutation({
mutationFn: api.deleteInvoice,
});
};
@@ -35,3 +35,8 @@ export const updateInvoice = async (id: string, params: CreateReceiptType) => {
const { data } = await axios.patch(`/invoices/${id}`, params); const { data } = await axios.patch(`/invoices/${id}`, params);
return data; return data;
}; };
export const deleteInvoice = async (id: string) => {
const { data } = await axios.delete(`/invoices/${id}`);
return data;
};