1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-11-01 19:07:38 +01:00
unleash.unleash/frontend/src/hooks/useChangeRequestsEnabled.ts
2022-12-15 13:43:06 +01:00

28 lines
885 B
TypeScript

import React from 'react';
import { useChangeRequestConfig } from './api/getters/useChangeRequestConfig/useChangeRequestConfig';
export const useChangeRequestsEnabled = (projectId: string) => {
const { data } = useChangeRequestConfig(projectId);
const isChangeRequestConfigured = React.useCallback(
(environment: string): boolean => {
return data.some(draft => {
return (
draft.environment === environment &&
draft.changeRequestEnabled
);
});
},
[JSON.stringify(data)]
);
const isChangeRequestConfiguredInAnyEnv = React.useCallback((): boolean => {
return data.some(draft => draft.changeRequestEnabled);
}, [JSON.stringify(data)]);
return {
isChangeRequestConfigured,
isChangeRequestConfiguredInAnyEnv,
};
};