import React, { useCallback, useState } from "react";
|
import DeleteSweepIcon from '@mui/icons-material/DeleteSweep';
|
import {
|
useDataProvider,
|
useNotify,
|
useRefresh,
|
Button as RaButton,
|
} from 'react-admin';
|
import ConfirmButton from "../components/ConfirmButton";
|
|
const LaneDeleteAllButton = () => {
|
const dataProvider = useDataProvider();
|
const notify = useNotify();
|
const refresh = useRefresh();
|
const [loading, setLoading] = useState(false);
|
|
const handleConfirm = useCallback(() => {
|
setLoading(true);
|
dataProvider.delete('lane', {
|
id: '__purge_all__',
|
meta: { deleteAll: true },
|
}).then(() => {
|
notify('page.lane.actions.deleteAllSuccess', { type: 'info' });
|
refresh();
|
}).catch((error) => {
|
console.error(error);
|
notify('page.lane.actions.deleteAllError', { type: 'error' });
|
}).finally(() => {
|
setLoading(false);
|
});
|
}, [dataProvider, notify, refresh]);
|
|
return (
|
<ConfirmButton
|
label="page.lane.actions.deleteAll"
|
onConfirm={handleConfirm}
|
disabled={loading}
|
renderButton={({ buttonProps }) => (
|
<RaButton
|
{...buttonProps}
|
label="page.lane.actions.deleteAll"
|
color="error"
|
size="small"
|
startIcon={<DeleteSweepIcon />}
|
sx={{
|
fontWeight: 600,
|
textTransform: 'none',
|
}}
|
/>
|
)}
|
/>
|
);
|
};
|
|
export default LaneDeleteAllButton;
|