1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

cancel changes (#2510)

This commit is contained in:
Mateusz Kwasniewski 2022-11-23 14:36:11 +01:00 committed by GitHub
parent f9726fdee9
commit 9fee0bb264
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 19 deletions

View File

@ -99,6 +99,23 @@ export const ChangeRequestOverview: FC = () => {
}
};
const onCancelChanges = async () => {
try {
await changeState(projectId, Number(id), {
state: 'Cancelled',
});
refetchChangeRequest();
refetchChangeRequestOpen();
setToastData({
type: 'success',
title: 'Success',
text: 'Changes cancelled',
});
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
}
};
const isSelfReview =
changeRequest?.createdBy.id === user?.id &&
changeRequest.state === 'In review' &&
@ -190,6 +207,23 @@ export const ChangeRequestOverview: FC = () => {
</PermissionButton>
}
/>
<ConditionallyRender
condition={
changeRequest.state !== 'Applied' &&
changeRequest.state !== 'Cancelled' &&
(changeRequest.createdBy.id === user?.id ||
isAdmin)
}
show={
<Button
sx={{ ml: 2 }}
variant="outlined"
onClick={onCancelChanges}
>
Cancel changes
</Button>
}
/>
</StyledButtonBox>
</StyledInnerContainer>
</StyledPaper>

View File

@ -54,22 +54,6 @@ export const ReviewButton = () => {
}
};
const onReject = async () => {
try {
await changeState(projectId, Number(id), {
state: 'Cancelled',
});
refetchChangeRequest();
setToastData({
type: 'success',
title: 'Success',
text: 'Changes rejected',
});
} catch (error: unknown) {
setToastApiError(formatUnknownError(error));
}
};
const onToggle = () => {
setOpen(prevOpen => !prevOpen);
};
@ -132,9 +116,6 @@ export const ReviewButton = () => {
<MenuItem onClick={onApprove}>
Approve changes
</MenuItem>
<MenuItem onClick={onReject}>
Reject changes
</MenuItem>
</MenuList>
</ClickAwayListener>
</Paper>