feat: add delete asset dialog
This commit is contained in:
parent
1d2720f273
commit
3a6b6af96a
34
app/components/assets/delete-asset-dialog.tsx
Normal file
34
app/components/assets/delete-asset-dialog.tsx
Normal 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 })}
|
||||
/>
|
||||
);
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user