Skip to content

Commit

Permalink
initial state for first time teacher interview flow
Browse files Browse the repository at this point in the history
  • Loading branch information
MirTalpur committed Mar 30, 2020
1 parent d5e5e22 commit 8530938
Show file tree
Hide file tree
Showing 5 changed files with 515 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,7 @@ yarn-error.log*
# firebase authenication
homeschool-nonprod-firebase-*
fire.html

# intellij
.idea*

78 changes: 67 additions & 11 deletions pages/dashboard.js
Original file line number Diff line number Diff line change
@@ -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 (
<div>
<Nav />
<h1>Dashboard Page</h1>
<p>You can't go into this page if you are not authenticated.</p>
</div>
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(
<div>
{renderConditionalDashboard()}
</div>
)
}
}
Expand Down
15 changes: 13 additions & 2 deletions pages/sign_up.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading

0 comments on commit 8530938

Please sign in to comment.