1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-10-13 11:17:26 +02:00
unleash.unleash/frontend/src/hooks/api/getters/useInstanceStats/useInstanceStats.ts
Christopher Kolstad 53354224fc
chore: Bump biome and configure husky (#6589)
Upgrades biome to 1.6.1, and updates husky pre-commit hook.

Most changes here are making type imports explicit.
2024-03-18 13:58:05 +01:00

36 lines
947 B
TypeScript

import useSWR from 'swr';
import { useMemo } from 'react';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import type { InstanceAdminStatsSchema } from 'openapi';
export interface IInstanceStatsResponse {
stats?: InstanceAdminStatsSchema;
refetchGroup: () => void;
loading: boolean;
error?: Error;
}
export const useInstanceStats = (): IInstanceStatsResponse => {
const { data, error, mutate } = useSWR(
formatApiPath(`api/admin/instance-admin/statistics`),
fetcher,
);
return useMemo(
() => ({
stats: data,
loading: !error && !data,
refetchGroup: () => mutate(),
error,
}),
[data, error, mutate],
);
};
const fetcher = (path: string) => {
return fetch(path)
.then(handleErrorResponses('Instance Stats'))
.then((res) => res.json());
};