diff --git a/app/components/assets/delete-asset-dialog.tsx b/app/components/assets/delete-asset-dialog.tsx new file mode 100644 index 0000000..4e0573d --- /dev/null +++ b/app/components/assets/delete-asset-dialog.tsx @@ -0,0 +1,34 @@ +import { useFetcher } from 'react-router'; +import { ConfirmDialog } from '~/components/ui/confirm-dialog'; +import { ASSET_INTENT, type AssetIntent } from '~/data/assets/constants'; +import { ROUTES } from '~/data/routes'; +import { useActionToast } from '~/hooks/use-action-toast'; +import type { ActionResult } from '~/types/action'; +import type { ArAsset } from '~/types/asset'; + +interface DeleteAssetDialogProps { + asset: ArAsset | null; + onClose: () => void; + onDeleted?: () => void; +} + +export function DeleteAssetDialog({ asset, onClose, onDeleted }: DeleteAssetDialogProps) { + const fetcher = useFetcher>(); + + useActionToast(fetcher.data, () => { + onClose(); + onDeleted?.(); + }); + + return ( + !open && onClose()} + title='Delete asset?' + description={`"${asset?.name ?? ''}" will be permanently deleted and its QR code will stop working.`} + confirmLabel='Delete' + pending={fetcher.state !== 'idle'} + onConfirm={() => asset && fetcher.submit({ intent: ASSET_INTENT.delete, id: asset.id }, { method: 'post', action: ROUTES.assets })} + /> + ); +}