Removed unused authentication and product code
This commit is contained in:
@@ -1,133 +0,0 @@
|
||||
import React, { useState } from 'react';
|
||||
import { useHistory } from 'react-router';
|
||||
import { useMutation, gql } from '@apollo/client';
|
||||
import { AUTH_TOKEN } from '../constants';
|
||||
|
||||
const SIGNUP_MUTATION = gql`
|
||||
mutation SignupMutation(
|
||||
$email: String!
|
||||
$password: String!
|
||||
$name: String!
|
||||
) {
|
||||
signup(
|
||||
email: $email
|
||||
password: $password
|
||||
username: $name
|
||||
) {
|
||||
token
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const LOGIN_MUTATION = gql`
|
||||
mutation LoginMutation(
|
||||
$email: String!
|
||||
$password: String!
|
||||
) {
|
||||
login(email: $email, password: $password) {
|
||||
token
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const Login = () => {
|
||||
const history = useHistory();
|
||||
|
||||
const [formState, setFormState] = useState({
|
||||
login: true,
|
||||
email: '',
|
||||
password: '',
|
||||
name: ''
|
||||
});
|
||||
|
||||
const [login] = useMutation(LOGIN_MUTATION, {
|
||||
variables: {
|
||||
email: formState.email,
|
||||
password: formState.password
|
||||
},
|
||||
onCompleted: ({ login }) => {
|
||||
localStorage.setItem(AUTH_TOKEN, login.token);
|
||||
history.push('/');
|
||||
}
|
||||
});
|
||||
|
||||
const [signup] = useMutation(SIGNUP_MUTATION, {
|
||||
variables: {
|
||||
name: formState.name,
|
||||
email: formState.email,
|
||||
password: formState.password
|
||||
},
|
||||
onCompleted: ({ signup }) => {
|
||||
localStorage.setItem(AUTH_TOKEN, signup.token);
|
||||
history.push('/');
|
||||
}
|
||||
});
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h4 className="mv3">
|
||||
{formState.login ? 'Login' : 'Sign Up'}
|
||||
</h4>
|
||||
<div className="flex flex-column">
|
||||
{!formState.login && (
|
||||
<input
|
||||
value={formState.name}
|
||||
onChange={(e) =>
|
||||
setFormState({
|
||||
...formState,
|
||||
name: e.target.value
|
||||
})
|
||||
}
|
||||
type="text"
|
||||
placeholder="Your name"
|
||||
/>
|
||||
)}
|
||||
<input
|
||||
value={formState.email}
|
||||
onChange={(e) =>
|
||||
setFormState({
|
||||
...formState,
|
||||
email: e.target.value
|
||||
})
|
||||
}
|
||||
type="text"
|
||||
placeholder="Your email address"
|
||||
/>
|
||||
<input
|
||||
value={formState.password}
|
||||
onChange={(e) =>
|
||||
setFormState({
|
||||
...formState,
|
||||
password: e.target.value
|
||||
})
|
||||
}
|
||||
type="password"
|
||||
placeholder="Choose a safe password"
|
||||
/>
|
||||
</div>
|
||||
<div className="flex mt3">
|
||||
<button
|
||||
className="pointer mr2 button"
|
||||
onClick={formState.login ? login : signup}
|
||||
>
|
||||
{formState.login ? 'login' : 'create account'}
|
||||
</button>
|
||||
<button
|
||||
className="pointer button"
|
||||
onClick={(e) =>
|
||||
setFormState({
|
||||
...formState,
|
||||
login: !formState.login
|
||||
})
|
||||
}
|
||||
>
|
||||
{formState.login
|
||||
? 'need to create an account?'
|
||||
: 'already have an account?'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Login;
|
||||
@@ -1,14 +0,0 @@
|
||||
import React from 'react';
|
||||
|
||||
const Product = (props) => {
|
||||
const { product } = props;
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<b>{product.title}</b>: only {product.qty}!
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Product;
|
||||
@@ -1,40 +0,0 @@
|
||||
import React from 'react';
|
||||
import Product from './Product';
|
||||
import { useQuery, gql } from '@apollo/client';
|
||||
|
||||
const FEED_QUERY = gql`
|
||||
{
|
||||
allProducts{
|
||||
title
|
||||
qty
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
const ProductList = () => {
|
||||
|
||||
const { data } = useQuery(FEED_QUERY);
|
||||
|
||||
console.log("Data:", data);
|
||||
|
||||
if (data !== undefined) {
|
||||
return (
|
||||
<div>
|
||||
{
|
||||
data.allProducts.map((product) => (
|
||||
<Product key={product.id} product={product} />
|
||||
))
|
||||
}
|
||||
</div>
|
||||
);
|
||||
} else {
|
||||
return (
|
||||
<div>
|
||||
Rendering...
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default ProductList;
|
||||
@@ -11,10 +11,6 @@ const FEED_SEARCH_QUERY = gql`
|
||||
title
|
||||
description
|
||||
type
|
||||
createdBy {
|
||||
id
|
||||
username
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user