import React, { useEffect } from 'react'; import { addActiveElement } from '../../../actions/MainNavigation/mainNavigationActions'; import { useSelector, useDispatch } from "react-redux"; import { Link } from "react-router-dom"; import './Menu.scss'; const className = height => { if (height === 35) { return "menu-stat shadow"; } else { return "menu-stat"; } } const style = ({ menuHeight, mobile }) => { if (mobile) { return; } if (document.documentElement.clientWidth > 900) { return menuHeight } else { return 45; } } const Menu = props => { const { activeElement, focusedElement } = useSelector(state => state.mainNavigation); const { i18n, panel, userName } = useSelector(state => state.session); const { session } = useSelector(state => state.userSession); const { user } = useSelector(state => state.menuCounters); const dispatch = useDispatch(); useEffect(() => { if (user.LANGUAGE) { localStorage.setItem("language", user.LANGUAGE); } }, [user]); const handleState = (tab, event) => { if (`${window.location.pathname}${window.location.search}` === tab) { return event.preventDefault(); } dispatch(addActiveElement(tab)); } const statClassName = activeName => { return `stat ${activeName === activeElement && 'l-active'} ${activeName === focusedElement && 'focus'}`; } const sizeFormatter = (bytes, decimals) => { if (!bytes) return null; if (bytes === "0") { return 0 b; } let k = 1024, dm = decimals <= 0 ? 0 : decimals || 2, sizes = ['b', 'kb', 'Mb', 'GB'], i = Math.floor(Math.log(bytes) / Math.log(k)); return ({parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} {sizes[i]}); } return (
handleState("/list/user/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.USER}

{ session.look && panel[session.look] ? (<>
{i18n.Disk}: {user.U_DISK} {panel[session.look]['U_DISK_MEASURE']}
{i18n.Bandwidth}: {user.U_BANDWIDTH} {panel[session.look]['U_BANDWIDTH_MEASURE']}
) : (<>
{i18n.users}: {user.U_USERS}
{i18n.spnd}: {user.SUSPENDED_USERS}
) }
{ panel[userName]['WEB_DOMAINS'] !== '0' && (
handleState("/list/web/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.WEB}

{i18n.domains}: {user.U_WEB_DOMAINS}
{i18n.aliases}: {user.U_WEB_ALIASES}
{i18n.spnd}: {user.SUSPENDED_WEB}
) } { panel[userName]['DNS_DOMAINS'] !== '0' && (
handleState("/list/dns/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.DNS}

{i18n.domains}: {user.U_DNS_DOMAINS}
{i18n.records}: {user.U_DNS_RECORDS}
{i18n.spnd}: {user.SUSPENDED_DNS}
) } { panel[userName]['MAIL_DOMAINS'] !== '0' && (
handleState("/list/mail/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.MAIL}

{i18n.domains}: {user.U_MAIL_DOMAINS}
{i18n.accounts}: {user.U_MAIL_ACCOUNTS}
{i18n.spnd}: {user.SUSPENDED_MAIL}
) } { panel[userName]['DATABASES'] !== '0' && (
handleState("/list/db/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.DB}

{i18n.databases}: {user.U_DATABASES}
{i18n.spnd}: {user.SUSPENDED_DB}
) } { panel[userName]['CRON_JOBS'] !== '0' && (
handleState("/list/cron/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.CRON}

{i18n.jobs}: {user.U_CRON_JOBS}
{i18n.spnd}: {user.SUSPENDED_CRON}
) } { panel[userName]['BACKUPS'] !== '0' && (
handleState("/list/backup/", event)} onKeyPress={event => event.preventDefault()}>

{i18n.BACKUP}

{i18n.backups}: {user.U_BACKUPS}
) }
); } export default Menu;