mirror of
https://gitlab.com/comunic/comunicconsole
synced 2025-07-07 10:32:50 +00:00
Can easily show alert dialogs
This commit is contained in:
79
src/ui/widgets/DialogsProvider.tsx
Normal file
79
src/ui/widgets/DialogsProvider.tsx
Normal 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);
|
||||
}
|
Reference in New Issue
Block a user