Commit 7275e4f3 authored by Daniel Caillibaud's avatar Daniel Caillibaud

initialize pas utilisé viré

parent be73a7c2
......@@ -67,8 +67,7 @@ ResourceForm.propTypes = {
handleSubmit: PropTypes.func,
submitting: PropTypes.bool,
saveRessource: PropTypes.func,
pristine: PropTypes.bool,
initialize: PropTypes.func
pristine: PropTypes.bool
}
const validate = (values) => {
......@@ -76,12 +75,14 @@ const validate = (values) => {
const {type} = values
const {validate: typeValidate} = getEditor(type)
if (typeValidate) {
console.log(`pour le type ${type} on a un validate`)
typeValidate(values, errors)
}
console.log(`pour le type ${type} on retourne les erreurs de validation`, errors)
return errors
}
const onSubmit = (values, dispatch, {saveRessource, initialize}) => {
const onSubmit = (values, dispatch, {saveRessource}) => {
const {saveHook = identity} = getEditor(values.type)
return saveRessource(saveHook(values), (savedRessource) => {
......@@ -103,6 +104,13 @@ const onSubmit = (values, dispatch, {saveRessource, initialize}) => {
})
}
const propsAfterLoadHook = ({ressource}) => {
const {loadHook = identity} = getEditor(ressource.type)
return {
initialValues: loadHook(ressource)
}
}
const formDef = {
form: 'ressource',
validate,
......@@ -110,20 +118,13 @@ const formDef = {
onSubmitFail,
enableReinitialize: true
}
const formComponent = reduxForm(formDef)(ResourceForm)
export default ensureLogged(
resourceLoader(
aliasForker( // fork si on édite un alias
resourceSaver( // fournit saveRessource
withProps(({ressource}) => {
const {loadHook = identity} = getEditor(ressource.type)
return {
initialValues: loadHook(ressource)
}
})(
reduxForm(formDef)(ResourceForm)
)
withProps(propsAfterLoadHook)(formComponent)
)
)
)
......
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