1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-28 00:17:12 +01:00
unleash.unleash/frontend/src/component/changeRequest/ChangeRequestConfirmDialog/ChangeRequestConfirmDialog.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

71 lines
2.4 KiB
TypeScript

import { FC } from 'react';
import { Alert, Typography } from '@mui/material';
import { Dialogue } from 'component/common/Dialogue/Dialogue';
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
import { useRequiredPathParam } from 'hooks/useRequiredPathParam';
import { ConditionallyRender } from 'component/common/ConditionallyRender/ConditionallyRender';
import { useChangeRequestInReviewWarning } from 'hooks/useChangeRequestInReviewWarning';
interface IChangeRequestDialogueProps {
isOpen: boolean;
onConfirm: () => void;
onClose: () => void;
environment?: string;
showBanner?: boolean;
messageComponent: JSX.Element;
}
export const ChangeRequestDialogue: FC<IChangeRequestDialogueProps> = ({
isOpen,
onConfirm,
onClose,
showBanner,
environment,
messageComponent,
}) => {
const projectId = useRequiredPathParam('projectId');
const { data } = usePendingChangeRequests(projectId);
const { changeRequestInReviewOrApproved, alert } =
useChangeRequestInReviewWarning(data);
const hasChangeRequestInReviewForEnvironment =
changeRequestInReviewOrApproved(environment || '');
const primaryButtonText = hasChangeRequestInReviewForEnvironment
? 'Add to existing change request'
: 'Add suggestion to draft';
return (
<Dialogue
open={isOpen}
primaryButtonText={primaryButtonText}
secondaryButtonText='Cancel'
onClick={onConfirm}
onClose={onClose}
title='Request changes'
fullWidth
>
<ConditionallyRender
condition={hasChangeRequestInReviewForEnvironment}
show={alert}
/>
<ConditionallyRender
condition={Boolean(showBanner)}
show={
<Alert severity='info' sx={{ mb: 2 }}>
Change requests feature is enabled for {environment}.
Your changes need to be approved before they will be
live. All the changes you do now will be added into a
draft that you can submit for review.
</Alert>
}
/>
<Typography variant='body2' color='text.secondary'>
Your suggestion:
</Typography>
{messageComponent}
</Dialogue>
);
};