2019-01-24 15:51:50 +00:00
|
|
|
import React from 'react';
|
2018-12-12 15:12:51 +00:00
|
|
|
import PropTypes from 'prop-types';
|
2018-12-29 15:43:17 +00:00
|
|
|
import { Field, reduxForm } from 'redux-form';
|
2019-01-24 15:51:50 +00:00
|
|
|
import { withNamespaces } from 'react-i18next';
|
2018-12-17 11:24:54 +00:00
|
|
|
import flow from 'lodash/flow';
|
|
|
|
|
2019-01-24 15:51:50 +00:00
|
|
|
import { renderField, required, ipv4, isPositive, toNumber } from '../../../helpers/form';
|
2018-12-12 15:12:51 +00:00
|
|
|
|
2018-12-29 15:43:17 +00:00
|
|
|
const Form = (props) => {
|
2018-12-12 15:12:51 +00:00
|
|
|
const {
|
2018-12-24 08:48:23 +00:00
|
|
|
t,
|
|
|
|
handleSubmit,
|
|
|
|
submitting,
|
2019-01-23 13:35:50 +00:00
|
|
|
invalid,
|
2019-01-23 14:22:04 +00:00
|
|
|
processingConfig,
|
2018-12-12 15:12:51 +00:00
|
|
|
} = props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<form onSubmit={handleSubmit}>
|
|
|
|
<div className="row">
|
|
|
|
<div className="col-lg-6">
|
2019-01-24 15:51:50 +00:00
|
|
|
<div className="form__group form__group--settings">
|
2018-12-17 11:24:54 +00:00
|
|
|
<label>{t('dhcp_form_gateway_input')}</label>
|
2018-12-12 15:12:51 +00:00
|
|
|
<Field
|
|
|
|
name="gateway_ip"
|
|
|
|
component={renderField}
|
|
|
|
type="text"
|
|
|
|
className="form-control"
|
2018-12-17 11:24:54 +00:00
|
|
|
placeholder={t('dhcp_form_gateway_input')}
|
2018-12-12 15:12:51 +00:00
|
|
|
validate={[ipv4, required]}
|
|
|
|
/>
|
|
|
|
</div>
|
2019-01-24 15:51:50 +00:00
|
|
|
<div className="form__group form__group--settings">
|
2018-12-17 11:24:54 +00:00
|
|
|
<label>{t('dhcp_form_subnet_input')}</label>
|
2018-12-12 15:12:51 +00:00
|
|
|
<Field
|
|
|
|
name="subnet_mask"
|
|
|
|
component={renderField}
|
|
|
|
type="text"
|
|
|
|
className="form-control"
|
2018-12-17 11:24:54 +00:00
|
|
|
placeholder={t('dhcp_form_subnet_input')}
|
2018-12-12 15:12:51 +00:00
|
|
|
validate={[ipv4, required]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="col-lg-6">
|
2019-01-24 15:51:50 +00:00
|
|
|
<div className="form__group form__group--settings">
|
2018-12-12 15:12:51 +00:00
|
|
|
<div className="row">
|
|
|
|
<div className="col-12">
|
2018-12-17 11:24:54 +00:00
|
|
|
<label>{t('dhcp_form_range_title')}</label>
|
2018-12-12 15:12:51 +00:00
|
|
|
</div>
|
|
|
|
<div className="col">
|
|
|
|
<Field
|
|
|
|
name="range_start"
|
|
|
|
component={renderField}
|
|
|
|
type="text"
|
|
|
|
className="form-control"
|
2018-12-17 11:24:54 +00:00
|
|
|
placeholder={t('dhcp_form_range_start')}
|
2018-12-12 15:12:51 +00:00
|
|
|
validate={[ipv4, required]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div className="col">
|
|
|
|
<Field
|
|
|
|
name="range_end"
|
|
|
|
component={renderField}
|
|
|
|
type="text"
|
|
|
|
className="form-control"
|
2018-12-17 11:24:54 +00:00
|
|
|
placeholder={t('dhcp_form_range_end')}
|
2018-12-12 15:12:51 +00:00
|
|
|
validate={[ipv4, required]}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2019-01-24 15:51:50 +00:00
|
|
|
<div className="form__group form__group--settings">
|
2018-12-17 11:24:54 +00:00
|
|
|
<label>{t('dhcp_form_lease_title')}</label>
|
2018-12-12 15:12:51 +00:00
|
|
|
<Field
|
|
|
|
name="lease_duration"
|
|
|
|
component={renderField}
|
|
|
|
type="number"
|
|
|
|
className="form-control"
|
2018-12-17 11:24:54 +00:00
|
|
|
placeholder={t('dhcp_form_lease_input')}
|
2018-12-13 12:26:47 +00:00
|
|
|
validate={[required, isPositive]}
|
|
|
|
normalize={toNumber}
|
2018-12-12 15:12:51 +00:00
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<button
|
|
|
|
type="submit"
|
2019-01-18 17:17:48 +00:00
|
|
|
className="btn btn-success btn-standard"
|
2019-01-23 14:22:04 +00:00
|
|
|
disabled={submitting || invalid || processingConfig}
|
2018-12-12 15:12:51 +00:00
|
|
|
>
|
2018-12-17 11:24:54 +00:00
|
|
|
{t('save_config')}
|
2018-12-12 15:12:51 +00:00
|
|
|
</button>
|
|
|
|
</form>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
Form.propTypes = {
|
|
|
|
handleSubmit: PropTypes.func,
|
|
|
|
submitting: PropTypes.bool,
|
2019-01-23 13:35:50 +00:00
|
|
|
invalid: PropTypes.bool,
|
2018-12-24 08:48:23 +00:00
|
|
|
interfaces: PropTypes.object,
|
2018-12-28 16:48:02 +00:00
|
|
|
initialValues: PropTypes.object,
|
2019-01-23 14:22:04 +00:00
|
|
|
processingConfig: PropTypes.bool,
|
2018-12-17 11:24:54 +00:00
|
|
|
t: PropTypes.func,
|
2018-12-12 15:12:51 +00:00
|
|
|
};
|
|
|
|
|
2018-12-17 11:24:54 +00:00
|
|
|
export default flow([
|
|
|
|
withNamespaces(),
|
|
|
|
reduxForm({ form: 'dhcpForm' }),
|
|
|
|
])(Form);
|