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 useAPI from '../useApi/useApi.js';
|
||||||
import type { CreateImpactMetricsConfigSchema } from 'openapi';
|
import type { CreateImpactMetricsConfigSchema } from 'openapi';
|
||||||
|
|
||||||
export const useImpactMetricsApi = ({
|
type UseImpactMetricsApiParams =
|
||||||
projectId,
|
| {
|
||||||
featureName,
|
projectId: string;
|
||||||
}: { projectId: string; featureName: 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({
|
const { makeRequest, createRequest, errors, loading } = useAPI({
|
||||||
propagateErrors: true,
|
propagateErrors: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
const createImpactMetric = useCallback(
|
const createImpactMetric = useCallback(
|
||||||
async (config: CreateImpactMetricsConfigSchema) => {
|
async (config: CreateImpactMetricsConfigSchema) => {
|
||||||
const path = `api/admin/projects/${projectId}/features/${featureName}/impact-metrics/config`;
|
|
||||||
const req = createRequest(
|
const req = createRequest(
|
||||||
path,
|
basePath,
|
||||||
{
|
{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: JSON.stringify(config),
|
body: JSON.stringify(config),
|
||||||
@ -29,9 +36,8 @@ export const useImpactMetricsApi = ({
|
|||||||
|
|
||||||
const deleteImpactMetric = useCallback(
|
const deleteImpactMetric = useCallback(
|
||||||
async (metricId: string) => {
|
async (metricId: string) => {
|
||||||
const path = `api/admin/projects/${projectId}/features/${featureName}/impact-metrics/config/${metricId}`;
|
|
||||||
const req = createRequest(
|
const req = createRequest(
|
||||||
path,
|
`${basePath}/${metricId}`,
|
||||||
{
|
{
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user