import classNames from "classnames"; import { useTranslation } from "next-i18next/pages"; import { TbApi } from "react-icons/tb"; import useSWR from "swr"; import Container from "../widget/container"; import Error from "../widget/error"; import Raw from "../widget/raw"; import WidgetLabel from "../widget/widget_label"; import ResolvedIcon from "components/resolvedicon"; import { formatValue, getValue } from "widgets/customapi/utils"; export default function CustomApi({ options }) { const { t } = useTranslation(); const { index, icon, label, mappings = [], refreshInterval = 10000 } = options; const { data, error } = useSWR(`/api/widgets/customapi?${new URLSearchParams({ index }).toString()}`, { refreshInterval: Math.max(1000, refreshInterval), }); if (error || (data?.error && !mappings.some((mapping) => mapping.field === "error"))) { return ; } return (
{icon ? ( ) : ( )}
{mappings.map((mapping) => (
{mapping.label} {data ? formatValue(t, mapping, getValue(mapping.field, data)) : "-"}
))}
{label && }
); }