mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-03 01:18:43 +02:00
42 lines
1.1 KiB
JavaScript
42 lines
1.1 KiB
JavaScript
import { connect } from 'react-redux';
|
|
|
|
import { createFeatureToggles } from '../../store/feature-actions';
|
|
import AddComponent from './add-component';
|
|
import { createMapper, createActions } from '../input-helpers';
|
|
|
|
const ID = 'add-feature-toggle';
|
|
const mapStateToProps = createMapper({ id: ID });
|
|
const prepare = (methods, dispatch) => {
|
|
methods.onSubmit = (input) => (
|
|
(e) => {
|
|
e.preventDefault();
|
|
// TODO: should add error handling
|
|
createFeatureToggles(input)(dispatch)
|
|
.then(() => methods.clear())
|
|
.then(() => window.history.back());
|
|
}
|
|
);
|
|
|
|
methods.onCancel = () => {
|
|
debugger;
|
|
window.history.back();
|
|
};
|
|
|
|
methods.addStrategy = (v) => {
|
|
methods.pushToList('strategies', v);
|
|
};
|
|
|
|
methods.updateStrategy = (v, n) => {
|
|
methods.updateInList('strategies', v, n);
|
|
};
|
|
|
|
methods.removeStrategy = (v) => {
|
|
methods.removeFromList('strategies', v);
|
|
};
|
|
|
|
return methods;
|
|
};
|
|
const actions = createActions({ id: ID, prepare });
|
|
|
|
export default connect(mapStateToProps, actions)(AddComponent);
|