Skip to content

Commit

Permalink
add rathing and check member of team in yet?
Browse files Browse the repository at this point in the history
  • Loading branch information
satanakorn committed Nov 27, 2024
1 parent b9ece08 commit f66e3b7
Showing 1 changed file with 40 additions and 10 deletions.
50 changes: 40 additions & 10 deletions frontend/src/Rating.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect } from 'react';
import Axios from 'axios';
import Swal from 'sweetalert2'

const Rating = () => {
const [teams, setTeams] = useState([]);
Expand Down Expand Up @@ -72,7 +73,7 @@ const Rating = () => {
}

// // Store TeamID in local storage
// localStorage.setItem('TeamID', TeamID);
localStorage.setItem('TeamID', TeamID);

// Fetch UserID from Username
const userResponse = await Axios.get(`http://localhost:3000/user/getUserID/${selectedUser}`);
Expand All @@ -81,29 +82,33 @@ const Rating = () => {


const ratedUserID = userResponse.data.UserID;



if (!ratedUserID) {
setErrorMessage('ไม่พบ UserID ของ Username นี้');
return;
}

console.log(ratedUserID)
console.log(UserID)

// Check if the user is part of the team
const checkTeam = await Axios.get(`http://localhost:3000/team/checkteam`, {
params: {
TeamID: TeamID,
UserID: ratedUserID,
UserID: UserID,
},
});



if (!checkTeam.data.valid) {
setErrorMessage('คุณไม่ได้อยู่ทีมเดียวกัน กรุณาลองใหม่อีกครั้ง');
setErrorMessage('คุณไม่ได้เป็นสมาชิกของทีมนี้');
return;
}

console.log(UserID)
console.log(ratedUserID)
console.log(typeof RatingValue);
console.log(Comment)


// Add rating
await Axios.post(`http://localhost:3000/rating/rateuser`, {
Expand All @@ -125,10 +130,35 @@ const Rating = () => {
setRatingValue('');
setComment('');
setErrorMessage('');
alert('บันทึกคะแนนสำเร็จ');

Swal.fire({
title: "Good job!",
text: " Add rating sucessfully!",
icon: "success"
});
setTimeout(() => {
Swal.close();
}, 3000);

await new Promise(resolve => setTimeout(resolve, 2000));

window.location.href = '/Rating';


} catch (error) {
console.error('Error:', error);
setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล');
console.error('Error adding rating:', error);
Swal.fire({
title: "Error!",
text: "ํYou're not a member of this team!",
icon: "error"
});
setTimeout(() => {
Swal.close();
}, 3000);

await new Promise(resolve => setTimeout(resolve, 2000));

window.location.href = '/Rating';
}
};

Expand Down

0 comments on commit f66e3b7

Please sign in to comment.