1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00

feat: handle global impact metrics in frontend api hook

This commit is contained in:
Tymoteusz Czech 2025-09-05 12:19:52 +02:00
parent 82c79a8216
commit a3ae7f2bd2
No known key found for this signature in database
GPG Key ID: 133555230D88D75F

View File

@ -2,19 +2,26 @@ import { useCallback } from 'react';
import useAPI from '../useApi/useApi.js';
import type { CreateImpactMetricsConfigSchema } from 'openapi';
export const useImpactMetricsApi = ({
projectId,
featureName,
}: { projectId: string; featureName: string }) => {
type UseImpactMetricsApiParams =
| {
projectId: string;
featureName: string;
}
| undefined;
export const useImpactMetricsApi = (params: UseImpactMetricsApiParams) => {
const basePath = params
? `api/admin/projects/${params.projectId}/features/${params.featureName}/impact-metrics/config`
: `api/admin/impact-metrics/config`;
const { makeRequest, createRequest, errors, loading } = useAPI({
propagateErrors: true,
});
const createImpactMetric = useCallback(
async (config: CreateImpactMetricsConfigSchema) => {
const path = `api/admin/projects/${projectId}/features/${featureName}/impact-metrics/config`;
const req = createRequest(
path,
basePath,
{
method: 'POST',
body: JSON.stringify(config),
@ -29,9 +36,8 @@ export const useImpactMetricsApi = ({
const deleteImpactMetric = useCallback(
async (metricId: string) => {
const path = `api/admin/projects/${projectId}/features/${featureName}/impact-metrics/config/${metricId}`;
const req = createRequest(
path,
`${basePath}/${metricId}`,
{
method: 'DELETE',
},