From 0e3caba922ba5a21a7e7aa0f433d944aacf58e78 Mon Sep 17 00:00:00 2001 From: Sascha Date: Wed, 17 Mar 2021 18:19:16 +0100 Subject: Update comment on submit --- webui/src/pages/bug/EditCommentForm.tsx | 23 ++++++++++++++++------- webui/src/pages/bug/EditCommentform.graphql | 7 +++++++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 webui/src/pages/bug/EditCommentform.graphql diff --git a/webui/src/pages/bug/EditCommentForm.tsx b/webui/src/pages/bug/EditCommentForm.tsx index 46cf1e1f..f5040064 100644 --- a/webui/src/pages/bug/EditCommentForm.tsx +++ b/webui/src/pages/bug/EditCommentForm.tsx @@ -7,7 +7,7 @@ import { makeStyles, Theme } from '@material-ui/core/styles'; import CommentInput from '../../components/CommentInput/CommentInput'; import { BugFragment } from './Bug.generated'; -import { useAddCommentMutation } from './CommentForm.generated'; +import { useEditCommentMutation } from './EditCommentform.generated'; import { AddCommentFragment } from './MessageCommentFragment.generated'; import { CreateFragment } from './MessageCreateFragment.generated'; @@ -46,14 +46,23 @@ type Props = { }; function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) { - const [addComment, { loading }] = useAddCommentMutation(); - const [issueComment, setIssueComment] = useState(comment.message); + const [editComment, { loading }] = useEditCommentMutation(); + const [message, setMessage] = useState(comment.message); const [inputProp, setInputProp] = useState(''); const classes = useStyles({ loading }); const form = useRef(null); const submit = () => { - console.log('submit: ' + issueComment); + console.log('submit: ' + message + '\nTo: ' + comment.id); + editComment({ + variables: { + input: { + prefix: bug.id, + message: message, + target: comment.id, + }, + }, + }); resetForm(); if (onPostSubmit) onPostSubmit(); }; @@ -66,7 +75,7 @@ function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) { const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - if (issueComment.length > 0) submit(); + if (message.length > 0) submit(); }; function getCancelButton() { @@ -83,7 +92,7 @@ function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) { setIssueComment(comment)} + onChange={(message: string) => setMessage(message)} inputText={comment.message} />
@@ -93,7 +102,7 @@ function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) { variant="contained" color="primary" type="submit" - disabled={loading || issueComment.length === 0} + disabled={loading || message.length === 0} > Update Comment diff --git a/webui/src/pages/bug/EditCommentform.graphql b/webui/src/pages/bug/EditCommentform.graphql new file mode 100644 index 00000000..c7047e6e --- /dev/null +++ b/webui/src/pages/bug/EditCommentform.graphql @@ -0,0 +1,7 @@ +mutation EditComment($input: EditCommentInput!) { + editComment(input: $input) { + bug { + id + } + } +} -- cgit