ar-test/app/components/assets/delete-asset-dialog.tsx

35 lines
1.2 KiB
TypeScript

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 })}
/>
);
}