1import Button from '@material-ui/core/Button';
2import CircularProgress from '@material-ui/core/CircularProgress';
3
4import { BugFragment } from 'src/pages/bug/Bug.generated';
5import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated';
6
7import { useOpenBugMutation } from './OpenBug.generated';
8
9interface Props {
10 bug: BugFragment;
11 disabled?: boolean;
12}
13
14function ReopenBugButton({ bug, disabled }: Props) {
15 const [openBug, { loading, error }] = useOpenBugMutation();
16
17 function openBugAction() {
18 openBug({
19 variables: {
20 input: {
21 prefix: bug.id,
22 },
23 },
24 refetchQueries: [
25 // TODO: update the cache instead of refetching
26 {
27 query: TimelineDocument,
28 variables: {
29 id: bug.id,
30 first: 100,
31 },
32 },
33 ],
34 awaitRefetchQueries: true,
35 });
36 }
37
38 if (loading) return <CircularProgress />;
39 if (error) return <div>Error</div>;
40
41 return (
42 <div>
43 <Button
44 variant="contained"
45 onClick={() => openBugAction()}
46 disabled={bug.status === 'OPEN' || disabled}
47 >
48 Reopen bug
49 </Button>
50 </div>
51 );
52}
53
54export default ReopenBugButton;