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';
|
import { ConfirmDialog } from '@/components/dialogs';
|
||||||
|
|
||||||
type DeleteConfirmDialogProps<T> = {
|
type DeleteConfirmDialogProps<T> = {
|
||||||
@ -19,10 +20,22 @@ export function DeleteConfirmDialog<T>({
|
|||||||
variant,
|
variant,
|
||||||
onConfirm,
|
onConfirm,
|
||||||
}: DeleteConfirmDialogProps<T>) {
|
}: DeleteConfirmDialogProps<T>) {
|
||||||
|
const [loading, setLoading] = useState(false);
|
||||||
|
|
||||||
|
function handleConfirm() {
|
||||||
|
setLoading(true);
|
||||||
|
onConfirm();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ConfirmDialog
|
<ConfirmDialog
|
||||||
open={target !== null}
|
open={target !== null}
|
||||||
onOpenChange={onOpenChange}
|
onOpenChange={(open) => {
|
||||||
|
if (!open) {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
onOpenChange(open);
|
||||||
|
}}
|
||||||
title={title}
|
title={title}
|
||||||
description={
|
description={
|
||||||
typeof description === 'function' && target
|
typeof description === 'function' && target
|
||||||
@ -33,7 +46,8 @@ export function DeleteConfirmDialog<T>({
|
|||||||
}
|
}
|
||||||
confirmLabel={confirmLabel}
|
confirmLabel={confirmLabel}
|
||||||
variant={variant}
|
variant={variant}
|
||||||
onConfirm={onConfirm}
|
onConfirm={handleConfirm}
|
||||||
|
loading={loading}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user