From 29581f884aee088433222304c6272bdf0da8065f Mon Sep 17 00:00:00 2001 From: misterrodger Date: Thu, 13 Jun 2019 16:52:07 +0300 Subject: [PATCH 1/2] Add StudentSignup to /studentSignup - Relates #44 - - --- .../{StudentSignup.css => StudentSignupForm.css} | 0 .../{StudentSignup.js => StudentSignupForm.js} | 6 +++--- src/routes/StudentSignup.js | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) rename src/components/StudentSignupForm/{StudentSignup.css => StudentSignupForm.css} (100%) rename src/components/StudentSignupForm/{StudentSignup.js => StudentSignupForm.js} (97%) diff --git a/src/components/StudentSignupForm/StudentSignup.css b/src/components/StudentSignupForm/StudentSignupForm.css similarity index 100% rename from src/components/StudentSignupForm/StudentSignup.css rename to src/components/StudentSignupForm/StudentSignupForm.css diff --git a/src/components/StudentSignupForm/StudentSignup.js b/src/components/StudentSignupForm/StudentSignupForm.js similarity index 97% rename from src/components/StudentSignupForm/StudentSignup.js rename to src/components/StudentSignupForm/StudentSignupForm.js index db49576..4343529 100644 --- a/src/components/StudentSignupForm/StudentSignup.js +++ b/src/components/StudentSignupForm/StudentSignupForm.js @@ -1,8 +1,8 @@ import React, { useState } from 'react'; -import './StudentSignup.css'; +import './StudentSignupForm.css'; import axios from 'axios'; -function StudentSignup() { +function StudentSignupForm() { const [data, setData] = useState({firstName:"", lastName: "", email: "", phoneNumber: "", password: "", university: "", yearOfStudy: "", courseStudied: "", aboutYou: "", LinkedinURL: ""}); @@ -111,4 +111,4 @@ function StudentSignup() { ) } -export default StudentSignup; +export default StudentSignupForm; diff --git a/src/routes/StudentSignup.js b/src/routes/StudentSignup.js index 2b9cde0..ceabbe4 100644 --- a/src/routes/StudentSignup.js +++ b/src/routes/StudentSignup.js @@ -1,9 +1,10 @@ import React, { Component } from "react"; +import StudentSignupForm from '../components/StudentSignupForm/StudentSignupForm.js' const StudentSignup = () => { return (
-

StudentSignup Page

+
); }; From 898da24798f8c4160ef7d8d72eb63c92184ad86e Mon Sep 17 00:00:00 2001 From: misterrodger Date: Thu, 13 Jun 2019 17:12:08 +0300 Subject: [PATCH 2/2] Connect StudentSignup React form to database - Using axios with async/await - Tested with Postman and it is working, yay! - Relates #44 --- .../StudentSignupForm/StudentSignupForm.js | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/src/components/StudentSignupForm/StudentSignupForm.js b/src/components/StudentSignupForm/StudentSignupForm.js index 4343529..5d8e1ef 100644 --- a/src/components/StudentSignupForm/StudentSignupForm.js +++ b/src/components/StudentSignupForm/StudentSignupForm.js @@ -15,20 +15,19 @@ function StudentSignupForm() { const handleSubmit = (event) => { event.preventDefault(); - console.log(data) - // const addStudent = async () => { - // console.log(`Fake submitting: ${data}`); - // try { - // return await - // axios.post('/api/student/create', this.data) - // } catch(error) { - // console.error(error) - // } - // } - // addStudent(); - // props.history.push('/dashboard'); - setData({firstName:"", lastName: "", email: "", //clear form on submit - phoneNumber: null, password: "", university: "", yearOfStudy: 0, + + const addStudent = async () => { + console.log(`Fake submitting: ${data}`); + try { + return await + axios.post('/api/student/sign-up', data) + } catch(error) { + console.error(error) + } + } + addStudent(); + setData({firstName:"", lastName: "", email: "", //clear form on submit + phoneNumber: "", password: "", university: "", yearOfStudy: "", courseStudied: "", aboutYou: "", LinkedinURL: ""}); }