From f8d41c3bcda516cd33be25475ac52ab72c376e1f Mon Sep 17 00:00:00 2001 From: Cláudio Date: Thu, 28 Jan 2021 21:24:40 -0300 Subject: Partial commit for #158 - It´s possible to create new issues from webui (only title) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Next step - Finish new issue form (First comment field and style) - Update Readme about codegen usage and enforcing playground usage --- webui/src/App.tsx | 4 +- webui/src/pages/new/NewBug.graphql | 7 ++++ webui/src/pages/new/NewBugPage.tsx | 85 ++++++++++++++++++++++++++++++++++++++ webui/src/pages/new/NewPage.tsx | 80 ----------------------------------- 4 files changed, 94 insertions(+), 82 deletions(-) create mode 100644 webui/src/pages/new/NewBug.graphql create mode 100644 webui/src/pages/new/NewBugPage.tsx delete mode 100644 webui/src/pages/new/NewPage.tsx (limited to 'webui') diff --git a/webui/src/App.tsx b/webui/src/App.tsx index f7df7d2b..3a5ef025 100644 --- a/webui/src/App.tsx +++ b/webui/src/App.tsx @@ -4,14 +4,14 @@ import { Route, Switch } from 'react-router'; import Layout from './layout'; import BugPage from './pages/bug'; import ListPage from './pages/list'; -import NewPage from './pages/new/NewPage'; +import NewBugPage from './pages/new/NewBugPage'; export default function App() { return ( - + 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..925034e1 --- /dev/null +++ b/webui/src/pages/new/NewBugPage.tsx @@ -0,0 +1,85 @@ +import React, { FormEvent } from 'react'; + +import Paper from '@material-ui/core/Paper/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
Loading
; + if (error) return
Error
; + + return ( + +
+ { + inputField = node; + }} + label="Title" + className={classes.titleInput} + variant="outlined" + fullWidth + margin="dense" + /> + + +
+ ); +} + +export default NewBugPage; diff --git a/webui/src/pages/new/NewPage.tsx b/webui/src/pages/new/NewPage.tsx deleted file mode 100644 index b485987e..00000000 --- a/webui/src/pages/new/NewPage.tsx +++ /dev/null @@ -1,80 +0,0 @@ -import { gql, useMutation } from '@apollo/client'; -import React, { FormEvent } from 'react'; - -import Paper from '@material-ui/core/Paper/Paper'; -import TextField from '@material-ui/core/TextField/TextField'; -import { fade, makeStyles, Theme } from '@material-ui/core/styles'; - -import GBButton from '../../components/Button/GBButton'; - -/** - * Styles - */ -const useStyles = makeStyles((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', - }, -})); - -const NEW_BUG = gql` - mutation NewBug($input: NewBugInput) { - newBug(input: $input) { - title - message - } - } -`; - -/** - * Form to create a new issue - */ -function NewPage() { - const classes = useStyles({ searching: false }); - const [newBugInput] = useMutation(NEW_BUG); - - function submitNewIssue(e: FormEvent) { - e.preventDefault(); - // TODO Call API - } - - return ( - -
- - - -
- ); -} - -export default NewPage; -- cgit