Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Rex Dri
Rex Dri
Commits
5689754f
Commit
5689754f
authored
Sep 14, 2018
by
Florent Chehab
Browse files
Better generalization
parent
6298e660
Pipeline
#27348
passed with stages
in 2 minutes and 38 seconds
Changes
5
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
frontend/src/components/university/editors/UniversityGeneralEditor.js
View file @
5689754f
...
...
@@ -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
frontend/src/components/university/editors/UniversitySemestersDatesEditor.js
View file @
5689754f
...
...
@@ -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
frontend/src/components/university/shared/Editor.js
View file @
5689754f
...
...
@@ -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
;
...
...
frontend/src/components/university/shared/editorFunctions/getMapDispatchToPropsForEditor.js
0 → 100644
View file @
5689754f
export
default
function
getMapDispatchToPropsForEditor
(
saveDataAction
,
savingHasErrorAction
)
{
return
(
dispatch
)
=>
{
return
{
saveData
:
(
data
)
=>
dispatch
(
saveDataAction
(
data
)),
clearSaveError
:
()
=>
dispatch
(
savingHasErrorAction
(
false
))
};
}
}
\ No newline at end of file
frontend/src/components/university/shared/editorFunctions/getMapStateToPropsForEditor.js
0 → 100644
View file @
5689754f
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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment