Commit 42dbc13a authored by Florent Chehab's avatar Florent Chehab
Browse files

Notif on form error and bug corrected

parent 10829504
......@@ -68,7 +68,7 @@ class Editor extends MyComponent {
hasChangesToSave(formData, modelData) {
for (let fieldKey in formData) {
if (formData[fieldKey] != modelData[fieldKey]) {
console.log(fieldKey, formData[fieldKey], modelData[fieldKey]);
// console.log(fieldKey, formData[fieldKey], modelData[fieldKey]);
return true;
}
}
......@@ -76,8 +76,7 @@ class Editor extends MyComponent {
}
handleSaveEditor() {
if (this.formIsValid()) {
if (this.formIsValid() && !this.formFieldsHaveError()) {
const formData = this.getDataFromFields();
const { modelData } = this.props;
if (this.hasChangesToSave(formData, modelData)) {
......@@ -104,7 +103,15 @@ class Editor extends MyComponent {
}
} else {
console.log("ici")
this.setState({
notification: {
open: true,
message: "Le formulaire semble incohérent, merci de vérifier son contenu.",
duration: 5000,
error: true,
handleClose: this.handleCloseNotification()
}
})
}
}
......@@ -151,7 +158,8 @@ class Editor extends MyComponent {
handleCloseNotification() {
this.setState({
notification: { open: false }
// backup message to prevent graphic artefact
notification: { open: false, message: this.state.notification.message }
})
}
......
import React from 'react';
import PropTypes, { array } from 'prop-types';
import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Snackbar from '@material-ui/core/Snackbar';
import DoneIcon from '@material-ui/icons/Done';
import Loading from '../../../../components/other/Loading'
import IconButton from '@material-ui/core/IconButton';
import CloseIcon from '@material-ui/icons/Close';
const styles = theme => ({
close: {
......@@ -33,6 +34,18 @@ class Notification extends React.Component {
actions.push(
<DoneIcon color='primary' />
)
} else if (this.props.error) {
actions.push(
<IconButton
key="close"
aria-label="Fermer"
color="inherit"
className={classes.close}
onClick={this.props.handleClose}
>
<CloseIcon />
</IconButton>
)
}
return (
......@@ -62,6 +75,7 @@ Notification.defaultProps = {
message: "",
preventClickAway: true,
success: false,
error: false,
isLoading: false,
handleClose: () => console.log("cloossee notif")
}
......@@ -73,6 +87,7 @@ Notification.propTypes = {
message: PropTypes.string.isRequired,
preventClickAway: PropTypes.bool.isRequired,
success: PropTypes.bool.isRequired,
error: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired,
handleClose: PropTypes.func.isRequired,
};
......
......@@ -18,7 +18,7 @@ const styles = theme => ({
class SelectField extends Field {
hasError(value) {
return this.props.required && !value;
return this.props.required && (value == null);
}
handleChangeValue = (value) => {
......
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