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