import React, { useState, useRef } from 'react'; import Button from '@material-ui/core/Button'; import Paper from '@material-ui/core/Paper'; import { makeStyles, Theme } from '@material-ui/core/styles'; import CommentInput from '../../components/CommentInput/CommentInput'; import { BugFragment } from './Bug.generated'; import { useEditCommentMutation } from './EditCommentform.generated'; import { AddCommentFragment } from './MessageCommentFragment.generated'; import { CreateFragment } from './MessageCreateFragment.generated'; type StyleProps = { loading: boolean }; const useStyles = makeStyles((theme) => ({ container: { padding: theme.spacing(0, 2, 2, 2), }, textarea: {}, tabContent: { margin: theme.spacing(2, 0), }, preview: { borderBottom: `solid 3px ${theme.palette.grey['200']}`, minHeight: '5rem', }, actions: { display: 'flex', justifyContent: 'flex-end', }, greenButton: { marginLeft: '8px', backgroundColor: '#2ea44fd9', color: '#fff', '&:hover': { backgroundColor: '#2ea44f', }, }, })); type Props = { bug: BugFragment; comment: AddCommentFragment | CreateFragment; onCancelClick?: () => void; onPostSubmit?: () => void; }; function EditCommentForm({ bug, comment, onCancelClick, onPostSubmit }: Props) { 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: ' + message + '\nTo: ' + comment.id); editComment({ variables: { input: { prefix: bug.id, message: message, target: comment.id, }, }, }); resetForm(); if (onPostSubmit) onPostSubmit(); }; function resetForm() { setInputProp({ value: '', }); } const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); if (message.length > 0) submit(); }; function getCancelButton() { return ( ); } return (
setMessage(message)} inputText={comment.message} />
{onCancelClick ? getCancelButton() : ''}
); } export default EditCommentForm;