import { BiError, BiWifi, BiCheckCircle, BiXCircle, BiNetworkChart } from "react-icons/bi"; import { MdSettingsEthernet } from "react-icons/md"; import { useTranslation } from "next-i18next"; import { SiUbiquiti } from "react-icons/si"; import Error from "../widget/error"; import Container from "../widget/container"; import Raw from "../widget/raw"; import WidgetIcon from "../widget/widget_icon"; import PrimaryText from "../widget/primary_text"; import useWidgetAPI from "utils/proxy/use-widget-api"; export default function Widget({ options }) { const { t } = useTranslation(); // eslint-disable-next-line no-param-reassign options.type = "unifi_console"; const { data: statsData, error: statsError } = useWidgetAPI(options, "stat/sites", { index: options.index }); if (statsError) { return } const defaultSite = options.site ? statsData?.data.find(s => s.desc === options.site) : statsData?.data?.find(s => s.name === "default"); if (!defaultSite) { return {t("unifi.wait")} ; } const wan = defaultSite.health.find(h => h.subsystem === "wan"); const lan = defaultSite.health.find(h => h.subsystem === "lan"); const wlan = defaultSite.health.find(h => h.subsystem === "wlan"); [wan, lan, wlan].forEach(s => { s.up = s.status === "ok" // eslint-disable-line no-param-reassign s.show = s.status !== "unknown" // eslint-disable-line no-param-reassign }); const name = wan.gw_name ?? defaultSite.desc; const uptime = wan["gw_system-stats"] ? wan["gw_system-stats"].uptime : null; const dataEmpty = !(wan.show || lan.show || wlan.show || uptime); return
{name}
{dataEmpty &&
{t("unifi.empty_data")}
}
{uptime &&
{t("common.number", { value: uptime / 86400, maximumFractionDigits: 1, })}
{t("unifi.days")}
} {wan.show &&
{t("unifi.wan")}
{wan.up ? : }
} {!wan.show && !lan.show && wlan.show &&
{t("unifi.wlan")}
{wlan.up ? : }
} {!wan.show && !wlan.show && lan.show &&
{t("unifi.lan")}
{lan.up ? : }
}
{wlan.show &&
{t("common.number", { value: wlan.num_user, maximumFractionDigits: 0, })}
} {lan.show &&
{t("common.number", { value: lan.num_user, maximumFractionDigits: 0, })}
} {(wlan.show && !lan.show || !wlan.show && lan.show) &&
{t("common.number", { value: wlan.show ? wlan.num_adopted : lan.num_adopted, maximumFractionDigits: 0, })}
}
}