import React from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { Field, reduxForm, formValueSelector } from 'redux-form';
import { Trans, withNamespaces } from 'react-i18next';
import flow from 'lodash/flow';
import { renderField, required, ipv4, isPositive, toNumber } from '../../../helpers/form';
const renderInterfaces = (interfaces => (
Object.keys(interfaces).map((item) => {
const option = interfaces[item];
const { name } = option;
const onlyIPv6 = option.ip_addresses.every(ip => ip.includes(':'));
let interfaceIP = option.ip_addresses[0];
if (!onlyIPv6) {
option.ip_addresses.forEach((ip) => {
if (!ip.includes(':')) {
interfaceIP = ip;
}
});
}
return (
);
})
));
const renderInterfaceValues = (interfaceValues => (
-
MTU:
{interfaceValues.mtu}
-
dhcp_hardware_address:
{interfaceValues.hardware_address}
-
dhcp_ip_addresses:
{
interfaceValues.ip_addresses
.map(ip => {ip})
}
));
let Form = (props) => {
const {
t,
handleSubmit,
submitting,
invalid,
enabled,
interfaces,
interfaceValue,
processingConfig,
processingInterfaces,
} = props;
return (
);
};
Form.propTypes = {
handleSubmit: PropTypes.func,
submitting: PropTypes.bool,
invalid: PropTypes.bool,
interfaces: PropTypes.object,
interfaceValue: PropTypes.string,
initialValues: PropTypes.object,
processingConfig: PropTypes.bool,
processingInterfaces: PropTypes.bool,
enabled: PropTypes.bool,
t: PropTypes.func,
};
const selector = formValueSelector('dhcpForm');
Form = connect((state) => {
const interfaceValue = selector(state, 'interface_name');
return {
interfaceValue,
};
})(Form);
export default flow([
withNamespaces(),
reduxForm({ form: 'dhcpForm' }),
])(Form);