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

Notif on form error and bug corrected

parent 10829504
Pipeline #27286 passed with stages
in 2 minutes and 48 seconds
...@@ -68,7 +68,7 @@ class Editor extends MyComponent { ...@@ -68,7 +68,7 @@ class Editor extends MyComponent {
hasChangesToSave(formData, modelData) { hasChangesToSave(formData, modelData) {
for (let fieldKey in formData) { for (let fieldKey in formData) {
if (formData[fieldKey] != modelData[fieldKey]) { if (formData[fieldKey] != modelData[fieldKey]) {
console.log(fieldKey, formData[fieldKey], modelData[fieldKey]); // console.log(fieldKey, formData[fieldKey], modelData[fieldKey]);
return true; return true;
} }
} }
...@@ -76,8 +76,7 @@ class Editor extends MyComponent { ...@@ -76,8 +76,7 @@ class Editor extends MyComponent {
} }
handleSaveEditor() { handleSaveEditor() {
if (this.formIsValid() && !this.formFieldsHaveError()) {
if (this.formIsValid()) {
const formData = this.getDataFromFields(); const formData = this.getDataFromFields();
const { modelData } = this.props; const { modelData } = this.props;
if (this.hasChangesToSave(formData, modelData)) { if (this.hasChangesToSave(formData, modelData)) {
...@@ -104,7 +103,15 @@ class Editor extends MyComponent { ...@@ -104,7 +103,15 @@ class Editor extends MyComponent {
} }
} else { } 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 { ...@@ -151,7 +158,8 @@ class Editor extends MyComponent {
handleCloseNotification() { handleCloseNotification() {
this.setState({ this.setState({
notification: { open: false } // backup message to prevent graphic artefact
notification: { open: false, message: this.state.notification.message }
}) })
} }
......
import React from 'react'; import React from 'react';
import PropTypes, { array } from 'prop-types'; import PropTypes, { array } from 'prop-types';
import { withStyles } from '@material-ui/core/styles'; import { withStyles } from '@material-ui/core/styles';
import Button from '@material-ui/core/Button';
import Snackbar from '@material-ui/core/Snackbar'; import Snackbar from '@material-ui/core/Snackbar';
import DoneIcon from '@material-ui/icons/Done'; import DoneIcon from '@material-ui/icons/Done';
import Loading from '../../../../components/other/Loading' import Loading from '../../../../components/other/Loading'
import IconButton from '@material-ui/core/IconButton';
import CloseIcon from '@material-ui/icons/Close';
const styles = theme => ({ const styles = theme => ({
close: { close: {
...@@ -33,6 +34,18 @@ class Notification extends React.Component { ...@@ -33,6 +34,18 @@ class Notification extends React.Component {
actions.push( actions.push(
<DoneIcon color='primary' /> <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 ( return (
...@@ -62,6 +75,7 @@ Notification.defaultProps = { ...@@ -62,6 +75,7 @@ Notification.defaultProps = {
message: "", message: "",
preventClickAway: true, preventClickAway: true,
success: false, success: false,
error: false,
isLoading: false, isLoading: false,
handleClose: () => console.log("cloossee notif") handleClose: () => console.log("cloossee notif")
} }
...@@ -73,6 +87,7 @@ Notification.propTypes = { ...@@ -73,6 +87,7 @@ Notification.propTypes = {
message: PropTypes.string.isRequired, message: PropTypes.string.isRequired,
preventClickAway: PropTypes.bool.isRequired, preventClickAway: PropTypes.bool.isRequired,
success: PropTypes.bool.isRequired, success: PropTypes.bool.isRequired,
error: PropTypes.bool.isRequired,
isLoading: PropTypes.bool.isRequired, isLoading: PropTypes.bool.isRequired,
handleClose: PropTypes.func.isRequired, handleClose: PropTypes.func.isRequired,
}; };
......
...@@ -18,7 +18,7 @@ const styles = theme => ({ ...@@ -18,7 +18,7 @@ const styles = theme => ({
class SelectField extends Field { class SelectField extends Field {
hasError(value) { hasError(value) {
return this.props.required && !value; return this.props.required && (value == null);
} }
handleChangeValue = (value) => { 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