mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			44 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| import { connect } from 'react-redux';
 | |
| import { hashHistory } from 'react-router';
 | |
| 
 | |
| 
 | |
| 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 = (evt) => {
 | |
|         evt.preventDefault();
 | |
|         hashHistory.push('/features');
 | |
|     };
 | |
| 
 | |
|     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);
 |