-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Frontend - requestSecret Mutation and createAccount Mutation
- Loading branch information
1 parent
743d1c6
commit 821f287
Showing
9 changed files
with
201 additions
and
86 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
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,13 @@ | ||
import { useState } from "react"; | ||
export default defaultValue => { | ||
const [value, setValue] = useState(defaultValue); | ||
|
||
const onChange = e => { | ||
const { | ||
target: { value } | ||
} = e; | ||
setValue(value); | ||
}; | ||
|
||
return { value, onChange }; | ||
}; |
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
import React, { useState } from "react"; | ||
import AuthPresenter from "./AuthPresenter"; | ||
import useInput from "../../Hooks/useInput"; | ||
import { useMutation } from "react-apollo-hooks"; | ||
import { LOG_IN, CREATE_ACCOUNT } from "./AuthQueries"; | ||
import { toast } from "react-toastify"; | ||
|
||
export default () => { | ||
const [action, setAction] = useState("logIn"); | ||
const username = useInput(""); | ||
const firstName = useInput(""); | ||
const lastName = useInput(""); | ||
const email = useInput(""); | ||
const [requestSecret] = useMutation(LOG_IN, { | ||
variables: { email: email.value }, | ||
update: (_, { data }) => { | ||
const { requestSecret } = data; | ||
if (!requestSecret) { | ||
toast.error("You don't have an account. Please Sign up!"); | ||
setTimeout(() => setAction("signUp"), 3000); | ||
} | ||
} | ||
}); | ||
const [createAccount] = useMutation(CREATE_ACCOUNT, { | ||
variables: { | ||
email: email.value, | ||
username: username.value, | ||
firstName: firstName.value, | ||
lastName: lastName.value | ||
} | ||
}); | ||
const onLogin = e => { | ||
e.preventDefault(); | ||
if (email.value !== "") { | ||
requestSecret(); | ||
} | ||
}; | ||
|
||
return ( | ||
<AuthPresenter | ||
setAction={setAction} | ||
action={action} | ||
username={username} | ||
firstName={firstName} | ||
lastName={lastName} | ||
email={email} | ||
onLogin={onLogin} | ||
/> | ||
); | ||
}; |
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,86 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
import { Link } from "react-router-dom"; | ||
import Input from "../../Components/Input"; | ||
import Button from "../../Components/Button"; | ||
|
||
const Wrapper = styled.div` | ||
min-height: 80vh; | ||
display: flex; | ||
align-items: center; | ||
justify-content: center; | ||
flex-direction: column; | ||
`; | ||
|
||
const Box = styled.div` | ||
${props => props.theme.whiteBox} | ||
border-radius: 0px; | ||
width: 100%; | ||
max-width: 350px; | ||
`; | ||
|
||
const StateChanger = styled(Box)` | ||
text-align: center; | ||
padding 20px 0px; | ||
`; | ||
|
||
const Form = styled(Box)` | ||
padding: 40px; | ||
padding-bottom: 30px; | ||
margin-bottom: 15px; | ||
form { | ||
width: 100%; | ||
input { | ||
width: 100%; | ||
&:not(:last-child) { | ||
margin-bottom: 7px; | ||
} | ||
} | ||
button { | ||
margin-top: 10px; | ||
} | ||
} | ||
`; | ||
|
||
export default ({ | ||
action, | ||
setAction, | ||
firstName, | ||
lastName, | ||
username, | ||
email, | ||
onLogin | ||
}) => ( | ||
<Wrapper> | ||
<Form> | ||
{action === "logIn" ? ( | ||
<form onSubmit={onLogin}> | ||
<Input placeholder={"Email"} {...email} type="email" /> | ||
<Button text={"Log in"} /> | ||
</form> | ||
) : ( | ||
<form onSubmit={onLogin}> | ||
<Input placeholder={"First name"} {...firstName} /> | ||
<Input placeholder={"Last name"} {...lastName} /> | ||
<Input placeholder={"Email"} {...email} type="email" /> | ||
<Input placeholder={"Username"} {...username} /> | ||
<Button text={"Sign up"} /> | ||
</form> | ||
)} | ||
</Form> | ||
|
||
<StateChanger> | ||
{action === "logIn" ? ( | ||
<> | ||
Don't have an account?{" "} | ||
<Link onClick={() => setAction("signUp")}>Sign up</Link> | ||
</> | ||
) : ( | ||
<> | ||
Have an account?{" "} | ||
<Link onClick={() => setAction("logIn")}>Log in</Link> | ||
</> | ||
)} | ||
</StateChanger> | ||
</Wrapper> | ||
); |
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,25 @@ | ||
import { gql } from "apollo-boost"; | ||
|
||
export const LOG_IN = gql` | ||
mutation requestSecret($email: String!) { | ||
requestSecret(email: $email) | ||
} | ||
`; | ||
|
||
export const CREATE_ACCOUNT = gql` | ||
mutation createAccount( | ||
$username: String! | ||
$email: String! | ||
$firstName: String | ||
$lastName: String | ||
$bio: String | ||
) { | ||
createAccount( | ||
username: $username | ||
email: $email | ||
firstName: $firstName | ||
lastName: $lastName | ||
bio: $bio | ||
) | ||
} | ||
`; |
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,2 @@ | ||
import AuthContainer from "./AuthContainer"; | ||
export default AuthContainer; |