feat: enhance DeleteConfirmDialog with loading state and confirm handler
This commit is contained in:
parent
10d2529dcd
commit
8377c25173
@ -1,3 +1,4 @@
|
||||
import { useState } from 'react';
|
||||
import { ConfirmDialog } from '@/components/dialogs';
|
||||
|
||||
type DeleteConfirmDialogProps<T> = {
|
||||
@ -19,10 +20,22 @@ export function DeleteConfirmDialog<T>({
|
||||
variant,
|
||||
onConfirm,
|
||||
}: DeleteConfirmDialogProps<T>) {
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
function handleConfirm() {
|
||||
setLoading(true);
|
||||
onConfirm();
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfirmDialog
|
||||
open={target !== null}
|
||||
onOpenChange={onOpenChange}
|
||||
onOpenChange={(open) => {
|
||||
if (!open) {
|
||||
setLoading(false);
|
||||
}
|
||||
onOpenChange(open);
|
||||
}}
|
||||
title={title}
|
||||
description={
|
||||
typeof description === 'function' && target
|
||||
@ -33,7 +46,8 @@ export function DeleteConfirmDialog<T>({
|
||||
}
|
||||
confirmLabel={confirmLabel}
|
||||
variant={variant}
|
||||
onConfirm={onConfirm}
|
||||
onConfirm={handleConfirm}
|
||||
loading={loading}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user