Skip to content

Commit 70a6d12

Browse files
committed
Register mutation
1 parent 10040fb commit 70a6d12

File tree

4 files changed

+104
-22
lines changed

4 files changed

+104
-22
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import * as React from 'react'
2+
import { Form, Field } from 'formik'
3+
4+
import { FormikInput } from 'src/Components/FomikInput'
5+
import { Button } from 'src/Components/Button'
6+
import { Br } from 'src/Components/Br'
7+
import { Text } from './style'
8+
9+
interface Props {
10+
changePage: () => void
11+
submit: () => void
12+
}
13+
14+
export const RegisterUI: React.SFC<Props> = ({ changePage, submit }) => (
15+
<Form>
16+
<Field
17+
name="email"
18+
placeholder="Email"
19+
label="Email"
20+
component={FormikInput}
21+
/>
22+
23+
<Field
24+
name="password"
25+
placeholder="Password"
26+
label="Password"
27+
type="password"
28+
component={FormikInput}
29+
/>
30+
31+
<Button fullWidth onClick={submit}>
32+
Register
33+
</Button>
34+
35+
<Br />
36+
37+
<Text onClick={changePage}>Login</Text>
38+
</Form>
39+
)
Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,42 @@
11
import * as React from 'react'
2+
import { Formik } from 'formik'
23

3-
import { Input } from 'src/Components/Input'
4-
import { Button } from 'src/Components/Button'
5-
import { Br } from 'src/Components/Br'
6-
import { Text } from './style'
4+
import { RegisterMutation } from 'src/Graphql/Register'
5+
import { RegisterUI } from './Register'
6+
7+
interface FieldProps {
8+
email: string
9+
password: string
10+
}
711

812
interface Props {
913
changePage: () => void
1014
}
1115

12-
export const Register: React.SFC<Props> = ({ changePage }) => (
13-
<>
14-
<Input onChange={() => null} type="text" placeholder="Email" />
15-
16-
<Input onChange={() => null} type="text" placeholder="Name" />
17-
18-
<Input onChange={() => null} type="text" placeholder="Surname" />
19-
20-
<Input onChange={() => null} type="password" placeholder="Password" />
21-
22-
<Button fullWidth>Register</Button>
23-
24-
<Br />
25-
26-
<Text onClick={changePage}>Login</Text>
27-
</>
28-
)
16+
export class Register extends React.Component<Props, {}> {
17+
public render() {
18+
const { changePage } = this.props
19+
20+
return (
21+
<RegisterMutation>
22+
{({ register }) => (
23+
<Formik<FieldProps>
24+
initialValues={{ email: '', password: '' }}
25+
onSubmit={async (values: FieldProps) =>
26+
await register({
27+
variables: { ...values }
28+
})
29+
}
30+
>
31+
{({ submitForm }) => (
32+
<RegisterUI
33+
changePage={changePage}
34+
submit={submitForm}
35+
/>
36+
)}
37+
</Formik>
38+
)}
39+
</RegisterMutation>
40+
)
41+
}
42+
}

client/src/Graphql/Register/index.tsx

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import * as React from 'react'
2+
import { Mutation } from 'react-apollo'
3+
import gql from 'graphql-tag'
4+
5+
const registerMutation = gql`
6+
mutation Register($email: String!, $password: String!) {
7+
register(input: { email: $email, password: $password }) {
8+
ok
9+
}
10+
}
11+
`
12+
13+
interface WithRegister {
14+
register: any
15+
}
16+
17+
interface Props {
18+
children: (data: WithRegister) => React.ReactNode
19+
}
20+
21+
export class RegisterMutation extends React.PureComponent<Props> {
22+
public render() {
23+
return (
24+
<Mutation mutation={registerMutation}>
25+
{mutate => this.props.children({ register: mutate })}
26+
</Mutation>
27+
)
28+
}
29+
}

client/src/Pages/CreateListing/Components/CreateListingForm/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as React from 'react'
22
import { Formik, Form } from 'formik'
33

4+
import { CreateListingMutation } from 'src/Graphql/CreateListing'
45
import { Wizard } from 'src/Components/Wizard'
56
import { Stepper } from 'src/Components/Stepper'
67
import { Button } from 'src/Components/Button'
@@ -9,7 +10,6 @@ import { RoomInfoForm } from '../RoomInfoForm'
910
import { LocationForm } from '../LocationForm'
1011

1112
import { Container, Wrapper, Buttons } from './style'
12-
import { CreateListingMutation } from '../../../../Graphql/CreateListing'
1313

1414
interface FieldValues {
1515
name: string

0 commit comments

Comments
 (0)