hard delete a resurant
This commit is contained in:
@@ -119,3 +119,9 @@ export const useGetRestaurant = (id: string) => {
|
|||||||
enabled: !!id,
|
enabled: !!id,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useHardDeleteRestaurant = () => {
|
||||||
|
return useMutation({
|
||||||
|
mutationFn: (id: string) => api.hardDeleteRestaurant(id),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { FC, useState } from 'react'
|
import { FC, useState } from 'react'
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import { useGetRestaurants } from '../hooks/useIconData'
|
import { useGetRestaurants, useHardDeleteRestaurant } from '../hooks/useIconData'
|
||||||
import PageLoading from '../../../components/PageLoading'
|
import PageLoading from '../../../components/PageLoading'
|
||||||
import Td from '../../../components/Td'
|
import Td from '../../../components/Td'
|
||||||
import { RestaurantType, RestaurantsResponse } from '../types/Types'
|
import { RestaurantType, RestaurantsResponse } from '../types/Types'
|
||||||
@@ -12,15 +12,19 @@ import RestaurantAdminsModal from './components/RestaurantAdminsModal'
|
|||||||
import Pagination from '../../../components/Pagination'
|
import Pagination from '../../../components/Pagination'
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import { Pages } from '../../../config/Pages'
|
import { Pages } from '../../../config/Pages'
|
||||||
|
import TrashWithConfrim from '../../../components/TrashWithConfrim'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
|
||||||
const RestaurantsList: FC = () => {
|
const RestaurantsList: FC = () => {
|
||||||
|
|
||||||
const { t } = useTranslation('global')
|
const { t } = useTranslation('global')
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const [page, setPage] = useState<number>(1)
|
const [page, setPage] = useState<number>(1)
|
||||||
const limit = 10
|
const limit = 10
|
||||||
const { data: restaurants, isLoading } = useGetRestaurants(page, limit)
|
const { data: restaurants, isLoading } = useGetRestaurants(page, limit)
|
||||||
const [selectedRestaurantId, setSelectedRestaurantId] = useState<string>('')
|
const [selectedRestaurantId, setSelectedRestaurantId] = useState<string>('')
|
||||||
const [isAdminsModalOpen, setIsAdminsModalOpen] = useState<boolean>(false)
|
const [isAdminsModalOpen, setIsAdminsModalOpen] = useState<boolean>(false)
|
||||||
|
const deleteRestaurant = useHardDeleteRestaurant()
|
||||||
|
|
||||||
const restaurantsList = (restaurants as RestaurantsResponse | undefined)?.data?.restaurants || []
|
const restaurantsList = (restaurants as RestaurantsResponse | undefined)?.data?.restaurants || []
|
||||||
const totalPages = (restaurants as RestaurantsResponse | undefined)?.data?.pager?.totalPages || 1
|
const totalPages = (restaurants as RestaurantsResponse | undefined)?.data?.pager?.totalPages || 1
|
||||||
@@ -60,6 +64,18 @@ const RestaurantsList: FC = () => {
|
|||||||
return moment(date).format('jYYYY-jMM-jDD')
|
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 (
|
return (
|
||||||
<div className='mt-4'>
|
<div className='mt-4'>
|
||||||
<div className='flex w-full justify-between items-center'>
|
<div className='flex w-full justify-between items-center'>
|
||||||
@@ -135,11 +151,15 @@ const RestaurantsList: FC = () => {
|
|||||||
</Td>
|
</Td>
|
||||||
<Td text={''}>
|
<Td text={''}>
|
||||||
<div className='flex items-center gap-4'>
|
<div className='flex items-center gap-4'>
|
||||||
|
<TrashWithConfrim
|
||||||
|
onDelete={() => handleDeleteRestaurant(item.id)}
|
||||||
|
isLoading={deleteRestaurant.isPending}
|
||||||
|
/>
|
||||||
<Link
|
<Link
|
||||||
to={Pages.dmenu.restaurants.update + item.id}
|
to={Pages.dmenu.restaurants.update + item.id}
|
||||||
>
|
>
|
||||||
<Edit
|
<Edit
|
||||||
size={18}
|
size={20}
|
||||||
color='#8C90A3'
|
color='#8C90A3'
|
||||||
/>
|
/>
|
||||||
</Link>
|
</Link>
|
||||||
|
|||||||
@@ -15,12 +15,14 @@ import { ErrorType } from '../../../helpers/types'
|
|||||||
import { TickCircle } from 'iconsax-react'
|
import { TickCircle } from 'iconsax-react'
|
||||||
import { Pages } from '../../../config/Pages'
|
import { Pages } from '../../../config/Pages'
|
||||||
import moment from 'moment-jalaali'
|
import moment from 'moment-jalaali'
|
||||||
|
import { useQueryClient } from '@tanstack/react-query'
|
||||||
|
|
||||||
const UpdateRestaurant: FC = () => {
|
const UpdateRestaurant: FC = () => {
|
||||||
|
|
||||||
const { id } = useParams()
|
const { id } = useParams()
|
||||||
const { t } = useTranslation('global')
|
const { t } = useTranslation('global')
|
||||||
const navigate = useNavigate()
|
const navigate = useNavigate()
|
||||||
|
const queryClient = useQueryClient()
|
||||||
const { data: restaurantData, isLoading } = useGetRestaurant(id || '')
|
const { data: restaurantData, isLoading } = useGetRestaurant(id || '')
|
||||||
const updateRestaurant = useUpdateRestaurant()
|
const updateRestaurant = useUpdateRestaurant()
|
||||||
|
|
||||||
@@ -56,6 +58,8 @@ const UpdateRestaurant: FC = () => {
|
|||||||
{
|
{
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
toast.success(t('success'))
|
toast.success(t('success'))
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['restaurants'] })
|
||||||
|
queryClient.invalidateQueries({ queryKey: ['restaurant', id] })
|
||||||
navigate(Pages.dmenu.restaurants.list)
|
navigate(Pages.dmenu.restaurants.list)
|
||||||
},
|
},
|
||||||
onError: (error: ErrorType) => {
|
onError: (error: ErrorType) => {
|
||||||
|
|||||||
@@ -112,3 +112,10 @@ export const getRestaurant = async (
|
|||||||
const { data } = await axios.get(`/admin/dmenu/restaurants/${id}`);
|
const { data } = await axios.get(`/admin/dmenu/restaurants/${id}`);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const hardDeleteRestaurant = async (id: string) => {
|
||||||
|
const { data } = await axios.delete(
|
||||||
|
`/admin/dmenu/restaurants/${id}/hard-delete`
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user