39 lines
932 B
React
Raw Normal View History

2022-09-02 12:13:15 +02:00
import useSWR from "swr";
import Widget from "../widget";
import Block from "../block";
import { formatApiUrl } from "utils/api-helpers";
2022-09-02 12:13:15 +02:00
export default function Npm({ service }) {
const config = service.widget;
const { data: infoData, error: infoError } = useSWR(formatApiUrl(config, "nginx/proxy-hosts"));
2022-09-02 12:13:15 +02:00
if (infoError) {
return <Widget error="NGINX Proxy Manager API Error" />;
}
if (!infoData) {
return (
<Widget>
2022-09-03 12:40:15 +03:00
<Block label="Enabled" />
<Block label="Disabled" />
2022-09-02 12:13:15 +02:00
<Block label="Total" />
</Widget>
);
}
const enabled = infoData.filter((c) => c.enabled === 1).length;
const disabled = infoData.filter((c) => c.enabled === 0).length;
const total = infoData.length;
return (
<Widget>
<Block label="Enabled" value={enabled} />
<Block label="Disabled" value={disabled} />
<Block label="Total" value={total} />
</Widget>
);
}