diff --git a/.gitignore b/.gitignore index f2944a4..e5cef2d 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,7 @@ yarn-error.log* # firebase authenication homeschool-nonprod-firebase-* fire.html + +# intellij +.idea* + diff --git a/pages/dashboard.js b/pages/dashboard.js index d73bbbb..fc223c5 100644 --- a/pages/dashboard.js +++ b/pages/dashboard.js @@ -1,31 +1,87 @@ // pages/dashboard.js import React from 'react'; -import Nav from '../components/nav'; import withAuth from '../src/helpers/withAuth'; +import { db } from '../src/firebase'; +import Router from 'next/router'; + + class Dashboard extends React.Component { constructor(props) { super(props); this.state = { authUser: this.props.authUser, - } + newTeacherUserFlow: false, + loading: true, + studentDashboard: false, + teacherDashboard: false, + }; } componentDidMount() { console.log("in component did mount"); - console.log(this.state.authUser) - if(this.state.authUser !== null){ - + console.log(this.state.authUser); + // get the doc with uid + // check if the uid is isNewUser than go to the + // new teacher interview flow + if(this.state.authUser !== null) { + let docRef = db.collection("users").doc(this.state.authUser.uid); + let currentComponent = this; + docRef.get().then((doc) => { + if(doc.exists) { + // check if the users uid isNewUser + console.log("Document data:", doc.data()); + if(doc.data().isNewUser && doc.data().userType === "teacher") { + console.log("newTeacherUserFlow interview questions"); + currentComponent.setState({ + newTeacherUserFlow: true, + }); + } + } else { + console.log("No such document!"); + } + }).catch((error) => { + console.log("Error getting document:", error); + }); } } + // shouldComponentUpdate() { + // let docRef = db.collection("users").doc(this.state.authUser.uid); + // docRef.get().then((doc) => { + // if(doc.exists) { + // // check if the users uid isNewUser + // console.log("Document data:", doc.data()); + // if(doc.data().isNewUser && doc.data().userType === "teacher") { + // console.log("newTeacherUserFlow interview questions"); + // this.setState({ + // newTeacherUserFlow: true, + // }); + // } + // } else { + // console.log("No such document!"); + // } + // }).catch(function(error) { + // console.log("Error getting document:", error); + // }); + // } + + render() { - return ( -
-
+ const renderConditionalDashboard = () => { + console.log("be here now") + if(this.state.newTeacherUserFlow === true) { + console.log("i'm here man") + Router.push('/teacher_setup') + } else { + return null + } + } + + return( +
+ {renderConditionalDashboard()} +
) } } diff --git a/pages/sign_up.js b/pages/sign_up.js index c094b15..e9bc301 100644 --- a/pages/sign_up.js +++ b/pages/sign_up.js @@ -231,9 +231,20 @@ class SignUp extends React.Component { }); auth.createUserWithEmailAndPassword(this.state.clientEmail, this.state.clientPassword) .then((firebaseUser) => { - let initialUserDoc = { email: this.state.email }; + let initialUserDoc = { + email: this.state.email + }; let initialUserDocStringify = JSON.stringify(initialUserDoc); - db.collection("teachers").doc(firebaseUser.user.uid).set({initialUserDocStringify}).then(() =>{ + let userDataCollection = { + "uid": firebaseUser.user.uid, + "displayName": firebaseUser.user.displayName, + "photoURL": firebaseUser.user.photoURL, + "email": firebaseUser.user.email, + "emailVerified": firebaseUser.user.emailVerified, + "isNewUser": firebaseUser.additionalUserInfo.isNewUser, + "userType": "teacher" + } + db.collection("users").doc(firebaseUser.user.uid).set(userDataCollection).then(() =>{ Router.push('/dashboard'); }).catch((error) =>{ console.log(error); diff --git a/pages/teacher_setup.js b/pages/teacher_setup.js new file mode 100644 index 0000000..933e0d4 --- /dev/null +++ b/pages/teacher_setup.js @@ -0,0 +1,429 @@ +import React from 'react'; +import withAuth from '../src/helpers/withAuth'; +import ErrorPage from 'next/error' +import { db } from "../src/firebase"; + + +class TeacherInterview extends React.Component { + constructor(props) { + super(props); + this.state = { + questionState: 1, + // Profile pic + questionOne: "Would you like to add a profile pic?", + questionTwo: "Upload your profile pic", + // Full Name + questionThree: "Do you want to add your full name?", + questionFour: "What is your full name?", + // Add students + questionFive: "Do you want to add students right now? You can always not add students or add them later if needed ", + questionSix: "Enter student emails and passwords, Note: This will be a temp password for students until they login", + // School name + questionSeven: "Do you want to add a name for you homeschool?", + questionEight: "Enter your homeschool name", + authUser: this.props.authUser, + teacherType: false, + firstTimeRender: true, + teacherStudent: [{ + email: "", + password: "", + }], + homeSchoolName: "", + teacherProfilePicFile: '', + teacherName: '', + teacherDataCollection: { + "uid": "", + "displayName": "", + "photoURL": "", + "email": "", + "emailVerified": "", + "isNewUser": "", + "userType": "teacher", + "teacherStudents": [], + "teacherName": "", + "homeschoolName": "", + }, + validationTeacherName: { + message: null, + }, + validationHomeSchoolName: { + message: null, + }, + isLoadingSubmit: true, + } + } + + componentDidMount() { + console.log("yoo dogg"); + // here check if the user is actually an teacher again + // if not throw a 404 + if (this.state.authUser !== null) { + let docRef = db.collection("users").doc(this.state.authUser.uid); + let currentComponent = this; + docRef.get().then((doc) => { + if (doc.exists) { + // check if the users uid isNewUser + console.log("Document data:", doc.data()); + if (doc.data().userType !== "teacher") { + currentComponent.setState({ + teacherType: false, + firstTimeRender: false, + }); + } else { + currentComponent.setState({ + firstTimeRender: false, + teacherType: true, + }); + } + } else { + console.log("No such document!"); + } + }).catch((error) => { + console.log("Error getting document:", error); + }); + } + } + + renderQuestion() { + if (this.state.firstTimeRender === true) { + return

Loading...

+ } + if (this.state.teacherType === false && this.state.firstTimeRender === false) { + return + } else { + switch (this.state.questionState) { + case 1: + return ( +
+
+

{this.state.questionOne}

+ + +
+
+ ) + case 2: + return ( +
+
+

{this.state.questionTwo}

+ this.handleImageUpload}/> + + +
+
+ + ) + case 3: + return ( +
+

{this.state.questionThree}

+ + +
+ ) + case 4: + return ( +
+
+

{this.state.questionFour}

+ Full Name:
+ this.handleTeacherName(event)} + onBlur={() => this.onBlurHandleTeacherName()} + /> +
+ + +
+ ) + case 5: + return ( +
+

{this.state.questionFive}

+ + +
+ ) + case 6: + return ( +
+
+

{this.state.questionSix}

+ Add Students:
+ { + this.state.teacherStudent.map((val, idx) => { + let studentId = `student-${idx}`, passwordId = `password-${idx}` + return ( +
+ + + + +
+ ) + }) + } + + + + +
+
+ ) + case 7: + return ( +
+

{this.state.questionSeven}

+ + +
+ ) + case 8: + return ( +
+
+

{this.state.questionEight}

+ Full Name:
+ this.handleHomeSchoolName(event)} + onBlur={() => this.onBlurHandleHomeSchoolName()} + /> +
+ + +
+ ) + } + } + } + + handleFirstTimeSetup(){ + + } + + handleSubmit = () => { + if(this.state.isLoadingSubmit){ + this.handleFirstTimeSetup(); + return( +
Loading first time submission....
+ ) + } else { + + } + } + + handleStudentChange = (e) => { + if (["email", "password"].includes(e.target.className)) { + let teacherStudent = [...this.state.teacherStudent] + teacherStudent[e.target.dataset.id][e.target.className] = e.target.value; + this.setState({teacherStudent}, () => console.log(this.state.teacherStudent)) + } else { + this.setState({[e.target.email]: e.target.value}) + } + } + + handleAddMoreStudents = (e) => { + e.preventDefault(); + this.setState((prevState) => ({ + teacherStudent: [...prevState.teacherStudent, {email: "", password: ""}] + })) + } + + handleTeacherName = (e) => { + e.preventDefault(); + const target = e.target; + const value = target.value; + this.setState({ + handleTeacherName: value, + }); + console.log(this.state.handleTeacherName); + } + + handleHomeSchoolName = (e) => { + e.preventDefault(); + const target = e.target; + const value = target.value; + this.setState({ + homeSchoolName: value, + }); + console.log(this.state.homeSchoolName); + } + + onBlurHandleHomeSchoolName = () => { + if (!this.state.homeSchoolName) { + this.setState({ + validationHomeSchoolName: { + message: 'Name invalid', + }, + }); + } else { + this.setState({ + validationHomeSchoolName: { + message: null, + }, + }); + } + } + + onBlurHandleTeacherName = () => { + if (!this.state.handleTeacherName) { + this.setState({ + validationTeacherName: { + message: 'Name invalid', + }, + }); + } else { + this.setState({ + validationTeacherName: { + message: null, + }, + }); + } + } + + handleImageUpload = (e) => { + this.setState({ + teacherProfilePicFile: e.target.files[0] + }); + } + + handleYesClick(event) { + event.preventDefault(); + if(this.state.questionState == 8){ + this.handleSubmit(); + } else { + let newQuestionState = this.state.questionState + 1; + this.setState({ + questionState: newQuestionState, + }); + } + } + + handleNoClick = (event) => { + event.preventDefault(); + if(this.state.questionState == 7) { + this.handleSubmit(); + } else { + let newQuestionState = this.state.questionState + 2; + this.setState({ + questionState: newQuestionState, + }); + } + } + + handleBackClick = (event) => { + event.preventDefault(); + let newQuestionState = this.state.questionState - 1; + this.setState({ + questionState: newQuestionState, + }); + } + + render() { + return ( + +
+ {this.renderQuestion()} +
+
+ ); + } +} + +export default withAuth(TeacherInterview); diff --git a/src/helpers/withAuth.js b/src/helpers/withAuth.js index 41c65bf..c28fa36 100644 --- a/src/helpers/withAuth.js +++ b/src/helpers/withAuth.js @@ -37,6 +37,8 @@ const withAuth = (Component) => { return

Loading ......

; } else if (status == 'SIGNED_IN') { return + } else { + return

In this state now...

} }