2022-10-26 13:57:59 +02:00
|
|
|
import { FC } from 'react';
|
2022-10-28 09:37:55 +02:00
|
|
|
import { Alert, Typography } from '@mui/material';
|
2022-10-26 13:57:59 +02:00
|
|
|
import { Dialogue } from 'component/common/Dialogue/Dialogue';
|
2022-11-29 14:52:01 +01:00
|
|
|
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';
|
2022-10-26 13:57:59 +02:00
|
|
|
|
2022-11-02 07:34:14 +01:00
|
|
|
interface IChangeRequestDialogueProps {
|
2022-10-26 13:57:59 +02:00
|
|
|
isOpen: boolean;
|
|
|
|
onConfirm: () => void;
|
|
|
|
onClose: () => void;
|
|
|
|
environment?: string;
|
2022-11-04 10:33:07 +01:00
|
|
|
showBanner?: boolean;
|
|
|
|
messageComponent: JSX.Element;
|
2022-10-26 13:57:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-02 07:34:14 +01:00
|
|
|
export const ChangeRequestDialogue: FC<IChangeRequestDialogueProps> = ({
|
2022-10-26 13:57:59 +02:00
|
|
|
isOpen,
|
|
|
|
onConfirm,
|
|
|
|
onClose,
|
2022-11-04 10:33:07 +01:00
|
|
|
showBanner,
|
2022-10-26 13:57:59 +02:00
|
|
|
environment,
|
2022-11-04 10:33:07 +01:00
|
|
|
messageComponent,
|
2022-11-29 14:52:01 +01:00
|
|
|
}) => {
|
|
|
|
const projectId = useRequiredPathParam('projectId');
|
2022-12-08 10:59:37 +01:00
|
|
|
const { data } = usePendingChangeRequests(projectId);
|
2022-11-29 14:52:01 +01:00
|
|
|
const { changeRequestInReviewOrApproved, alert } =
|
2022-12-08 10:59:37 +01:00
|
|
|
useChangeRequestInReviewWarning(data);
|
2022-11-29 14:52:01 +01:00
|
|
|
|
|
|
|
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}.
|
2023-01-25 15:10:35 +01:00
|
|
|
Your changes need to be approved before they will be
|
2022-11-29 14:52:01 +01:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
};
|