From 3902da1747a3e32db0b67f1162eafd4860b3d27a Mon Sep 17 00:00:00 2001 From: Joseph Ditton Date: Sat, 20 Nov 2021 19:34:10 -0700 Subject: working on signup implementation --- client/components/sign_up/_sign_up.jsx | 86 ++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 client/components/sign_up/_sign_up.jsx (limited to 'client/components/sign_up/_sign_up.jsx') diff --git a/client/components/sign_up/_sign_up.jsx b/client/components/sign_up/_sign_up.jsx new file mode 100644 index 0000000..bbbd51b --- /dev/null +++ b/client/components/sign_up/_sign_up.jsx @@ -0,0 +1,86 @@ +import { useState } from 'react'; + +export const SignUp = () => { + const [name, setName] = useState(''); + const [email, setEmail] = useState(''); + const [emailConfirmation, setEmailConfirmation] = useState(''); + const [password, setPassword] = useState(''); + const [passwordConfiramation, setPasswordConfirmation] = useState(''); + const [errorMessage, setErrorMessage] = useState(''); + + const signUp = async () => { + if (email === '') { + setErrorMessage('Email cannot be blank'); + return; + } + if (email !== emailConfirmation) { + setErrorMessage('Email does not match.'); + return; + } + if (password === '') { + setErrorMessage('Password cannot be blank'); + return; + } + if (password !== passwordConfiramation) { + setErrorMessage('Password does not match'); + return; + } + if (name === '') { + setErrorMessage('Name cannot be blank.'); + return; + } + try { + await fetch('/users', { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ + name, + email, + password, + }), + }); + } catch (e) { + console.log(e.message); + } + }; + + return ( +
+
Name
+ setName(e.target.value)} + /> +
Email
+ setEmail(e.target.value)} + /> +
Confirm Email
+ setEmailConfirmation(e.target.value)} + /> +
Password
+ setPassword(e.target.value)} + /> +
Confirm Password
+ setPasswordConfirmation(e.target.value)} + /> +
+ +
+
+ ); +}; -- cgit v1.2.3-70-g09d2