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