diff options
Diffstat (limited to 'webui/src/pages/new')
-rw-r--r-- | webui/src/pages/new/NewBug.graphql | 7 | ||||
-rw-r--r-- | webui/src/pages/new/NewBugPage.tsx | 121 |
2 files changed, 128 insertions, 0 deletions
diff --git a/webui/src/pages/new/NewBug.graphql b/webui/src/pages/new/NewBug.graphql new file mode 100644 index 00000000..92df016e --- /dev/null +++ b/webui/src/pages/new/NewBug.graphql @@ -0,0 +1,7 @@ +mutation newBug($input: NewBugInput!) { + newBug(input: $input) { + bug { + humanId + } + } +}
\ No newline at end of file diff --git a/webui/src/pages/new/NewBugPage.tsx b/webui/src/pages/new/NewBugPage.tsx new file mode 100644 index 00000000..c8e68e7b --- /dev/null +++ b/webui/src/pages/new/NewBugPage.tsx @@ -0,0 +1,121 @@ +import React, { FormEvent, useState } from 'react'; + +import { Button } from '@material-ui/core'; +import Paper from '@material-ui/core/Paper'; +import TextField from '@material-ui/core/TextField/TextField'; +import { fade, makeStyles, Theme } from '@material-ui/core/styles'; + +import CommentInput from '../bug/CommentInput'; + +import { useNewBugMutation } from './NewBug.generated'; + +/** + * Css in JS styles + */ +const useStyles = makeStyles((theme: Theme) => ({ + main: { + maxWidth: 800, + margin: 'auto', + marginTop: theme.spacing(4), + marginBottom: theme.spacing(4), + padding: theme.spacing(2), + overflow: 'hidden', + }, + titleInput: { + borderRadius: theme.shape.borderRadius, + borderColor: fade(theme.palette.primary.main, 0.2), + borderStyle: 'solid', + borderWidth: '1px', + backgroundColor: fade(theme.palette.primary.main, 0.05), + padding: theme.spacing(0, 0), + transition: theme.transitions.create([ + 'width', + 'borderColor', + 'backgroundColor', + ]), + }, + form: { + display: 'flex', + flexDirection: 'column', + }, + actions: { + display: 'flex', + justifyContent: 'flex-end', + }, + gitbugButton: { + backgroundColor: '#2ea44fd9', + color: '#fff', + '&:hover': { + backgroundColor: '#2ea44f', + }, + }, +})); + +/** + * Form to create a new issue + */ +function NewBugPage() { + const [newBug, { loading, error }] = useNewBugMutation(); + const [issueTitle, setIssueTitle] = useState(''); + const [issueComment, setIssueComment] = useState(''); + const classes = useStyles(); + let issueTitleInput: any; + + function submitNewIssue(e: FormEvent) { + e.preventDefault(); + if (!isFormValid()) return; + console.log('submitNewISsue'); + console.log('title: ', issueTitle); + console.log('comment: ', issueComment); + newBug({ + variables: { + input: { + title: issueTitle, + message: issueComment, + }, + }, + }); + issueTitleInput.value = ''; + } + + function isFormValid() { + return issueTitle.length > 0 && issueComment.length > 0 ? true : false; + } + + if (loading) return <div>Loading</div>; + if (error) return <div>Error</div>; + + return ( + <Paper className={classes.main}> + <form className={classes.form} onSubmit={submitNewIssue}> + <TextField + inputRef={(node) => { + issueTitleInput = node; + }} + label="Title" + className={classes.titleInput} + variant="outlined" + fullWidth + margin="dense" + onChange={(event: any) => setIssueTitle(event.target.value)} + /> + <CommentInput + loading={false} + onChange={(comment: string) => setIssueComment(comment)} + /> + <div className={classes.actions}> + <Button + className={classes.gitbugButton} + variant="contained" + type="submit" + disabled={isFormValid() ? false : true} + > + Submit new issue + </Button> + </div> + </form> + </Paper> + ); +} + +export default NewBugPage; |