import React, { useEffect, useState } from 'react';
import { addActiveElement, removeFocusedElement } from "../../../actions/MainNavigation/mainNavigationActions";
import AddItemLayout from '../../ControlPanel/AddItemLayout/AddItemLayout';
import { addWeb, getWebStats } from '../../../ControlPanelService/Web';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import AdvancedOptions from './AdvancedOptions/AdvancedOptions';
import { getIpList } from '../../../ControlPanelService/Ip';
import Toolbar from '../../MainNav/Toolbar/Toolbar';
import { useHistory } from 'react-router-dom';
import Spinner from '../../Spinner/Spinner';
import { useDispatch, useSelector } from 'react-redux';
import './AddWebDomain.scss';
import { Helmet } from 'react-helmet';
import { refreshCounters } from 'src/actions/MenuCounters/menuCounterActions';
import HtmlParser from 'react-html-parser';
const AddWebDomain = props => {
const { i18n } = useSelector(state => state.session);
const dispatch = useDispatch();
const token = localStorage.getItem("token");
const history = useHistory();
const [state, setState] = useState({
loading: false,
dnsSupport: true,
mailSupport: true,
showAdvancedOptions: false,
okMessage: '',
domain: '',
errorMessage: '',
webStats: [],
prefixI18N: '',
internetProtocols: []
});
useEffect(() => {
dispatch(addActiveElement('/list/web/'));
dispatch(removeFocusedElement());
setState({ ...state, loading: true });
Promise.all([getWebStats(), getIpList()])
.then(result => {
const [webStats, internetProtocols] = result;
let internetProtocolNames = getInternetProtocolNames(internetProtocols.data.data);
setState({
...state,
webStats: webStats.data.data,
internetProtocols: internetProtocolNames,
prefixI18N: webStats.data.prefixI18N,
loading: false
});
});
}, []);
const getInternetProtocolNames = internetProtocols => {
let result = [];
for (let i in internetProtocols) {
result.push(i);
}
return result;
}
const renderInternetProtocolsOptions = () => {
return state.internetProtocols.map(ip => );
}
const showAdvancedOption = () => {
setState({ ...state, showAdvancedOptions: !state.showAdvancedOptions });
}
const renderAdvancedOptions = () => {
if (state.showAdvancedOptions) {
return