1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-12 13:48:35 +02:00
unleash.unleash/frontend/src/hooks/api/getters/useCheckDependenciesExist/useCheckDependenciesExist.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

33 lines
883 B
TypeScript

import type { SWRConfiguration } from 'swr';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR';
export const useCheckDependenciesExist = (
project: string,
options: SWRConfiguration = {},
) => {
const path = formatApiPath(`/api/admin/projects/${project}/dependencies`);
const { data, error } = useConditionalSWR(
project,
false,
path,
fetcher,
options,
);
return {
dependenciesExist: data,
error,
loading: !error && !data,
};
};
const fetcher = async (path: string): Promise<boolean> => {
const res = await fetch(path).then(
handleErrorResponses('Dependencies exist check'),
);
const data = await res.json();
return data;
};