2022-11-29 14:52:01 +01:00
|
|
|
import { Alert } from '@mui/material';
|
|
|
|
import { oneOf } from 'utils/oneOf';
|
|
|
|
import { IChangeRequest } from '../component/changeRequest/changeRequest.types';
|
|
|
|
|
|
|
|
export const useChangeRequestInReviewWarning = (
|
2023-10-02 14:25:46 +02:00
|
|
|
draft: IChangeRequest[] | undefined,
|
2022-11-29 14:52:01 +01:00
|
|
|
) => {
|
|
|
|
const changeRequestInReviewOrApproved = (environment: string) => {
|
|
|
|
if (!draft) return false;
|
|
|
|
|
|
|
|
return draft.some(
|
2023-10-02 14:25:46 +02:00
|
|
|
(changeRequest) =>
|
2022-11-29 14:52:01 +01:00
|
|
|
changeRequest.environment === environment &&
|
2023-10-02 14:25:46 +02:00
|
|
|
oneOf(['In review', 'Approved'], changeRequest.state),
|
2022-11-29 14:52:01 +01:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
return {
|
|
|
|
changeRequestInReviewOrApproved,
|
|
|
|
alert: (
|
2023-10-02 14:25:46 +02:00
|
|
|
<Alert sx={{ margin: '1rem 0' }} severity='warning'>
|
2022-11-29 14:52:01 +01:00
|
|
|
You currently have a change request in review for this
|
|
|
|
environment. Adding a new change will add the change to the
|
|
|
|
existing change request, and all existing approvals will be
|
|
|
|
reset. Are you sure you want to continue?
|
|
|
|
</Alert>
|
|
|
|
),
|
|
|
|
};
|
|
|
|
};
|