-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create a user with mutation and connect to the form
- Loading branch information
1 parent
6c833c7
commit 3856a83
Showing
10 changed files
with
165 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,87 @@ | ||
import React, { useState } from 'react' | ||
import Link from 'next/link' | ||
import { AccountCircle, Email, Lock } from '@styled-icons/material-outlined' | ||
|
||
import { UsersPermissionsRegisterInput } from 'graphql/generated/globalTypes' | ||
import { MUTATION_REGISTER } from 'graphql/mutations/register' | ||
|
||
import { FormWrapper, FormLink } from 'components/Form' | ||
import Button from 'components/Button' | ||
import TextField from 'components/TextField' | ||
import { useMutation } from '@apollo/client' | ||
|
||
const FormSignUp = () => { | ||
const [values, setValues] = useState<UsersPermissionsRegisterInput>({ | ||
username: '', | ||
email: '', | ||
password: '' | ||
}) | ||
|
||
const [createUser] = useMutation(MUTATION_REGISTER) | ||
|
||
const handleSubmit = async (event: React.FormEvent) => { | ||
event.preventDefault() | ||
|
||
createUser({ | ||
variables: { | ||
input: { | ||
username: values.username, | ||
email: values.email, | ||
password: values.password | ||
} | ||
} | ||
}) | ||
} | ||
|
||
const handleInput = (field: string, value: string) => { | ||
setValues((s) => ({ ...s, [field]: value })) | ||
} | ||
|
||
return ( | ||
<FormWrapper> | ||
<form onSubmit={handleSubmit}> | ||
<TextField | ||
name="username" | ||
placeholder="Username" | ||
type="text" | ||
icon={<AccountCircle />} | ||
onInputChange={(v) => handleInput('username', v)} | ||
/> | ||
<TextField | ||
name="email" | ||
placeholder="Email" | ||
type="email" | ||
icon={<Email />} | ||
onInputChange={(v) => handleInput('email', v)} | ||
/> | ||
<TextField | ||
name="password" | ||
placeholder="Password" | ||
type="password" | ||
icon={<Lock />} | ||
onInputChange={(v) => handleInput('password', v)} | ||
/> | ||
<TextField | ||
name="confirm-password" | ||
placeholder="Confirm password" | ||
type="password" | ||
icon={<Lock />} | ||
onInputChange={(v) => handleInput('confirm-password', v)} | ||
/> | ||
|
||
<Button type="submit" size="large" fullWidth> | ||
Sign up now | ||
</Button> | ||
|
||
const FormSignUp = () => ( | ||
<FormWrapper> | ||
<form> | ||
<TextField | ||
name="name" | ||
placeholder="Name" | ||
type="name" | ||
icon={<AccountCircle />} | ||
/> | ||
<TextField | ||
name="email" | ||
placeholder="Email" | ||
type="email" | ||
icon={<Email />} | ||
/> | ||
<TextField | ||
name="password" | ||
placeholder="Password" | ||
type="password" | ||
icon={<Lock />} | ||
/> | ||
<TextField | ||
name="confirm-password" | ||
placeholder="Confirm password" | ||
type="password" | ||
icon={<Lock />} | ||
/> | ||
|
||
<Button size="large" fullWidth> | ||
Sign up now | ||
</Button> | ||
|
||
<FormLink> | ||
Already have an account?{' '} | ||
<Link href="/sign-in"> | ||
<a>Sign in</a> | ||
</Link> | ||
</FormLink> | ||
</form> | ||
</FormWrapper> | ||
) | ||
<FormLink> | ||
Already have an account?{' '} | ||
<Link href="/sign-in"> | ||
<a>Sign in</a> | ||
</Link> | ||
</FormLink> | ||
</form> | ||
</FormWrapper> | ||
) | ||
} | ||
|
||
export default FormSignUp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
// @generated | ||
// This file was automatically generated and should not be edited. | ||
|
||
import { UsersPermissionsRegisterInput } from "./globalTypes"; | ||
|
||
// ==================================================== | ||
// GraphQL mutation operation: MutationRegister | ||
// ==================================================== | ||
|
||
export interface MutationRegister_register { | ||
__typename: "UsersPermissionsLoginPayload"; | ||
jwt: string | null; | ||
} | ||
|
||
export interface MutationRegister { | ||
register: MutationRegister_register; | ||
} | ||
|
||
export interface MutationRegisterVariables { | ||
input: UsersPermissionsRegisterInput; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { gql } from '@apollo/client' | ||
|
||
export const MUTATION_REGISTER = gql` | ||
mutation MutationRegister($input: UsersPermissionsRegisterInput!) { | ||
register(input: $input) { | ||
jwt | ||
} | ||
} | ||
` |