2017-07-18 15:53:56 +02:00
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* EditForm
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-27 17:13:15 +02:00
|
|
|
import React from 'react';
|
2017-09-20 11:12:04 +02:00
|
|
|
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';
|
2017-07-19 10:49:23 +02:00
|
|
|
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() {
|
2017-09-30 14:42:52 +02:00
|
|
|
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 (
|
2017-08-08 15:35:37 +02:00
|
|
|
<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}
|
2017-08-04 15:23:21 +02:00
|
|
|
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}>
|
2017-08-17 11:07:52 +02:00
|
|
|
<FormattedMessage id="settings-manager.form.button.cancel">
|
2017-08-07 15:23:25 +02:00
|
|
|
{(message) => (
|
2017-09-30 14:42:52 +02:00
|
|
|
<Button type="button" label={message} buttonSize={"buttonMd"} buttonBackground={"secondary"} onClick={this.props.handleCancel} style={buttonStyle} />
|
2017-08-07 15:23:25 +02:00
|
|
|
)}
|
|
|
|
|
</FormattedMessage>
|
2017-08-17 11:07:52 +02:00
|
|
|
<FormattedMessage id="settings-manager.form.button.save">
|
2017-08-07 15:23:25 +02:00
|
|
|
{(message) => (
|
2017-09-30 14:42:52 +02:00
|
|
|
<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 = {
|
2017-09-26 10:32:48 +02:00
|
|
|
cancelAction: PropTypes.bool,
|
|
|
|
|
formErrors: PropTypes.array,
|
2017-09-26 11:47:13 +02:00
|
|
|
handleCancel: PropTypes.func,
|
|
|
|
|
handleChange: PropTypes.func,
|
|
|
|
|
handleSubmit: PropTypes.func,
|
|
|
|
|
sections: PropTypes.array,
|
2017-09-30 14:42:52 +02:00
|
|
|
showLoader: PropTypes.bool,
|
2017-09-26 11:47:13 +02:00
|
|
|
values: PropTypes.object,
|
2017-07-18 18:06:15 +02:00
|
|
|
};
|
2017-07-18 15:53:56 +02:00
|
|
|
|
|
|
|
|
export default EditForm;
|