import { Description, Dialog, DialogBackdrop, DialogPanel, DialogTitle, } from '@headlessui/react' import { useEffect, type Dispatch, type SetStateAction } from 'react' import toast from 'react-hot-toast' import { useFetcher } from 'react-router' import type { TSubscribePlanResponse } from '~/apis/common/get-subscribe-plan' import { Button } from '~/components/ui/button' import { formatNumberWithPeriods } from '~/utils/formatter' type TProperties = { selectedItem?: TSubscribePlanResponse setSelectedItem: Dispatch> } export const DialogDelete = (properties: TProperties) => { const { selectedItem, setSelectedItem } = 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('Subscribe plan 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 subscribe plan berikut?

{selectedItem?.name}

Length: {selectedItem?.length}

Harga: Rp. {formatNumberWithPeriods(selectedItem?.price || 0)}

) }