2020-02-27 21:36:07 +01:00
|
|
|
import { connect } from 'react-redux';
|
|
|
|
import ContextComponent from './form-context-component';
|
|
|
|
import { updateContextField, validateName } from './../../store/context/actions';
|
|
|
|
|
|
|
|
const mapStateToProps = (state, props) => {
|
|
|
|
const contextFieldBase = { name: '', description: '', legalValues: [] };
|
|
|
|
const field = state.context.toJS().find(n => n.name === props.contextFieldName);
|
|
|
|
const contextField = Object.assign(contextFieldBase, field);
|
2021-02-24 11:03:18 +01:00
|
|
|
if (!field) {
|
|
|
|
contextField.initial = true;
|
|
|
|
}
|
2020-02-27 21:36:07 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
contextField,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => ({
|
|
|
|
validateName,
|
|
|
|
submit: contextField => updateContextField(contextField)(dispatch),
|
|
|
|
editMode: true,
|
|
|
|
});
|
|
|
|
|
2020-04-18 22:06:49 +02:00
|
|
|
const FormAddContainer = connect(mapStateToProps, mapDispatchToProps)(ContextComponent);
|
2020-02-27 21:36:07 +01:00
|
|
|
|
|
|
|
export default FormAddContainer;
|