import { Description, Dialog, DialogBackdrop, DialogPanel, DialogTitle, } from '@headlessui/react' import { useEffect, type PropsWithChildren } from 'react' import toast from 'react-hot-toast' import { useFetcher } from 'react-router' import { Button } from '~/components/ui/button' type TProperties = PropsWithChildren & { selectedId?: string close: () => void title: string fetcherAction: string } export const DialogDelete = (properties: TProperties) => { const { selectedId, close, children, title, fetcherAction } = properties || {} const fetcher = useFetcher() useEffect(() => { if (!fetcher.data?.success && fetcher.data?.message) { toast.error(fetcher.data.message) } if (fetcher.data?.success) { close() toast.success(`${title} berhasil dihapus!`) } // eslint-disable-next-line react-hooks/exhaustive-deps }, [fetcher.data]) return ( { if (fetcher.state === 'idle') { close() } }} className="relative z-50" transition >
Anda akan menghapus{' '} {title} berikut? {children}
) }