diff options
author | Michael Muré <batolettre@gmail.com> | 2021-02-05 10:38:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 10:38:38 +0100 |
commit | 52f6563495095af13a777b866ea8fea100fd0ff8 (patch) | |
tree | 461e92c46c5e4ba8fd897b2a808ac52cc57c41ae /webui/src/components/CloseBugButton/CloseBugButton.tsx | |
parent | b6a967efac24672b64d02dbbe6e661d195804fbd (diff) | |
parent | ad45f9199898ed4abaf4a8a52421edd727eaa26e (diff) | |
download | git-bug-52f6563495095af13a777b866ea8fea100fd0ff8.tar.gz git-bug-52f6563495095af13a777b866ea8fea100fd0ff8.zip |
Merge pull request #547 from claudioantonio/webui_546
Webui 546
Diffstat (limited to 'webui/src/components/CloseBugButton/CloseBugButton.tsx')
-rw-r--r-- | webui/src/components/CloseBugButton/CloseBugButton.tsx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/webui/src/components/CloseBugButton/CloseBugButton.tsx b/webui/src/components/CloseBugButton/CloseBugButton.tsx new file mode 100644 index 00000000..19f56cab --- /dev/null +++ b/webui/src/components/CloseBugButton/CloseBugButton.tsx @@ -0,0 +1,55 @@ +import React from 'react'; + +import Button from '@material-ui/core/Button'; + +import { BugFragment } from 'src/pages/bug/Bug.generated'; +import { TimelineDocument } from 'src/pages/bug/TimelineQuery.generated'; + +import { useCloseBugMutation } from './CloseBug.generated'; + +interface Props { + bug: BugFragment; + disabled: boolean; +} + +function CloseBugButton({ bug, disabled }: Props) { + const [closeBug, { loading, error }] = useCloseBugMutation(); + + function closeBugAction() { + closeBug({ + variables: { + input: { + prefix: bug.id, + }, + }, + refetchQueries: [ + // TODO: update the cache instead of refetching + { + query: TimelineDocument, + variables: { + id: bug.id, + first: 100, + }, + }, + ], + awaitRefetchQueries: true, + }); + } + + if (loading) return <div>Loading...</div>; + if (error) return <div>Error</div>; + + return ( + <div> + <Button + variant="contained" + onClick={() => closeBugAction()} + disabled={bug.status === 'CLOSED' || disabled} + > + Close issue + </Button> + </div> + ); +} + +export default CloseBugButton; |