1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/feature/form-add-container.jsx
Ivar 993222a749 Fix input-store list bug.
Because we convert items from Immutable Object to js
we can not just look up items in a list property via
the object itself, as it is not the same.

The easy fix is to just use the index of the item in
the list, as we already know it anyway.

closes #5
2016-11-16 21:20:41 +01:00

48 lines
1.4 KiB
JavaScript

import { connect } from 'react-redux';
import { hashHistory } from 'react-router';
import { createFeatureToggles, validateName } from '../../store/feature-actions';
import { createMapper, createActions } from '../input-helpers';
import FormComponent from './form';
const ID = 'add-feature-toggle';
const mapStateToProps = createMapper({ id: ID });
const prepare = (methods, dispatch) => {
methods.onSubmit = (input) => (
(e) => {
e.preventDefault();
createFeatureToggles(input)(dispatch)
.then(() => methods.clear())
.then(() => hashHistory.push('/features'));
}
);
methods.onCancel = (evt) => {
evt.preventDefault();
hashHistory.push('/features');
};
methods.addStrategy = (v) => {
methods.pushToList('strategies', v);
};
methods.updateStrategy = (index, n) => {
methods.updateInList('strategies', index, n);
};
methods.removeStrategy = (index) => {
methods.removeFromList('strategies', index);
};
methods.validateName = (v) => {
const featureToggleName = v.target.value;
validateName(featureToggleName)
.then(() => methods.setValue('nameError', undefined))
.catch((err) => methods.setValue('nameError', err.message));
};
return methods;
};
const actions = createActions({ id: ID, prepare });
export default connect(mapStateToProps, actions)(FormComponent);