35 lines
793 B
React
Raw Normal View History

2022-08-25 16:29:26 +03:00
import useSWR from "swr";
import Widget from "../widget";
import Block from "../block";
import { formatApiUrl } from "utils/api-helpers";
2022-08-25 16:29:26 +03:00
export default function Ombi({ service }) {
const config = service.widget;
const { data: statsData, error: statsError } = useSWR(formatApiUrl(config, `Request/count`));
2022-08-25 16:29:26 +03:00
if (statsError) {
return <Widget error="Ombi API Error" />;
}
if (!statsData) {
return (
<Widget>
<Block label="Pending" />
<Block label="Approved" />
<Block label="Available" />
</Widget>
);
}
return (
<Widget>
<Block label="Pending" value={statsData.pending} />
<Block label="Approved" value={statsData.approved} />
<Block label="Available" value={statsData.available} />
</Widget>
);
}