1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/frontend/src/hooks/api/getters/useFeaturesArchive/useFeaturesArchive.ts
2023-03-06 14:18:39 +00:00

41 lines
1.1 KiB
TypeScript

import useSWR from 'swr';
import { FeatureSchema, FeaturesSchema } from 'openapi';
import handleErrorResponses from '../httpErrorResponseHandler';
import { formatApiPath } from 'utils/formatPath';
export interface IUseFeaturesArchiveOutput {
archivedFeatures?: FeatureSchema[];
refetchArchived: () => void;
loading: boolean;
error?: Error;
}
const fetcher = (path: string) => {
return fetch(path)
.then(handleErrorResponses('Feature toggle archive'))
.then(res => res.json());
};
export const useFeaturesArchive = (
projectId?: string
): IUseFeaturesArchiveOutput => {
const { data, error, mutate, isLoading } = useSWR<FeaturesSchema>(
formatApiPath(
projectId
? `/api/admin/archive/features/${projectId}`
: 'api/admin/archive/features'
),
fetcher,
{
refreshInterval: 15 * 1000, // ms
}
);
return {
archivedFeatures: data?.features,
refetchArchived: mutate,
loading: isLoading,
error,
};
};