Skip to content

Commit bbb685c

Browse files
committed
Login mutation
1 parent 70a6d12 commit bbb685c

File tree

3 files changed

+111
-25
lines changed

3 files changed

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

3-
import LogoSvg from 'src/Images/logo.svg'
4-
import { Input } from 'src/Components/Input'
5-
import { Button } from 'src/Components/Button'
6-
import { Br } from 'src/Components/Br'
7-
import { LogoWrapper, Logo, Text } from './style'
4+
import { LoginMutation } from 'src/Graphql/Login'
5+
import { LoginUI } from './Login'
6+
7+
interface FieldProps {
8+
email: string
9+
password: string
10+
}
811

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

client/src/Graphql/Login/index.tsx

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

0 commit comments

Comments
 (0)