hard delete a resurant

This commit is contained in:
hamid zarghami
2026-01-06 09:37:33 +03:30
parent b3943b8e07
commit e47816470a
4 changed files with 39 additions and 2 deletions
+6
View File
@@ -119,3 +119,9 @@ export const useGetRestaurant = (id: string) => {
enabled: !!id,
});
};
export const useHardDeleteRestaurant = () => {
return useMutation({
mutationFn: (id: string) => api.hardDeleteRestaurant(id),
});
};
+22 -2
View File
@@ -1,6 +1,6 @@
import { FC, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { useGetRestaurants } from '../hooks/useIconData'
import { useGetRestaurants, useHardDeleteRestaurant } from '../hooks/useIconData'
import PageLoading from '../../../components/PageLoading'
import Td from '../../../components/Td'
import { RestaurantType, RestaurantsResponse } from '../types/Types'
@@ -12,15 +12,19 @@ import RestaurantAdminsModal from './components/RestaurantAdminsModal'
import Pagination from '../../../components/Pagination'
import { Link } from 'react-router-dom'
import { Pages } from '../../../config/Pages'
import TrashWithConfrim from '../../../components/TrashWithConfrim'
import { useQueryClient } from '@tanstack/react-query'
const RestaurantsList: FC = () => {
const { t } = useTranslation('global')
const queryClient = useQueryClient()
const [page, setPage] = useState<number>(1)
const limit = 10
const { data: restaurants, isLoading } = useGetRestaurants(page, limit)
const [selectedRestaurantId, setSelectedRestaurantId] = useState<string>('')
const [isAdminsModalOpen, setIsAdminsModalOpen] = useState<boolean>(false)
const deleteRestaurant = useHardDeleteRestaurant()
const restaurantsList = (restaurants as RestaurantsResponse | undefined)?.data?.restaurants || []
const totalPages = (restaurants as RestaurantsResponse | undefined)?.data?.pager?.totalPages || 1
@@ -60,6 +64,18 @@ const RestaurantsList: FC = () => {
return moment(date).format('jYYYY-jMM-jDD')
}
const handleDeleteRestaurant = (restaurantId: string) => {
deleteRestaurant.mutate(restaurantId, {
onSuccess: () => {
toast.success('رستوران با موفقیت حذف شد')
queryClient.invalidateQueries({ queryKey: ['restaurants'] })
},
onError: () => {
toast.error('خطا در حذف رستوران')
}
})
}
return (
<div className='mt-4'>
<div className='flex w-full justify-between items-center'>
@@ -135,11 +151,15 @@ const RestaurantsList: FC = () => {
</Td>
<Td text={''}>
<div className='flex items-center gap-4'>
<TrashWithConfrim
onDelete={() => handleDeleteRestaurant(item.id)}
isLoading={deleteRestaurant.isPending}
/>
<Link
to={Pages.dmenu.restaurants.update + item.id}
>
<Edit
size={18}
size={20}
color='#8C90A3'
/>
</Link>
+4
View File
@@ -15,12 +15,14 @@ import { ErrorType } from '../../../helpers/types'
import { TickCircle } from 'iconsax-react'
import { Pages } from '../../../config/Pages'
import moment from 'moment-jalaali'
import { useQueryClient } from '@tanstack/react-query'
const UpdateRestaurant: FC = () => {
const { id } = useParams()
const { t } = useTranslation('global')
const navigate = useNavigate()
const queryClient = useQueryClient()
const { data: restaurantData, isLoading } = useGetRestaurant(id || '')
const updateRestaurant = useUpdateRestaurant()
@@ -56,6 +58,8 @@ const UpdateRestaurant: FC = () => {
{
onSuccess: () => {
toast.success(t('success'))
queryClient.invalidateQueries({ queryKey: ['restaurants'] })
queryClient.invalidateQueries({ queryKey: ['restaurant', id] })
navigate(Pages.dmenu.restaurants.list)
},
onError: (error: ErrorType) => {
+7
View File
@@ -112,3 +112,10 @@ export const getRestaurant = async (
const { data } = await axios.get(`/admin/dmenu/restaurants/${id}`);
return data;
};
export const hardDeleteRestaurant = async (id: string) => {
const { data } = await axios.delete(
`/admin/dmenu/restaurants/${id}/hard-delete`
);
return data;
};