aboutsummaryrefslogtreecommitdiffstats
path: root/webui/src/pages/new/NewBugPage.tsx
blob: 118966ed98e43b3b414d9ef9dd5f0f9b9fb06e46 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import React, { FormEvent } from 'react';

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 { useNewBugMutation } from './NewBug.generated';

/**
 * 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: 'row',
    flexWrap: 'wrap',
    justifyContent: 'flex-end',
  },
}));

/**
 * Form to create a new issue
 */
function NewBugPage() {
  const classes = useStyles();
  let inputField: any;
  const [newBug, { loading, error }] = useNewBugMutation();

  function submitNewIssue(e: FormEvent) {
    e.preventDefault();
    newBug({
      variables: {
        input: {
          title: String(inputField.value),
          message: 'Message', //TODO
        },
      },
    });
    inputField.value = '';
  }

  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) => {
            inputField = node;
          }}
          label="Title"
          className={classes.titleInput}
          variant="outlined"
          fullWidth
          margin="dense"
        />
        <button type="submit">Submit</button>
      </form>
    </Paper>
  );
}

export default NewBugPage;