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 Controls from './Controls';
import renderField from './renderField';
import { R_IPV4 } from '../../helpers/constants';
const required = (value) => {
if (value || value === 0) {
return false;
}
return form_error_required;
};
const ipv4 = (value) => {
if (value && !new RegExp(R_IPV4).test(value)) {
return form_error_ip_format;
}
return false;
};
const port = (value) => {
if (value < 1 || value > 65535) {
return form_error_port;
}
return false;
};
const toNumber = value => value && parseInt(value, 10);
let Settings = (props) => {
const {
handleSubmit,
interfaceIp,
interfacePort,
dnsIp,
dnsPort,
invalid,
} = props;
const dnsAddress = dnsPort && dnsPort !== 53 ? `${dnsIp}:${dnsPort}` : dnsIp;
const interfaceAddress = interfacePort ? `http://${interfaceIp}:${interfacePort}` : `http://${interfaceIp}`;
return (
);
};
Settings.propTypes = {
handleSubmit: PropTypes.func.isRequired,
interfaceIp: PropTypes.string.isRequired,
dnsIp: PropTypes.string.isRequired,
interfacePort: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
dnsPort: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
invalid: PropTypes.bool.isRequired,
initialValues: PropTypes.object,
};
Settings.defaultProps = {
interfaceIp: '192.168.0.1',
interfacePort: 3000,
dnsIp: '192.168.0.1',
dnsPort: 53,
};
const selector = formValueSelector('install');
Settings = connect((state) => {
const interfaceIp = selector(state, 'web.ip');
const interfacePort = selector(state, 'web.port');
const dnsIp = selector(state, 'dns.ip');
const dnsPort = selector(state, 'dns.port');
return {
interfaceIp,
interfacePort,
dnsIp,
dnsPort,
};
})(Settings);
export default flow([
withNamespaces(),
reduxForm({
form: 'install',
destroyOnUnmount: false,
forceUnregisterOnUnmount: true,
}),
])(Settings);