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/useExecutiveSummary/useExecutiveSummary.ts
andreas-unleash ec6c439c09
feat: updates per environment type chart (#6449)
Creates the updates per environment type chart.
(forgive the sample data)

Closes #
[1-2034](https://linear.app/unleash/issue/1-2034/widget-updates-per-environment-type-frontend)

<img width="1385" alt="Screenshot 2024-03-06 at 16 52 18"
src="https://github.com/Unleash/unleash/assets/104830839/b05479f8-de8b-4de7-98a3-a1285737db0d">

---------

Signed-off-by: andreas-unleash <andreas@getunleash.ai>
2024-03-07 11:00:18 +02:00

52 lines
1.5 KiB
TypeScript

import useSWR, { mutate, SWRConfiguration } from 'swr';
import { useCallback } from 'react';
import { formatApiPath } from 'utils/formatPath';
import handleErrorResponses from '../httpErrorResponseHandler';
import { ExecutiveSummarySchema } from 'openapi';
interface IUseExecutiveDashboardDataOutput {
executiveDashboardData: ExecutiveSummarySchema;
refetchExecutiveDashboard: () => void;
loading: boolean;
error?: Error;
}
export const useExecutiveDashboard = (
options?: SWRConfiguration,
): IUseExecutiveDashboardDataOutput => {
const path = formatApiPath('api/admin/dashboard/executive');
const { data, error } = useSWR<ExecutiveSummarySchema>(
path,
fetchExecutiveDashboard,
options,
);
const refetchExecutiveDashboard = useCallback(() => {
mutate(path).catch(console.warn);
}, [path]);
return {
executiveDashboardData: data || {
users: { total: 0, inactive: 0, active: 0 },
flags: { total: 0 },
userTrends: [],
flagTrends: [],
projectFlagTrends: [],
metricsSummaryTrends: [],
environmentTypeTrends: [],
},
refetchExecutiveDashboard,
loading: !error && !data,
error,
};
};
const fetchExecutiveDashboard = (
path: string,
): Promise<ExecutiveSummarySchema> => {
return fetch(path)
.then(handleErrorResponses('Executive Dashboard Data'))
.then((res) => res.json());
};