2022-11-14 12:34:38 +01:00
|
|
|
import React from 'react';
|
|
|
|
import { useChangeRequestConfig } from './api/getters/useChangeRequestConfig/useChangeRequestConfig';
|
2022-11-04 09:50:00 +01:00
|
|
|
|
2022-11-14 12:34:38 +01:00
|
|
|
export const useChangeRequestsEnabled = (projectId: string) => {
|
|
|
|
const { data } = useChangeRequestConfig(projectId);
|
|
|
|
|
|
|
|
const isChangeRequestConfigured = React.useCallback(
|
|
|
|
(environment: string): boolean => {
|
2022-12-15 13:43:06 +01:00
|
|
|
return data.some(draft => {
|
2022-11-14 12:34:38 +01:00
|
|
|
return (
|
|
|
|
draft.environment === environment &&
|
|
|
|
draft.changeRequestEnabled
|
|
|
|
);
|
|
|
|
});
|
|
|
|
},
|
2022-11-24 16:16:14 +01:00
|
|
|
[JSON.stringify(data)]
|
2022-11-07 09:16:29 +01:00
|
|
|
);
|
2022-11-14 12:34:38 +01:00
|
|
|
|
|
|
|
const isChangeRequestConfiguredInAnyEnv = React.useCallback((): boolean => {
|
2022-12-15 13:43:06 +01:00
|
|
|
return data.some(draft => draft.changeRequestEnabled);
|
2022-11-24 16:16:14 +01:00
|
|
|
}, [JSON.stringify(data)]);
|
2022-11-14 12:34:38 +01:00
|
|
|
|
|
|
|
return {
|
|
|
|
isChangeRequestConfigured,
|
|
|
|
isChangeRequestConfiguredInAnyEnv,
|
|
|
|
};
|
2022-11-04 09:50:00 +01:00
|
|
|
};
|