Commit e46eca11 authored by Hasitha Samarasekara's avatar Hasitha Samarasekara

Create User Login - Tutor DashBoard - 2

parent 477ad330
......@@ -28,20 +28,21 @@ router.route('/getCredentials').post((req, res) => {
const email = req.body.user_email;
const password = req.body.user_password;
console.log(email);
userAccount.find({user_email:email}, function (err, User) {
}).then(User => {
let payload = {
user_id: User[0].user_id,
user_email:User[0].user_email,
user_name:'',
user_type:User[0].user_type
}
console.log(User);
if(User.length > 0){
let payload = {
user_id: User[0].user_id,
user_email:User[0].user_email,
user_name:'',
user_type:User[0].user_type
}
console.log(password);
console.log(User[0].user_password);
if(User[0].user_password === password){
......@@ -90,7 +91,10 @@ router.route('/getCredentials').post((req, res) => {
})
.catch(err => res.status(400).json('Error: ' + err));
.catch(err => {
console.log(err);
res.status(400).json('Error: ' + err)
});
});
......
......@@ -115,7 +115,9 @@ export default class Dashboard extends Component {
<div className="dropdown-content1 dropdown-menu-right">
<button type="button" className="dropdown-item">User Account</button>
<button type="button" className="dropdown-item" style={{color:"red"}} onClick={()=>{window.location.replace("/UserLogin");}}>Sign Out</button>
<button type="button" className="dropdown-item" style={{color:"red"}} onClick={()=>{
localStorage.clear();
window.location.replace("/UserLogin");}}>Sign Out</button>
</div>
</div>
</div>
......
......@@ -6,6 +6,7 @@ import axios from "axios";
import * as configs from "../../Config/config";
import * as Icon from "react-bootstrap-icons";
import moment from "moment";
import swal from "sweetalert";
export default class TutorProfileView extends Component{
......@@ -53,10 +54,29 @@ export default class TutorProfileView extends Component{
this.onSID = this.onSID.bind(this);
this.onTutorID = this.onTutorID.bind(this);
this.submitRating = this.submitRating.bind(this);
this.getTutorRatingAndReviews = this.getTutorRatingAndReviews.bind(this);
}
componentDidMount() {
const user_email = localStorage.getItem("email");
const user_id = localStorage.getItem("userID");
const user_name = localStorage.getItem("userName");
const user_type = localStorage.getItem("userType");
if(user_id !== " "){
this.setState({
isLogged : true
})
}
this.setState({
user_email: user_email,
student_id : user_id,
user_name : user_name,
user_type : user_type
})
axios.get(configs.BASE_URL + '/tutorSingUp/' + this.state.tutor_id)
.then(response => {
console.log(response.data);
......@@ -105,53 +125,7 @@ export default class TutorProfileView extends Component{
}, () => {
axios.get(configs.BASE_URL + '/tutorRatings/' + this.state.tutor_id)
.then(response => {
console.log(response.data);
let TotalRating = 0;
let Rating5 = 0;
let Rating4 = 0;
let Rating3 = 0;
let Rating2 = 0;
let Rating1 = 0;
response.data.map((rate)=>{
TotalRating = TotalRating + Number(rate.rating);
if(Number(rate.rating) === 5){
Rating5++
}
else if(Number(rate.rating) === 4){
Rating4++
}
else if(Number(rate.rating) === 3){
Rating3++
}
else if(Number(rate.rating) === 2){
Rating2++
}
else if(Number(rate.rating) === 1){
Rating1++
}
})
console.log(TotalRating)
this.setState({
detailReviewList: response.data.sort((a,b) => b.rating - a.rating),
overRollRating : Number(TotalRating / response.data.length),
ratingCount : response.data.length,
ratingFive : Rating5,
ratingFour : Rating4,
ratingThree:Rating3,
ratingTwo: Rating2,
ratingOne: Rating1,
}, () => {
console.log(this.state.overRollRating)
})
})
this.getTutorRatingAndReviews();
})
......@@ -164,6 +138,56 @@ export default class TutorProfileView extends Component{
})
}
getTutorRatingAndReviews(){
axios.get(configs.BASE_URL + '/tutorRatings/' + this.state.tutor_id)
.then(response => {
console.log(response.data);
let TotalRating = 0;
let Rating5 = 0;
let Rating4 = 0;
let Rating3 = 0;
let Rating2 = 0;
let Rating1 = 0;
response.data.map((rate)=>{
TotalRating = TotalRating + Number(rate.rating);
if(Number(rate.rating) === 5){
Rating5++
}
else if(Number(rate.rating) === 4){
Rating4++
}
else if(Number(rate.rating) === 3){
Rating3++
}
else if(Number(rate.rating) === 2){
Rating2++
}
else if(Number(rate.rating) === 1){
Rating1++
}
})
console.log(TotalRating)
this.setState({
detailReviewList: response.data.sort((a,b) => b.rating - a.rating),
overRollRating : Number(TotalRating / response.data.length),
ratingCount : response.data.length,
ratingFive : Rating5,
ratingFour : Rating4,
ratingThree:Rating3,
ratingTwo: Rating2,
ratingOne: Rating1,
}, () => {
console.log(this.state.overRollRating)
})
})
}
onClickRatingValue(e) {
console.log(e.target.value);
this.setState({
......@@ -214,13 +238,33 @@ export default class TutorProfileView extends Component{
}
// console.log("payload");
console.log(payload);
axios.post(configs.BASE_URL + '/tutorRatings/add', payload)
.then(response => {
alert("One Review added!!!")
});
if(this.state.student_id !== null){
if(this.state.review !== ""){
if(this.state.rating !== 0){
console.log(payload);
axios.post(configs.BASE_URL + '/tutorRatings/add', payload)
.then(response => {
swal("Thank You", "Your Review Added Successfully", "success");
this.getTutorRatingAndReviews();
});
}
else {
swal("Sorry", "Please give a rating first", "warning");
}
}
else {
swal("Sorry", "Please add a review first", "warning");
}
}
else {
swal("Sorry", "You Need to Login to the system...", "warning");
}
// console.log("payload");
}
render() {
......@@ -406,7 +450,7 @@ export default class TutorProfileView extends Component{
<label>{tutorClass.class_conduct_day} - {tutorClass.class_conduct_time}</label>
</div>
<div className="col">
<button className="rounded" style={{background:'Orange', padding:'3px', width:'60px'}} value={""} onClick={e => this.onSelectOneClass(e)}>View</button>
<button className="rounded" style={{background:'Orange', padding:'3px', width:'60px'}} value={""} >View</button>
</div>
</div>
......@@ -549,7 +593,7 @@ export default class TutorProfileView extends Component{
<div className="col">
<div className="row" style={{padding: '15px'}}>
<h2 style={{marginLeft: '15px'}}><span style={{color: 'gray'}}><b
style={{fontSize: '40px', color: "black"}}>{this.state.overRollRating}</b>/5</span></h2>
style={{fontSize: '40px', color: "black"}}>{this.state.overRollRating.toFixed(1)}</b>/5</span></h2>
</div>
<div className="row">
{[...Array(5)].map((star, i) => {
......
......@@ -67,12 +67,13 @@ export default class NavBar extends Component {
color: '#EAE4E4',
marginRight: '50px'
}}><h5>{this.state.user_name !== null ? <span style={{cursor:'pointer'}} onClick={()=>{ window.location.replace("/studentDashboard");}}> {this.state.user_name}</span> : <label onClick={() => {
window.location.replace("UserLogin");
// window.location.replace("UserLogin");
window.location = '/UserLogin';
}}>Login</label>} </h5></label>
{this.state.user_name !== null && <img src={logout} onClick={() => {
localStorage.clear();
window.location.replace("/UserLogin");
}} style={{position: 'absolute', top: '10px', right: '30px', width:'40px', height:'40px',cursor:'pointer'}}/>}
window.location = '/UserLogin';
}} style={{position: 'absolute', top: '15px', right: '30px', width:'30px', height:'30px',cursor:'pointer'}}/>}
{/*{this.state.user_name !== null && <h5 onClick={() => {*/}
{/* localStorage.clear();*/}
......
......@@ -112,7 +112,9 @@ export default class StudentDashboard extends Component {
<div className="dropdown-content1 dropdown-menu-right">
<button type="button" className="dropdown-item" onClick={()=>{window.location.replace("/Home");}}>Back To Home</button>
<button type="button" className="dropdown-item" style={{color:"red"}} onClick={()=>{window.location.replace("/UserLogin");}}>Sign Out</button>
<button type="button" className="dropdown-item" style={{color:"red"}} onClick={()=>{
localStorage.clear();
window.location.replace("/UserLogin");}}>Sign Out</button>
</div>
</div>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment