Skip to content

Commit

Permalink
update schema team userteam and decorate hackathon page
Browse files Browse the repository at this point in the history
  • Loading branch information
satanakorn committed Dec 7, 2024
1 parent b813803 commit c4cac55
Show file tree
Hide file tree
Showing 19 changed files with 1,097 additions and 704 deletions.
Binary file modified bun.lockb
Binary file not shown.
116 changes: 84 additions & 32 deletions frontend/src/Dashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,49 @@ const Dashboard = () => {
window.location.href = '/AllUsers';
}


// Add the following function inside the Dashboard component

const deleteHackathon = async (hackathonID, hackathonName) => {
const result = await Swal.fire({
title: `Delete ${hackathonName}?`,
text: "Are you sure you want to delete this hackathon?",
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
confirmButtonText: "Yes, delete it!",
});

if (result.isConfirmed) {
try {
await Axios.delete('http://localhost:3000/hackathon/delete', {
data: { id: hackathonID },
});

Swal.fire({
title: "Deleted!",
text: `${hackathonName} has been deleted.`,
icon: "success",
timer: 2000,
showConfirmButton: false,
});

// Refresh hackathons list
const response = await Axios.get('http://localhost:3000/hackathon');
setHackathons(response.data);
} catch (error) {
console.error(`Error deleting ${hackathonName}:`, error);
Swal.fire({
title: "Error",
text: `There was an error deleting ${hackathonName}.`,
icon: "error",
});
}
}
};


return (
<div className="min-h-screen bg-gradient-to-br from-gray-100 to-gray-200 p-8">
<div className="max-w-6xl mx-auto space-y-8">
Expand Down Expand Up @@ -238,38 +281,47 @@ const Dashboard = () => {
</div>
</div>

{/* Hackathons Section */}
<div className="bg-white rounded-xl shadow-xl p-8 transform hover:shadow-2xl transition-all duration-300">
<h2 className="text-2xl font-semibold mb-6 text-gray-800 border-b pb-4 relative">
Hackathon Management
<span className="absolute bottom-0 left-0 w-1/4 h-1 bg-gradient-to-r from-blue-400 to-indigo-500"></span>
</h2>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
{hackathons.map((hackathon) => (
<div key={hackathon.HackathonID} className="relative group perspective-1000">
<button
className="w-full group flex flex-col items-center justify-center p-6 bg-gradient-to-r from-blue-500 to-indigo-600 hover:from-blue-400 hover:to-indigo-500 text-white rounded-xl transition-all duration-500 transform hover:scale-110 hover:rotate-2 hover:shadow-xl backdrop-blur-sm"
>
<span className="text-3xl mb-3 transform group-hover:scale-125 group-hover:rotate-12 transition-transform duration-300">
🏆
</span>
<span className="font-semibold tracking-wide group-hover:text-blue-100">
{hackathon.Name}
</span>
</button>
</div>
))}
<button
onClick={handleAddHackathon}
className="group flex flex-col items-center justify-center p-6 bg-gradient-to-r from-indigo-500 to-indigo-600 hover:from-indigo-400 hover:to-blue-500 text-white rounded-xl transition-all duration-500 transform hover:scale-110 hover:-rotate-2 hover:shadow-xl"
>
<span className="text-3xl mb-3 transform group-hover:rotate-180 transition-transform duration-500"></span>
<span className="font-semibold tracking-wide group-hover:text-indigo-100">
Add more hackathon
</span>
</button>
</div>
</div>

{/* Hackathons Section */}
<div className="bg-white rounded-xl shadow-xl p-8 transform hover:shadow-2xl transition-all duration-300">
<h2 className="text-2xl font-semibold mb-6 text-gray-800 border-b pb-4 relative">
Hackathon Management
<span className="absolute bottom-0 left-0 w-1/4 h-1 bg-gradient-to-r from-blue-400 to-indigo-500"></span>
</h2>
<div className="grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 gap-6">
{hackathons.map((hackathon) => (
<div key={hackathon.HackathonID} className="relative group perspective-1000">
<button
className="w-full group flex flex-col items-center justify-center p-6 bg-gradient-to-r from-blue-500 to-indigo-600 hover:from-blue-400 hover:to-indigo-500 text-white rounded-xl transition-all duration-500 transform hover:scale-110 hover:rotate-2 hover:shadow-xl backdrop-blur-sm"
>
<span className="text-3xl mb-3 transform group-hover:scale-125 group-hover:rotate-12 transition-transform duration-300">
🏆
</span>
<span className="font-semibold tracking-wide group-hover:text-blue-100">
{hackathon.Name}
</span>
</button>
<button
onClick={() => deleteHackathon(hackathon.HackathonID, hackathon.Name)}
className="absolute -top-2 -right-2 bg-red-500 text-white rounded-full p-2 opacity-0 group-hover:opacity-100 transform scale-75 group-hover:scale-100 transition-all duration-300 hover:bg-red-600 hover:rotate-90 shadow-lg"
>
<svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
))}
<button
onClick={handleAddHackathon}
className="group flex flex-col items-center justify-center p-6 bg-gradient-to-r from-indigo-500 to-indigo-600 hover:from-indigo-400 hover:to-blue-500 text-white rounded-xl transition-all duration-500 transform hover:scale-110 hover:-rotate-2 hover:shadow-xl"
>
<span className="text-3xl mb-3 transform group-hover:rotate-180 transition-transform duration-500"></span>
<span className="font-semibold tracking-wide group-hover:text-indigo-100">
Add more hackathon
</span>
</button>
</div>
</div>

{/* Users Section */}
<div className="bg-white rounded-xl shadow-xl p-8">
Expand Down
154 changes: 81 additions & 73 deletions frontend/src/Rating.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,113 +54,121 @@ const Rating = () => {
setErrorMessage('คุณต้องล็อกอินก่อนเพื่อให้คะแนน');
return;
}

if (RatingValue < 1 || RatingValue > 5) {
setErrorMessage('กรุณากรอกคะแนนระหว่าง 1 ถึง 5 เป็นจำนวนเต็ม');
return;
}


// Prevent self-rating on frontend
// Fetch UserID from Username
if (selectedUser === UserID) {
setErrorMessage('คุณไม่สามารถให้คะแนนตัวเองได้');
return;
}

// Fetch TeamID from TeamName
const teamResponse = await Axios.get(`http://localhost:3000/team/getTeam`, {
params: { TeamID: selectedTeam },
});

const TeamID = teamResponse.data.TeamID;

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

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

// Fetch UserID from Username
const userResponse = await Axios.get(`http://localhost:3000/user/getUserID/${selectedUser}`);

console.log(userResponse.data);



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`, {
// Check if the user is part of the team
const checkTeam = await Axios.get(`http://localhost:3000/team/checkteam`, {
params: {
TeamID: TeamID,
UserID: UserID,
},
});




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



// Add rating
await Axios.post(`http://localhost:3000/rating/rateuser`, {
ratedByID: UserID,
ratedUserID: ratedUserID,
ratingValue: parseInt(RatingValue),
comment: Comment,
},
{
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`,
},
}
);

// Reset form
setSelectedTeam('');
setSelectedUser('');
setRatingValue('');
setComment('');
setErrorMessage('');

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 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';
// **Check for existing rating**
const existingRating = await Axios.get(`http://localhost:3000/rating/${ratedUserID}`, {
params: { ratedUserID },
});

const hasRated = existingRating.data.some(
(rating) => rating.RatedByID === UserID && rating.RatedUserID === ratedUserID
);

if (hasRated) {
setErrorMessage('You have rated this user.');
return;
}

// Add rating
await Axios.post(`http://localhost:3000/rating/rateuser`, {
ratedByID: UserID,
ratedUserID: ratedUserID,
ratingValue: parseInt(RatingValue),
comment: Comment,
},
{
headers: {
Authorization: `Bearer ${localStorage.getItem('token')}`,
},
}
};
);

// Reset form
setSelectedTeam('');
setSelectedUser('');
setRatingValue('');
setComment('');
setErrorMessage('');

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

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

window.location.href = '/Rating';

} catch (error) {
console.error('Error adding rating:', error);
Swal.fire({
title: "Error!",
text: "You cannot rate this user!!",
icon: "error"
});
setTimeout(() => {
Swal.close();
}, 3000);

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

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

return (
<div className="min-h-screen bg-gradient-to-r from-blue-200 to-indigo-400 flex items-center justify-center p-4">
Expand Down
Loading

0 comments on commit c4cac55

Please sign in to comment.