Closes #4698. Squashed commit of the following: commit 6be0caee58926f8cea1e10650fbde0c8d97d0dac Author: Ildar Kamalov <ik@adguard.com> Date: Fri Jul 8 13:41:50 2022 +0300 update translation commit e0370656d05e8463d73ea73568cae81187c6b2e3 Author: Ildar Kamalov <ik@adguard.com> Date: Fri Jul 8 13:40:54 2022 +0300 client: validate static lease ip commit 7f4d00f9f3a54dc93ce5d5c45e9c21745f6e39d1 Merge: 2ee7962677e5e27dAuthor: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Jul 8 13:20:15 2022 +0300 Merge branch 'master' into 4698-lease-with-gateway commit 2ee79626a1b0c7b113dbd22ba4ef6e85ea9913ec Merge: 471b96b83505ce87Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Jul 7 19:34:33 2022 +0300 Merge branch 'master' into 4698-lease-with-gateway commit 471b96b81da8920c1e71b7110050154f912677d2 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Jul 7 16:07:23 2022 +0300 dhcpd: imp docs commit 67dd6c76f7d2df4712a57281e0f40f2ee1a1efa2 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Jul 7 15:48:47 2022 +0300 dhcpd: restrict gateway ip for lease
117 lines
3.8 KiB
JavaScript
117 lines
3.8 KiB
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { Field, reduxForm } from 'redux-form';
|
|
import { Trans, useTranslation } from 'react-i18next';
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { renderInputField, normalizeMac } from '../../../../helpers/form';
|
|
import {
|
|
validateIpv4,
|
|
validateMac,
|
|
validateRequiredValue,
|
|
validateIpv4InCidr,
|
|
validateIpGateway,
|
|
} from '../../../../helpers/validators';
|
|
import { FORM_NAME } from '../../../../helpers/constants';
|
|
import { toggleLeaseModal } from '../../../../actions';
|
|
|
|
const Form = ({
|
|
handleSubmit,
|
|
reset,
|
|
pristine,
|
|
submitting,
|
|
processingAdding,
|
|
cidr,
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const dispatch = useDispatch();
|
|
|
|
const onClick = () => {
|
|
reset();
|
|
dispatch(toggleLeaseModal());
|
|
};
|
|
|
|
return (
|
|
<form onSubmit={handleSubmit}>
|
|
<div className="modal-body">
|
|
<div className="form__group">
|
|
<Field
|
|
id="mac"
|
|
name="mac"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('form_enter_mac')}
|
|
normalize={normalizeMac}
|
|
validate={[validateRequiredValue, validateMac]}
|
|
/>
|
|
</div>
|
|
<div className="form__group">
|
|
<Field
|
|
id="ip"
|
|
name="ip"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('form_enter_subnet_ip', { cidr })}
|
|
validate={[
|
|
validateRequiredValue,
|
|
validateIpv4,
|
|
validateIpv4InCidr,
|
|
validateIpGateway,
|
|
]}
|
|
/>
|
|
</div>
|
|
<div className="form__group">
|
|
<Field
|
|
id="hostname"
|
|
name="hostname"
|
|
component={renderInputField}
|
|
type="text"
|
|
className="form-control"
|
|
placeholder={t('form_enter_hostname')}
|
|
/>
|
|
</div>
|
|
</div>
|
|
|
|
<div className="modal-footer">
|
|
<div className="btn-list">
|
|
<button
|
|
type="button"
|
|
className="btn btn-secondary btn-standard"
|
|
disabled={submitting}
|
|
onClick={onClick}
|
|
>
|
|
<Trans>cancel_btn</Trans>
|
|
</button>
|
|
<button
|
|
type="submit"
|
|
className="btn btn-success btn-standard"
|
|
disabled={submitting || pristine || processingAdding}
|
|
>
|
|
<Trans>save_btn</Trans>
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</form>
|
|
);
|
|
};
|
|
|
|
Form.propTypes = {
|
|
initialValues: PropTypes.shape({
|
|
mac: PropTypes.string.isRequired,
|
|
ip: PropTypes.string.isRequired,
|
|
hostname: PropTypes.string.isRequired,
|
|
cidr: PropTypes.string.isRequired,
|
|
gatewayIp: PropTypes.string,
|
|
}),
|
|
pristine: PropTypes.bool.isRequired,
|
|
handleSubmit: PropTypes.func.isRequired,
|
|
reset: PropTypes.func.isRequired,
|
|
submitting: PropTypes.bool.isRequired,
|
|
processingAdding: PropTypes.bool.isRequired,
|
|
cidr: PropTypes.string.isRequired,
|
|
};
|
|
|
|
export default reduxForm({ form: FORM_NAME.LEASE })(Form);
|