import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, } from '@mui/material'; import { useMutation, useQueryClient } from '@tanstack/react-query'; export const DeleteDialog = (props) => { const { params, open, queryKey, service, setOpen } = props; const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: (id) => { return service.destroy(id).then(() => { setOpen(false); }); }, onSuccess: () => { queryClient.invalidateQueries({ queryKey: [queryKey], }); }, }); const handleClose = () => { setOpen(false); }; const itemName = (item) => { if (item) { return ( {item.name || item.title || item.description || 'this item'} ); } }; return ( Delete this? This will delete{' '} {params?.row ? itemName(params?.row) : 'this item'}. Are you sure? ); };