mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-05 17:53:12 +02:00
feat: handle global impact metrics in frontend api hook (#10626)
This commit is contained in:
parent
82c79a8216
commit
ea4c0a0941
@ -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',
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user