feat: add delete asset dialog

This commit is contained in:
rajun 2026-10-27 16:28:48 +05:30
parent 1d2720f273
commit 3a6b6af96a

View File

@ -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<ActionResult<AssetIntent>>();
useActionToast(fetcher.data, () => {
onClose();
onDeleted?.();
});
return (
<ConfirmDialog
open={!!asset}
onOpenChange={(open) => !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 })}
/>
);
}