|
|
@@ -2,6 +2,8 @@ import { AlertTriangle } from 'lucide-react'
|
|
|
import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert'
|
|
|
import { ConfirmDialog } from '@/components/confirm-dialog'
|
|
|
import { type Post } from '@/types/posts.types'
|
|
|
+import { useDeletePost } from '@/hooks/posts/useDeletePost'
|
|
|
+import { toast } from 'sonner'
|
|
|
|
|
|
interface Props {
|
|
|
open: boolean
|
|
|
@@ -10,23 +12,26 @@ interface Props {
|
|
|
}
|
|
|
|
|
|
export function PostsDeleteDialog({ open, onOpenChange, currentRow }: Props) {
|
|
|
- // const { mutate, isPending } = useDeleteUser()
|
|
|
+ const { mutate, isPending } = useDeletePost()
|
|
|
|
|
|
if (!currentRow) return null
|
|
|
|
|
|
- // const handleDelete = () => {
|
|
|
- // mutate(currentRow.id, {
|
|
|
- // onSuccess: () => {
|
|
|
- // onOpenChange(false)
|
|
|
- // },
|
|
|
- // })
|
|
|
- // }
|
|
|
+ const handleDelete = () => {
|
|
|
+ mutate(
|
|
|
+ { id: currentRow.id },
|
|
|
+ {
|
|
|
+ onSuccess: () => {
|
|
|
+ onOpenChange(false)
|
|
|
+ toast.success('پست مورد نظر با موفقیت حذف شد!')
|
|
|
+ },
|
|
|
+ }
|
|
|
+ )
|
|
|
+ }
|
|
|
|
|
|
return (
|
|
|
<ConfirmDialog
|
|
|
open={open}
|
|
|
onOpenChange={onOpenChange}
|
|
|
- form='posts-delete-form'
|
|
|
title={
|
|
|
<span className='text-destructive'>
|
|
|
<AlertTriangle
|
|
|
@@ -46,8 +51,9 @@ export function PostsDeleteDialog({ open, onOpenChange, currentRow }: Props) {
|
|
|
}
|
|
|
confirmText='حذف'
|
|
|
cancelBtnText='انصراف'
|
|
|
- // isLoading={isPending}
|
|
|
+ isLoading={isPending}
|
|
|
destructive
|
|
|
+ handleConfirm={handleDelete}
|
|
|
/>
|
|
|
)
|
|
|
}
|