Commit 9e940bf1 authored by Florent Chehab's avatar Florent Chehab
Browse files

Alert when closing with unsave data

parent 22a5c7fe
......@@ -172,6 +172,33 @@ class Editor extends MyComponent {
})
}
handleCloseEditorRequest() {
console.log("close asked !")
const formData = this.getDataFromFields();
const { modelData } = this.props;
if (this.hasChangesToSave(formData, modelData)) {
this.setState({
alert: {
open: true,
info: false,
title: "Modifications non enregistrées !",
description: "Vous avez des modifications qui n'ont pas été sauvegardées. Voulez-vous les enregistrer ?",
agreeText: "Oui, je les enregistre",
disagreeText: "Non",
handleResponse: (agree) => {
if (agree) {
this.handleSaveEditor();
} else {
this.props.handleCloseEditor();
}
},
}
})
} else {
this.props.handleCloseEditor();
}
}
renderEditor() {
return (<div>No editor set</div>)
}
......@@ -208,7 +235,6 @@ class Editor extends MyComponent {
<Dialog
fullScreen
open={this.props.open}
onClose={this.props.handleCloseEditor}
TransitionComponent={Transition}
>
<Alert
......@@ -217,7 +243,7 @@ class Editor extends MyComponent {
/>
<AppBar className={classes.appBar} >
<Toolbar>
<IconButton color="inherit" onClick={this.props.handleCloseEditor} aria-label="Close">
<IconButton color="inherit" onClick={() => this.handleCloseEditorRequest()} aria-label="Close">
<CloseIcon />
</IconButton>
<Typography variant="title" color="inherit" className={classes.flex}>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment