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 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 (
{t("widget.api_error")} -
); } const defaultSite = 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; return (
{name}
{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, })}
}
); }