CloseBugButton.tsx

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