72 lines
2.4 KiB
JavaScript
Raw Normal View History

2017-07-18 15:53:56 +02:00
/**
*
* EditForm
*
*/
2017-09-27 17:13:15 +02:00
import React from 'react';
import PropTypes from 'prop-types';
2017-07-18 15:53:56 +02:00
import { map } from 'lodash';
2017-08-07 15:23:25 +02:00
import { FormattedMessage } from 'react-intl';
import Button from 'components/Button';
2017-07-18 15:53:56 +02:00
import EditFormSection from 'components/EditFormSection';
import styles from './styles.scss';
class EditForm extends React.Component { // eslint-disable-line react/prefer-stateless-function
render() {
const buttonStyle = this.props.showLoader ? { display: 'none' } : {};
2017-07-18 15:53:56 +02:00
return (
<div className={styles.editForm}>
2017-08-11 10:48:50 +02:00
<form onSubmit={this.props.handleSubmit} autoComplete="nope">
2017-08-02 15:52:44 +02:00
<div className={styles.formContainer}>
{map(this.props.sections, (section, key) => {
let line;
// display hr only if next section
if (key + 1 < this.props.sections.length) {
line = <hr />;
}
return (
<div key={key} className={styles.sectionContainer}>
2017-08-02 15:52:44 +02:00
<EditFormSection
section={section}
values={this.props.values}
handleChange={this.props.handleChange}
cancelAction={this.props.cancelAction}
2017-08-10 17:11:28 +02:00
formErrors={this.props.formErrors}
2017-08-02 15:52:44 +02:00
/>
{line}
</div>
)
})}
</div>
<div className={styles.buttonContainer}>
<FormattedMessage id="settings-manager.form.button.cancel">
2017-08-07 15:23:25 +02:00
{(message) => (
<Button type="button" label={message} buttonSize={"buttonMd"} buttonBackground={"secondary"} onClick={this.props.handleCancel} style={buttonStyle} />
2017-08-07 15:23:25 +02:00
)}
</FormattedMessage>
<FormattedMessage id="settings-manager.form.button.save">
2017-08-07 15:23:25 +02:00
{(message) => (
<Button type="submit" loader={this.props.showLoader} label={message} buttonSize={"buttonLg"} buttonBackground={"primary"} onClick={this.props.handleSubmit} />
2017-08-07 15:23:25 +02:00
)}
</FormattedMessage>
2017-08-02 15:52:44 +02:00
</div>
</form>
2017-07-18 15:53:56 +02:00
</div>
);
}
}
EditForm.propTypes = {
cancelAction: PropTypes.bool,
formErrors: PropTypes.array,
handleCancel: PropTypes.func,
handleChange: PropTypes.func,
handleSubmit: PropTypes.func,
sections: PropTypes.array,
showLoader: PropTypes.bool,
values: PropTypes.object,
2017-07-18 18:06:15 +02:00
};
2017-07-18 15:53:56 +02:00
export default EditForm;