homepage/src/widgets/npm/component.jsx

40 lines
1.1 KiB
React
Raw Normal View History

2022-09-25 19:43:00 +03:00
import { useTranslation } from "next-i18next";
2022-09-02 12:13:15 +02:00
2022-09-26 15:25:10 +03:00
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
2022-09-27 22:59:14 +03:00
import useWidgetAPI from "utils/proxy/use-widget-api";
2022-09-26 02:23:02 +03:00
export default function Component({ service }) {
2022-09-08 11:48:16 +03:00
const { t } = useTranslation();
2022-09-27 22:59:14 +03:00
const { widget } = service;
2022-09-02 12:13:15 +02:00
2022-09-27 22:59:14 +03:00
const { data: infoData, error: infoError } = useWidgetAPI(widget, "nginx/proxy-hosts");
2022-09-02 12:13:15 +02:00
if (infoError) {
2022-09-26 15:25:10 +03:00
return <Container error={t("widget.api_error")} />;
2022-09-02 12:13:15 +02:00
}
if (!infoData) {
return (
<Container service={service}>
<Block label="npm.enabled" />
<Block label="npm.disabled" />
<Block label="npm.total" />
2022-09-26 15:25:10 +03:00
</Container>
2022-09-02 12:13:15 +02:00
);
}
const enabled = infoData.filter((c) => c.enabled === 1).length;
const disabled = infoData.filter((c) => c.enabled === 0).length;
const total = infoData.length;
return (
<Container service={service}>
<Block label="npm.enabled" value={enabled} />
<Block label="npm.disabled" value={disabled} />
<Block label="npm.total" value={total} />
2022-09-26 15:25:10 +03:00
</Container>
2022-09-02 12:13:15 +02:00
);
}