diff --git a/src/App.js b/src/App.js index ec72f6c..fea7231 100644 --- a/src/App.js +++ b/src/App.js @@ -10,11 +10,13 @@ import Nav from './pages/pageSections/Nav'; import Footer from './pages/pageSections/Footer'; import LoginForm from './components/Auth/LoginForm.js'; import SignUpForm from './components/Auth/SignUpForm.js'; +import Register from './components/Auth/Register.js'; import Connect from './pages/Connect'; import Profile from './pages/Profile'; -import ResourceSubmit from './pages/Resources/ResourceSubmit'; -import ResourcePage from './pages/Resources/ResourcePage.js'; +import SubmitResource from './components/Resources/submitResource'; +import ResourcePage from './components/Resources/ResourcePage.js'; import PrivateRoute from './PrivateRoute'; +import VerifyEmail from './components/Auth/VerifyEmail'; function App() { const [authTokens, setAuthTokens] = useState( @@ -45,6 +47,13 @@ function App() { + + + + } + /> diff --git a/src/components/Auth/Register.js b/src/components/Auth/Register.js new file mode 100644 index 0000000..313281d --- /dev/null +++ b/src/components/Auth/Register.js @@ -0,0 +1,130 @@ +import React, { useState } from 'react'; +import PropTypes from 'prop-types'; +import { registerUser } from '../../utils/queries'; +import { Link, Redirect } from 'react-router-dom'; +import { Box, Button, TextField } from '@material-ui/core/'; +import { useAuth } from './AuthContext'; +import { validationResolver, defaultValues } from './Register.schema'; +import { Form, Field } from '../form'; + +const Register = ({ toggleActiveForm }) => { + const [errorMessage, setErrorMessage] = useState(null); + const [isLoggedIn, setIsLoggedIn] = useState(false); + const referer = '/profile'; + const auth = useAuth(); + + const onSubmit = ({ username, email, password, passwordConfirmation }) => { + console.log('#GC SUBMIT', { + username, + email, + password, + passwordConfirmation, + }); + //registerUser(data); + }; + + if (isLoggedIn) { + return ; + } + + if (auth && auth.authTokens) { + return

Welcome!

; + } + + return ( + + + Create an account + + + + + + + {errorMessage && {errorMessage}} + + + + +

+ Already have an account? + {toggleActiveForm ? ( + + Log in + + ) : ( + Log in + )} + . +

+
+ ); +}; + +const { func } = PropTypes; + +Register.propTypes = { + toggleActiveForm: func, +}; + +export default Register; diff --git a/src/components/Auth/Register.schema.js b/src/components/Auth/Register.schema.js new file mode 100644 index 0000000..828a943 --- /dev/null +++ b/src/components/Auth/Register.schema.js @@ -0,0 +1,30 @@ +import Joi from '@hapi/joi'; +import { createValidationResolver } from '../form'; + +const schema = Joi.object({ + username: Joi.string() + .required() + .trim() + .label('Username'), + email: Joi.string() + .required() + .trim() + .label('Email'), + password: Joi.string() + .required() + .label('Password'), + passwordConfirmation: Joi.string() + .required() + .label('Password Confirmation') + .valid(Joi.ref('password')), +}); + +const defaultValues = { + username: '', + email: '', + password: '', + passwordConfirmation: '', +}; + +const validationResolver = createValidationResolver(schema); +export { validationResolver, schema, defaultValues }; diff --git a/src/components/Auth/VerifyEmail.js b/src/components/Auth/VerifyEmail.js new file mode 100644 index 0000000..f92e8d9 --- /dev/null +++ b/src/components/Auth/VerifyEmail.js @@ -0,0 +1,21 @@ +import React from 'react'; +import PropTypes from 'prop-types'; +import { useQuery } from 'react-query'; +import { verifyEmail } from '../../utils/queries'; + +function VerifyEmail({ matchProps }) { + console.log(matchProps); + const key = matchProps.match.params.key; + console.log(key); + const { isLoading, data, error } = useQuery(['key', key], verifyEmail); + console.log(isLoading); + console.log(data); + console.log(error); + return

verify email

; +} + +VerifyEmail.propTypes = { + matchProps: PropTypes.object, +}; + +export default VerifyEmail; diff --git a/src/utils/queries.js b/src/utils/queries.js index 5a6d85a..8173ceb 100644 --- a/src/utils/queries.js +++ b/src/utils/queries.js @@ -1,6 +1,6 @@ import axios from 'axios'; -const API_URL = '/api/v1'; +const API_URL = 'http://localhost:8000/api/v1'; const getResource = async (_key, id) => { const { data } = await axios.get(`${API_URL}/resources/${id}`); @@ -12,4 +12,25 @@ const getResources = async searchTerm => { return data; }; -export { getResource, getResources }; +const registerUser = async (_key, user) => { + const { username, password1, email, password2 } = user; + const { data } = await axios.post(`${API_URL}/auth/registration`, { + username, + email, + password1, + password2, + }); + return data; +}; + +const verifyEmail = async (_key, apiKey) => { + const { data } = await axios.post( + `${API_URL}/auth/registration/verify-email`, + { + key: apiKey, + } + ); + return data; +}; + +export { getResource, getResources, verifyEmail, registerUser };