1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-06 00:07:44 +01:00
unleash.unleash/frontend/src/hooks/api/actions/useFeatureStrategyApi/useFeatureStrategyApi.ts
olav 35262e404b refactor: clean up strategy parameter types (#944)
* refactor: fix splash page button background color

* refactor: regenerate OpenAPI client

* refactor: clean up strategy parameter types

* refactor: remove index signature from IConstraint

* refactor: fix never-seen status in features list
2022-05-04 15:16:34 +02:00

65 lines
2.1 KiB
TypeScript

import { IFeatureStrategyPayload, IFeatureStrategy } from 'interfaces/strategy';
import useAPI from '../useApi/useApi';
const useFeatureStrategyApi = () => {
const { makeRequest, createRequest, errors, loading } = useAPI({
propagateErrors: true,
});
const addStrategyToFeature = async (
projectId: string,
featureId: string,
environmentId: string,
payload: IFeatureStrategyPayload
): Promise<IFeatureStrategy> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies`;
const req = createRequest(
path,
{ method: 'POST', body: JSON.stringify(payload) },
'addStrategyToFeature'
);
return (await makeRequest(req.caller, req.id)).json();
};
const deleteStrategyFromFeature = async (
projectId: string,
featureId: string,
environmentId: string,
strategyId: string
): Promise<void> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/${strategyId}`;
const req = createRequest(
path,
{ method: 'DELETE' },
'deleteStrategyFromFeature'
);
await makeRequest(req.caller, req.id);
};
const updateStrategyOnFeature = async (
projectId: string,
featureId: string,
environmentId: string,
strategyId: string,
payload: IFeatureStrategyPayload
): Promise<void> => {
const path = `api/admin/projects/${projectId}/features/${featureId}/environments/${environmentId}/strategies/${strategyId}`;
const req = createRequest(
path,
{ method: 'PUT', body: JSON.stringify(payload) },
'updateStrategyOnFeature'
);
await makeRequest(req.caller, req.id);
};
return {
addStrategyToFeature,
updateStrategyOnFeature,
deleteStrategyFromFeature,
loading,
errors,
};
};
export default useFeatureStrategyApi;