Can easily show alert dialogs

This commit is contained in:
2021-05-10 16:58:45 +02:00
parent 0ed340c592
commit 10e0440a5a
9 changed files with 359 additions and 60 deletions

View File

@ -0,0 +1,79 @@
/**
* Application dialogs provider
*
* @author Pierre Hubert
*/
import { Dialog, DialogTitle, DialogContent, DialogContentText, DialogActions, Button } from "@material-ui/core";
import React from "react";
let cache : ApplicationDialogsProvider;
interface AppDiagProvState {
// Alert dialog
alertMessage : string,
showAlert : boolean,
}
export class ApplicationDialogsProvider extends React.Component<{}, AppDiagProvState> {
constructor(props: any) {
super(props);
this.setState({
// Alert dialog
alertMessage: "",
showAlert: false,
});
this.handleCloseAlert = this.handleCloseAlert.bind(this);
}
showAlert(message: string) {
this.setState({
showAlert: true,
alertMessage: message
})
}
handleCloseAlert() {
this.setState({showAlert: false});
}
render() {
cache = this;
if(this.state == null)
return(<div></div>);
return (<div>
{/* Simple alert dialog */}
<Dialog
open={this.state.showAlert}
onClose={this.handleCloseAlert}
aria-labelledby="alert-dialog-title"
aria-describedby="alert-dialog-description"
>
<DialogTitle id="alert-dialog-title" style={{minWidth: "300px"}}>Message</DialogTitle>
<DialogContent>
<DialogContentText id="alert-dialog-description">
{this.state.alertMessage}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={this.handleCloseAlert} color="default">
OK
</Button>
</DialogActions>
</Dialog>
</div>)
}
}
export function matAlert(msg: string) {
cache.showAlert(msg);
}