mirror of
https://github.com/Unleash/unleash.git
synced 2025-10-13 11:17:26 +02:00
Upgrades biome to 1.6.1, and updates husky pre-commit hook. Most changes here are making type imports explicit.
36 lines
947 B
TypeScript
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());
|
|
};
|