In a react-admin project I created my own toolbar button that should display a confirmation dialog, similar to the JavaScript alert but not quite as ugly.
Only when the user clicks OK, things should happen, in my case some database operations.
is there an ootb alert dialog in react-admin or what is an easy way to create one? I could not find anything in the docs about that topic. I tried the alert example from material ui (see https://v1.material-ui.com/demos/dialogs/) but due to my very limited understandig of react I am not able to create a reusable component from the example.
Update:
The code snippet below illustrates what I'd like to do:
// Definition of a toolbar button
const ActionButton = ({ handleSubmitWithRedirect, ...props }) => {
const form = useForm();
var formdata = form.getState().values;
switch (formdata.status.id) {
case 0:
props.label = "Text for state 0";
break;
case 1:
props.label = "Text for state 2";
break;
default:
props.label = "Unknown state"
}
const handleClick = useCallback(() => {
switch (formdata.status.id) {
case 0:
form.change('status', status[1]);
break;
case 1:
// Here I want to open a confirmation Dialog...
if( openAlertDialog("Warning, things will happen","Okay","Better not"))
{
form.change('status', status[2]);
createDatabaseRecord(formdata).then(() => (
// success handling [...]
),
() => (
// error handling [...]
))
};
break;
default:
}
handleSubmitWithRedirect('list');
}, [formdata, form]);
return <SaveButton {...props} handleSubmitWithRedirect={handleClick} />;
};