Commit 5689754f authored by Florent Chehab's avatar Florent Chehab

Better generalization

parent 6298e660
Pipeline #27348 passed with stages
in 2 minutes and 38 seconds
...@@ -9,6 +9,9 @@ import editorStyle from '../shared/editorStyle'; ...@@ -9,6 +9,9 @@ import editorStyle from '../shared/editorStyle';
import TextField from '../shared/fields/TextField'; import TextField from '../shared/fields/TextField';
import getMapStateToPropsForEditor from '../shared/editorFunctions/getMapStateToPropsForEditor';
import getMapDispatchToPropsForEditor from '../shared/editorFunctions/getMapDispatchToPropsForEditor';
import { import {
universitiesElSaveData, universitiesElSaveData,
universitiesElSavingHasError universitiesElSavingHasError
...@@ -57,35 +60,15 @@ class UniversityGeneral extends Editor { ...@@ -57,35 +60,15 @@ class UniversityGeneral extends Editor {
} }
UniversityGeneral.propTypes = { UniversityGeneral.propTypes = {
modelData: PropTypes.object.isRequired, modelData: PropTypes.object.isRequired,
}; };
const mapStateToProps = (state) => {
let lastUpdateTime = null;
const tmp = state.universitiesEl.fetched;
if (tmp.fetchedAt) {
lastUpdateTime = tmp.data.updated_on;
}
return {
savingHasError: state.universitiesEl.savingHasError,
lastSaveTime: state.universitiesEl.savedAt,
lastUpdateTime,
};
};
const mapDispatchToProps = (dispatch) => {
return {
saveData: (data) => dispatch(universitiesElSaveData(data)),
clearSaveError: () => dispatch(universitiesElSavingHasError(false))
};
};
export default compose( export default compose(
withStyles(styles, { withTheme: true }), withStyles(styles, { withTheme: true }),
connect(mapStateToProps, mapDispatchToProps) connect(
getMapStateToPropsForEditor('universitiesEl'),
getMapDispatchToPropsForEditor(universitiesElSaveData, universitiesElSavingHasError)
)
)(UniversityGeneral); )(UniversityGeneral);
\ No newline at end of file
...@@ -12,6 +12,9 @@ import MarkdownField from '../shared/fields/MarkdownField'; ...@@ -12,6 +12,9 @@ import MarkdownField from '../shared/fields/MarkdownField';
import dateStrToDate from '../../../utils/dateStrToDate'; import dateStrToDate from '../../../utils/dateStrToDate';
import getMapStateToPropsForEditor from '../shared/editorFunctions/getMapStateToPropsForEditor';
import getMapDispatchToPropsForEditor from '../shared/editorFunctions/getMapDispatchToPropsForEditor';
import { import {
universitiesSemestersDatesElSaveData, universitiesSemestersDatesElSaveData,
universitiesSemestersDatesElSavingHasError universitiesSemestersDatesElSavingHasError
...@@ -30,7 +33,7 @@ class UniversitySemestersDatesEditor extends Editor { ...@@ -30,7 +33,7 @@ class UniversitySemestersDatesEditor extends Editor {
let messages = Array(); let messages = Array();
const formData = this.getDataFromFields(); const formData = this.getDataFromFields();
const { autumn_begin, autumn_end, spring_begin, spring_end } = formData; const { autumn_begin, autumn_end, spring_begin, spring_end } = formData;
if (onlyOneIsNull(autumn_begin, autumn_end)) { if (onlyOneIsNull(autumn_begin, autumn_end)) {
messages.push("Si une date est saisie pour le semestre d'automne, l'autre doit l'être aussi."); messages.push("Si une date est saisie pour le semestre d'automne, l'autre doit l'être aussi.");
} }
...@@ -91,36 +94,15 @@ class UniversitySemestersDatesEditor extends Editor { ...@@ -91,36 +94,15 @@ class UniversitySemestersDatesEditor extends Editor {
} }
} }
UniversitySemestersDatesEditor.propTypes = { UniversitySemestersDatesEditor.propTypes = {
modelData: PropTypes.object.isRequired, modelData: PropTypes.object.isRequired,
}; };
const mapStateToProps = (state) => {
let lastUpdateTime = null;
const tmp = state.universitiesSemestersDatesEl.fetched;
if (tmp.fetchedAt) {
lastUpdateTime = tmp.data.updated_on;
}
return {
savingHasError: state.universitiesSemestersDatesEl.savingHasError,
lastSaveTime: state.universitiesSemestersDatesEl.savedAt,
lastUpdateTime,
};
};
const mapDispatchToProps = (dispatch) => {
return {
saveData: (data) => dispatch(universitiesSemestersDatesElSaveData(data)),
clearSaveError: () => dispatch(universitiesSemestersDatesElSavingHasError(false))
};
};
export default compose( export default compose(
withStyles(styles, { withTheme: true }), withStyles(styles, { withTheme: true }),
connect(mapStateToProps, mapDispatchToProps) connect(
getMapStateToPropsForEditor('universitiesSemestersDatesEl'),
getMapDispatchToPropsForEditor(universitiesSemestersDatesElSaveData, universitiesSemestersDatesElSavingHasError)
)
)(UniversitySemestersDatesEditor); )(UniversitySemestersDatesEditor);
\ No newline at end of file
...@@ -163,7 +163,6 @@ class Editor extends MyComponent { ...@@ -163,7 +163,6 @@ class Editor extends MyComponent {
if (this.state.lastSaveTime < this.props.lastSaveTime) { if (this.state.lastSaveTime < this.props.lastSaveTime) {
//saving data was successfull //saving data was successfull
console.log("state", this.state.lastSaveTime, "props", this.props.lastSaveTime)
// We check if data was moderated // We check if data was moderated
let message = "Les données ont été enregistrées avec succès !"; let message = "Les données ont été enregistrées avec succès !";
let lastUpdateTime = this.state.lastUpdateTime; let lastUpdateTime = this.state.lastUpdateTime;
......
export default function getMapDispatchToPropsForEditor(saveDataAction, savingHasErrorAction) {
return (dispatch) => {
return {
saveData: (data) => dispatch(saveDataAction(data)),
clearSaveError: () => dispatch(savingHasErrorAction(false))
};
}
}
\ No newline at end of file
export default function getMapStateToPropsForEditor(elKey) {
return (state) => {
let lastUpdateTime = null;
const tmp = state[elKey].fetched;
if (tmp.fetchedAt) {
lastUpdateTime = tmp.data.updated_on;
}
return {
savingHasError: state[elKey].savingHasError,
lastSaveTime: state[elKey].savedAt,
lastUpdateTime,
};
};
}
\ No newline at end of file
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