diff --git a/frontend/src/components/university/editors/UniversityGeneralEditor.js b/frontend/src/components/university/editors/UniversityGeneralEditor.js index 35cf956a67302dc7f167b66a3d0cea73d639b9f5..e12dd3064bb5d3842d9000d3e8f58c555a941160 100644 --- a/frontend/src/components/university/editors/UniversityGeneralEditor.js +++ b/frontend/src/components/university/editors/UniversityGeneralEditor.js @@ -9,6 +9,9 @@ import editorStyle from '../shared/editorStyle'; import TextField from '../shared/fields/TextField'; +import getMapStateToPropsForEditor from '../shared/editorFunctions/getMapStateToPropsForEditor'; +import getMapDispatchToPropsForEditor from '../shared/editorFunctions/getMapDispatchToPropsForEditor'; + import { universitiesElSaveData, universitiesElSavingHasError @@ -57,35 +60,15 @@ class UniversityGeneral extends Editor { } - UniversityGeneral.propTypes = { 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( withStyles(styles, { withTheme: true }), - connect(mapStateToProps, mapDispatchToProps) + connect( + getMapStateToPropsForEditor('universitiesEl'), + getMapDispatchToPropsForEditor(universitiesElSaveData, universitiesElSavingHasError) + ) )(UniversityGeneral); \ No newline at end of file diff --git a/frontend/src/components/university/editors/UniversitySemestersDatesEditor.js b/frontend/src/components/university/editors/UniversitySemestersDatesEditor.js index 1998a1d56af5b46f9607855e93e4775620c155d8..e38958bd6b343ab7555684f5c9d49c52132c142f 100644 --- a/frontend/src/components/university/editors/UniversitySemestersDatesEditor.js +++ b/frontend/src/components/university/editors/UniversitySemestersDatesEditor.js @@ -12,6 +12,9 @@ import MarkdownField from '../shared/fields/MarkdownField'; import dateStrToDate from '../../../utils/dateStrToDate'; +import getMapStateToPropsForEditor from '../shared/editorFunctions/getMapStateToPropsForEditor'; +import getMapDispatchToPropsForEditor from '../shared/editorFunctions/getMapDispatchToPropsForEditor'; + import { universitiesSemestersDatesElSaveData, universitiesSemestersDatesElSavingHasError @@ -30,7 +33,7 @@ class UniversitySemestersDatesEditor extends Editor { let messages = Array(); const formData = this.getDataFromFields(); const { autumn_begin, autumn_end, spring_begin, spring_end } = formData; - + if (onlyOneIsNull(autumn_begin, autumn_end)) { 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 { } } - - UniversitySemestersDatesEditor.propTypes = { 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( withStyles(styles, { withTheme: true }), - connect(mapStateToProps, mapDispatchToProps) + connect( + getMapStateToPropsForEditor('universitiesSemestersDatesEl'), + getMapDispatchToPropsForEditor(universitiesSemestersDatesElSaveData, universitiesSemestersDatesElSavingHasError) + ) )(UniversitySemestersDatesEditor); \ No newline at end of file diff --git a/frontend/src/components/university/shared/Editor.js b/frontend/src/components/university/shared/Editor.js index 29c61ce0bee36ca305b1ee4157cae1afab89e13c..0f7a43cbb33589d789972a39ce7671ff5c353541 100644 --- a/frontend/src/components/university/shared/Editor.js +++ b/frontend/src/components/university/shared/Editor.js @@ -163,7 +163,6 @@ class Editor extends MyComponent { if (this.state.lastSaveTime < this.props.lastSaveTime) { //saving data was successfull - console.log("state", this.state.lastSaveTime, "props", this.props.lastSaveTime) // We check if data was moderated let message = "Les données ont été enregistrées avec succès !"; let lastUpdateTime = this.state.lastUpdateTime; diff --git a/frontend/src/components/university/shared/editorFunctions/getMapDispatchToPropsForEditor.js b/frontend/src/components/university/shared/editorFunctions/getMapDispatchToPropsForEditor.js new file mode 100644 index 0000000000000000000000000000000000000000..0c80439765a86138ab5ec2a9b75606fb9b899e25 --- /dev/null +++ b/frontend/src/components/university/shared/editorFunctions/getMapDispatchToPropsForEditor.js @@ -0,0 +1,8 @@ +export default function getMapDispatchToPropsForEditor(saveDataAction, savingHasErrorAction) { + return (dispatch) => { + return { + saveData: (data) => dispatch(saveDataAction(data)), + clearSaveError: () => dispatch(savingHasErrorAction(false)) + }; + } +} \ No newline at end of file diff --git a/frontend/src/components/university/shared/editorFunctions/getMapStateToPropsForEditor.js b/frontend/src/components/university/shared/editorFunctions/getMapStateToPropsForEditor.js new file mode 100644 index 0000000000000000000000000000000000000000..c03c9a22923424b3e7630358ddb485164212d535 --- /dev/null +++ b/frontend/src/components/university/shared/editorFunctions/getMapStateToPropsForEditor.js @@ -0,0 +1,15 @@ +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