1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

Merge pull request #56 from Unleash/refactor-form-add-component-layout

refactor layout into a new form add component
This commit is contained in:
Vegard Sandvold 2017-01-28 16:46:34 +01:00 committed by GitHub
commit f73d2c6633
3 changed files with 71 additions and 54 deletions

View File

@ -0,0 +1,18 @@
import React, { PropTypes } from 'react';
import { Card, CardTitle } from 'react-mdl';
import FormComponent from './form';
import { styles as commonStyles } from '../common';
const FormAddComponent = ({ title, ...formProps }) => (
<Card className={commonStyles.fullwidth}>
<CardTitle style={{ paddingTop: '24px' }}>{title}</CardTitle>
<FormComponent {...formProps}/>
</Card>
);
FormAddComponent.propTypes = {
title: PropTypes.string,
};
export default FormAddComponent;

View File

@ -2,7 +2,7 @@ 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';
import FormAddComponent from './form-add-component';
const ID = 'add-feature-toggle';
const mapStateToProps = createMapper({
@ -66,4 +66,9 @@ const prepare = (methods, dispatch) => {
};
const actions = createActions({ id: ID, prepare });
export default connect(mapStateToProps, actions)(FormComponent);
const FormAddContainer = connect(
mapStateToProps,
actions
)(FormAddComponent);
export default FormAddContainer;

View File

@ -1,8 +1,8 @@
import React, { Component, PropTypes } from 'react';
import { Textfield, Switch, Grid, Cell } from 'react-mdl';
import { Textfield, Switch } from 'react-mdl';
import StrategiesSection from './strategies-section-container';
import { FormButtons, HeaderTitle } from '../../common';
import { FormButtons } from '../../common';
const trim = (value) => {
if (value && value.trim) {
@ -33,7 +33,6 @@ class AddFeatureToggleComponent extends Component {
onSubmit,
onCancel,
editmode = false,
title,
} = this.props;
const {
@ -45,57 +44,52 @@ class AddFeatureToggleComponent extends Component {
const configuredStrategies = input.strategies || [];
return (
<Grid className="mdl-color--white">
<Cell col={12}>
<form onSubmit={onSubmit(input)}>
{title && <HeaderTitle title={title} />}
<section>
<Textfield
floatingLabel
label="Name"
name="name"
disabled={editmode}
required
value={name}
error={nameError}
onBlur={(v) => validateName(v.target.value)}
onChange={(v) => setValue('name', trim(v.target.value))} />
<br />
<Textfield
floatingLabel
style={{ width: '100%' }}
rows={1}
label="Description"
required
value={description}
onChange={(v) => setValue('description', v.target.value)} />
{!editmode && <div>
<br />
<Switch
checked={enabled}
onChange={() => {
setValue('enabled', !enabled);
}}>Enabled</Switch>
<hr />
</div>}
</section>
<StrategiesSection
configuredStrategies={configuredStrategies}
addStrategy={addStrategy}
updateStrategy={updateStrategy}
moveStrategy={moveStrategy}
removeStrategy={removeStrategy} />
<form onSubmit={onSubmit(input)}>
<section style={{ padding: '16px' }}>
<Textfield
floatingLabel
label="Name"
name="name"
disabled={editmode}
required
value={name}
error={nameError}
onBlur={(v) => validateName(v.target.value)}
onChange={(v) => setValue('name', trim(v.target.value))} />
<br />
<Textfield
floatingLabel
style={{ width: '100%' }}
rows={1}
label="Description"
required
value={description}
onChange={(v) => setValue('description', v.target.value)} />
{!editmode && <div>
<br />
<FormButtons
submitText={editmode ? 'Update' : 'Create'}
onCancel={onCancel}
/>
</form>
</Cell>
</Grid>
<Switch
checked={enabled}
onChange={() => {
setValue('enabled', !enabled);
}}>Enabled</Switch>
<hr />
</div>}
<StrategiesSection
configuredStrategies={configuredStrategies}
addStrategy={addStrategy}
updateStrategy={updateStrategy}
moveStrategy={moveStrategy}
removeStrategy={removeStrategy} />
<br />
<FormButtons
submitText={editmode ? 'Update' : 'Create'}
onCancel={onCancel}
/>
</section>
</form>
);
}