Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add dialog for cancel #2568

Merged
merged 1 commit into from
Nov 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ChangeRequestComment } from './ChangeRequestComments/ChangeRequestComme
import { AddCommentField } from './ChangeRequestComments/AddCommentField';
import { usePendingChangeRequests } from 'hooks/api/getters/usePendingChangeRequests/usePendingChangeRequests';
import { useChangeRequestsEnabled } from '../../../hooks/useChangeRequestsEnabled';
import { Dialogue } from 'component/common/Dialogue/Dialogue';

const StyledAsideBox = styled(Box)(({ theme }) => ({
width: '30%',
Expand Down Expand Up @@ -50,6 +51,7 @@ const StyledInnerContainer = styled(Box)(({ theme }) => ({

export const ChangeRequestOverview: FC = () => {
const projectId = useRequiredPathParam('projectId');
const [showCancelDialog, setShowCancelDialog] = useState(false);
const { user } = useAuthUser();
const { isAdmin } = useContext(AccessContext);
const [commentText, setCommentText] = useState('');
Expand Down Expand Up @@ -110,6 +112,7 @@ export const ChangeRequestOverview: FC = () => {
await changeState(projectId, Number(id), {
state: 'Cancelled',
});
setShowCancelDialog(false);
refetchChangeRequest();
refetchChangeRequestOpen();
setToastData({
Expand All @@ -122,6 +125,9 @@ export const ChangeRequestOverview: FC = () => {
}
};

const onCancel = () => setShowCancelDialog(true);
const onCancelAbort = () => setShowCancelDialog(false);

const isSelfReview =
changeRequest?.createdBy.id === user?.id &&
changeRequest.state === 'In review' &&
Expand Down Expand Up @@ -239,7 +245,7 @@ export const ChangeRequestOverview: FC = () => {
<Button
sx={{ ml: 2 }}
variant="outlined"
onClick={onCancelChanges}
onClick={onCancel}
>
Cancel changes
</Button>
Expand All @@ -248,6 +254,24 @@ export const ChangeRequestOverview: FC = () => {
</StyledButtonBox>
</StyledInnerContainer>
</StyledPaper>
<Dialogue
open={showCancelDialog}
onClick={onCancelChanges}
onClose={onCancelAbort}
title="Cancel change request"
>
<Typography sx={{ marginBottom: 2 }}>
You are about to cancel this change request
</Typography>
<Typography
variant="body2"
sx={theme => ({ color: theme.palette.neutral.dark })}
>
The change request will be moved to closed, and it can't
be applied anymore. Once cancelled, the change request
can't be reopened.
</Typography>
</Dialogue>
</Box>
</>
);
Expand Down