mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-08 01:15:49 +02:00
This switches to using conditional SWR to fetch project details only when you provide a project. This fixes an issue where we'd make requests for `api/admin/personal-dashboard/undefined` (which will be a 404 in the future).
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { formatApiPath } from 'utils/formatPath';
|
|
import handleErrorResponses from '../httpErrorResponseHandler';
|
|
import type { PersonalDashboardProjectDetailsSchema } from 'openapi';
|
|
import { useConditionalSWR } from '../useConditionalSWR/useConditionalSWR';
|
|
|
|
export interface IPersonalDashboardProjectDetailsOutput {
|
|
personalDashboardProjectDetails?: PersonalDashboardProjectDetailsSchema;
|
|
refetch: () => void;
|
|
loading: boolean;
|
|
error?: Error;
|
|
}
|
|
|
|
export const usePersonalDashboardProjectDetails = (
|
|
project: string,
|
|
): IPersonalDashboardProjectDetailsOutput => {
|
|
const { data, error, mutate } = useConditionalSWR(
|
|
Boolean(project),
|
|
{
|
|
latestEvents: [],
|
|
onboardingStatus: {
|
|
status: 'onboarding-started',
|
|
},
|
|
owners: [],
|
|
roles: [],
|
|
},
|
|
formatApiPath(`api/admin/personal-dashboard/${project}`),
|
|
fetcher,
|
|
);
|
|
|
|
return {
|
|
personalDashboardProjectDetails: data,
|
|
loading: !error && !data,
|
|
refetch: () => mutate(),
|
|
error,
|
|
};
|
|
};
|
|
|
|
const fetcher = (path: string) => {
|
|
return fetch(path)
|
|
.then(handleErrorResponses('Personal Dashboard Project Details'))
|
|
.then((res) => res.json());
|
|
};
|