Feature: crowdsec widget (#3197)

This commit is contained in:
shamoon
2024-03-28 15:39:40 -05:00
committed by GitHub
parent def9b27006
commit d4c0e482d3
8 changed files with 169 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import { useTranslation } from "next-i18next";
import Container from "components/services/widget/container";
import Block from "components/services/widget/block";
import useWidgetAPI from "utils/proxy/use-widget-api";
export default function Component({ service }) {
const { t } = useTranslation();
const { widget } = service;
const { data: alerts, error: alertsError } = useWidgetAPI(widget, "alerts");
const { data: bans, error: bansError } = useWidgetAPI(widget, "bans");
if (alertsError || bansError) {
return <Container service={service} error={alertsError ?? bansError} />;
}
if (!alerts || !bans) {
return (
<Container service={service}>
<Block label="crowdsec.alerts" />
<Block label="crowdsec.bans" />
</Container>
);
}
return (
<Container service={service}>
<Block label="crowdsec.alerts" value={t("common.number", { value: alerts.length })} />
<Block label="crowdsec.bans" value={t("common.number", { value: bans.length })} />
</Container>
);
}