import React, { Component } from 'react'; import { connect } from 'react-redux'; import PropTypes from 'prop-types'; import { Field, reduxForm, formValueSelector } from 'redux-form'; import { Trans, withTranslation } from 'react-i18next'; import flow from 'lodash/flow'; import Controls from './Controls'; import AddressList from './AddressList'; import { getInterfaceIp } from '../../helpers/helpers'; import { ALL_INTERFACES_IP, FORM_NAME, ADDRESS_IN_USE_TEXT, PORT_53_FAQ_LINK, STATUS_RESPONSE, STANDARD_DNS_PORT, STANDARD_WEB_PORT, } from '../../helpers/constants'; import { renderInputField, toNumber } from '../../helpers/form'; import { validateRequiredValue, validateInstallPort } from '../../helpers/validators'; const renderInterfaces = (interfaces) => Object.values(interfaces) .map((option) => { const { name, ip_addresses, flags, } = option; if (option && ip_addresses?.length > 0) { const ip = getInterfaceIp(option); const isDown = flags?.includes('down'); return ; } return null; }); class Settings extends Component { componentDidMount() { const { webIp, webPort, dnsIp, dnsPort, } = this.props; this.props.validateForm({ web: { ip: webIp, port: webPort, }, dns: { ip: dnsIp, port: dnsPort, }, }); } getStaticIpMessage = (staticIp) => { const { static: status, ip } = staticIp; switch (status) { case STATUS_RESPONSE.NO: { return <>
text]}> install_static_configure
; } case STATUS_RESPONSE.ERROR: { return
install_static_error
; } case STATUS_RESPONSE.YES: { return
install_static_ok
; } default: return null; } }; handleAutofix = (type) => { const { webIp, webPort, dnsIp, dnsPort, handleFix, } = this.props; const web = { ip: webIp, port: webPort, autofix: false, }; const dns = { ip: dnsIp, port: dnsPort, autofix: false, }; const set_static_ip = false; if (type === 'web') { web.autofix = true; } else { dns.autofix = true; } handleFix(web, dns, set_static_ip); }; handleStaticIp = (ip) => { const { webIp, webPort, dnsIp, dnsPort, handleFix, } = this.props; const web = { ip: webIp, port: webPort, autofix: false, }; const dns = { ip: dnsIp, port: dnsPort, autofix: false, }; const set_static_ip = true; if (window.confirm(this.props.t('confirm_static_ip', { ip }))) { handleFix(web, dns, set_static_ip); } }; render() { const { handleSubmit, handleChange, webIp, webPort, dnsIp, dnsPort, interfaces, invalid, config, t, } = this.props; const { status: webStatus, can_autofix: isWebFixAvailable, } = config.web; const { status: dnsStatus, can_autofix: isDnsFixAvailable, } = config.dns; const { staticIp } = config; return (
install_settings_title
{renderInterfaces(interfaces)}
{webStatus &&
{webStatus} {isWebFixAvailable && }
}
install_settings_interface_link
install_settings_dns
{renderInterfaces(interfaces)}
{dnsStatus && <>
{dnsStatus} {isDnsFixAvailable && }
{isDnsFixAvailable &&

autofix_warning_text

text]}> autofix_warning_list

autofix_warning_result

} } {dnsPort === STANDARD_DNS_PORT && !isDnsFixAvailable && dnsStatus.includes(ADDRESS_IN_USE_TEXT) && link]}> port_53_faq_link }
install_settings_dns_desc
static_ip
static_ip_desc
{this.getStaticIpMessage(staticIp)}
); } } Settings.propTypes = { handleSubmit: PropTypes.func.isRequired, handleChange: PropTypes.func, handleFix: PropTypes.func.isRequired, validateForm: PropTypes.func, webIp: PropTypes.string.isRequired, dnsIp: PropTypes.string.isRequired, config: PropTypes.object.isRequired, webPort: PropTypes.oneOfType([ PropTypes.string, PropTypes.number, ]), dnsPort: PropTypes.oneOfType([ PropTypes.string, PropTypes.number, ]), interfaces: PropTypes.object.isRequired, invalid: PropTypes.bool.isRequired, initialValues: PropTypes.object, t: PropTypes.func.isRequired, }; const selector = formValueSelector(FORM_NAME.INSTALL); const SettingsForm = connect((state) => { const webIp = selector(state, 'web.ip'); const webPort = selector(state, 'web.port'); const dnsIp = selector(state, 'dns.ip'); const dnsPort = selector(state, 'dns.port'); return { webIp, webPort, dnsIp, dnsPort, }; })(Settings); export default flow([ withTranslation(), reduxForm({ form: FORM_NAME.INSTALL, destroyOnUnmount: false, forceUnregisterOnUnmount: true, }), ])(SettingsForm);