1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-10 01:19:53 +01:00
unleash.unleash/frontend/src/hooks/useChangeRequestInReviewWarning.tsx
Thomas Heartman e2853acf15
Remove uses of one of / use operator checks instead (#10328)
Updates a few remaining places where we check constraint operators with
the new constraint operator checks. Additionally, because there was only
one remaining place where we used the `oneOf` function, I replaced it
with a normal `includes` check and deleted the `oneOf` util. From what I
can tell, there's no need to have that utility function; it doesn't
provide much benefit over using the language built-ins 🤷🏼
2025-07-08 11:10:45 +02:00

29 lines
1005 B
TypeScript

import { Alert } from '@mui/material';
import type { ChangeRequestType } from '../component/changeRequest/changeRequest.types';
export const useChangeRequestInReviewWarning = (
draft: ChangeRequestType[] | undefined,
) => {
const changeRequestInReviewOrApproved = (environment: string) => {
if (!draft) return false;
return draft.some(
(changeRequest) =>
changeRequest.environment === environment &&
['In review', 'Approved'].includes(changeRequest.state),
);
};
return {
changeRequestInReviewOrApproved,
alert: (
<Alert sx={{ margin: '1rem 0' }} severity='warning'>
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>
),
};
};