Initial commit - copied workspace after database cleanup
This commit is contained in:
36
dashboard/src/hooks/useClientDelete.ts
Normal file
36
dashboard/src/hooks/useClientDelete.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { useState } from 'react';
|
||||
import { deleteClient } from '../apiClients';
|
||||
|
||||
export function useClientDelete(onDeleted?: (uuid: string) => void) {
|
||||
const [showDialog, setShowDialog] = useState(false);
|
||||
const [deleteClientId, setDeleteClientId] = useState<string | null>(null);
|
||||
|
||||
// Details-Modal separat im Parent verwalten!
|
||||
|
||||
const handleDelete = (uuid: string) => {
|
||||
setDeleteClientId(uuid);
|
||||
setShowDialog(true);
|
||||
};
|
||||
|
||||
const confirmDelete = async () => {
|
||||
if (deleteClientId) {
|
||||
await deleteClient(deleteClientId);
|
||||
setShowDialog(false);
|
||||
if (onDeleted) onDeleted(deleteClientId);
|
||||
setDeleteClientId(null);
|
||||
}
|
||||
};
|
||||
|
||||
const cancelDelete = () => {
|
||||
setShowDialog(false);
|
||||
setDeleteClientId(null);
|
||||
};
|
||||
|
||||
return {
|
||||
showDialog,
|
||||
deleteClientId,
|
||||
handleDelete,
|
||||
confirmDelete,
|
||||
cancelDelete,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user