diff --git a/src/components/SignInForm/index.jsx b/src/components/SignInForm/index.jsx index fd7424e..aa22206 100644 --- a/src/components/SignInForm/index.jsx +++ b/src/components/SignInForm/index.jsx @@ -1,12 +1,27 @@ -import React from 'react'; +import React, { useRef } from 'react'; import { Link as RouterLink } from 'react-router-dom'; import { Avatar, Button, Container, CssBaseline, Grid, Link, TextField, Typography } from '@material-ui/core'; import LockOutlinedIcon from '@material-ui/icons/LockOutlined'; +import { useUserContext } from '../Contexts/UserContext'; import useStyles from '../Styles'; export default function SignInForm() { const classes = useStyles(); - + const emailEl = useRef(null); + const passwordEl = useRef(null); + const { fetching, signIn, setError } = useUserContext(); + const onSubmit = async (event) => { + try { + event.preventDefault(); + const username = emailEl.current.value; + const password = passwordEl.current.value; + const result = await signIn(username, password); + } + catch (e) { + setError(e.message); + } + }; + return ( @@ -17,7 +32,7 @@ export default function SignInForm() { Sign in -
+ diff --git a/src/components/SignUpForm/index.jsx b/src/components/SignUpForm/index.jsx index 247d46d..89c5236 100644 --- a/src/components/SignUpForm/index.jsx +++ b/src/components/SignUpForm/index.jsx @@ -1,12 +1,29 @@ -import React from 'react'; +import React, { useRef } from 'react'; import { Link as RouterLink } from 'react-router-dom'; import { Avatar, Button, Container, CssBaseline, Grid, Link, TextField, Typography } from '@material-ui/core'; import LockOpenOutlinedIcon from '@material-ui/icons/LockOpenOutlined'; import useStyles from '../Styles'; +import { useUserContext } from '../Contexts/UserContext'; export default function SignInForm() { + const { signUp, fetching, setError } = useUserContext(); const classes = useStyles(); - + const emailEl = useRef(null); + const passwordEl = useRef(null); + const confirmEl = useRef(null); + const onSubmit = async (event) => { + try { + event.preventDefault(); + const email = emailEl.current.value; + const password = passwordEl.current.value; + const confirm = confirmEl.current.value; + const result = await signUp(email, password, confirm); + } + catch (e) { + setError(e.message); + } + }; + return ( @@ -17,7 +34,7 @@ export default function SignInForm() { Sign up - +