diff --git a/frontend/src/eventdetail.jsx b/frontend/src/eventdetail.jsx
index b7d6fe7..f8d92af 100644
--- a/frontend/src/eventdetail.jsx
+++ b/frontend/src/eventdetail.jsx
@@ -26,7 +26,74 @@ const EventDetail = () => {
useEffect(() => {
console.log('member:', member);
}, [member]);
+
+ const checkteam = async (TeamID) => {
+ try {
+ const responsed = await Axios.get(`http://localhost:3000/team/finduserteam/${TeamID}`);
+ const team = responsed.data;
+ const currentUser = team.find(member => member.UserID === UserID);
+ if (currentUser) {
+ Swal.fire({
+ title: "Sorry",
+ text: "You are in the team !",
+ icon: "error"
+ });
+ setTimeout(() => {
+ Swal.close();
+ }, 3000);
+
+ await new Promise(resolve => setTimeout(resolve, 2000));
+ window.location.href = `/EventDetail/${HackathonID}`;}
+ } catch (error) {
+ console.error("Error deleting from team:", error);
+ }
+ }
+
+
+ const deleteteam = async (TeamID) => {
+ try {
+ const responsed = await Axios.get(`http://localhost:3000/team/finduserteam/${TeamID}`);
+ const team = responsed.data;
+ const currentUser = team.find(member => member.UserID === UserID);
+ if (currentUser) {
+ setCurrentUserRole(currentUser.role)}
+
+ if (currentUserRole === 'head'){
+ const response = await Axios.delete(`http://localhost:3000/team/delete/${TeamID}`,TeamID);
+ console.log('Delete response:', response.data);
+ Swal.fire({
+ title: "Congratulation",
+ text: "Delete team success !",
+ icon: "success"
+ });
+ setTimeout(() => {
+ Swal.close();
+ }, 3000);
+
+ await new Promise(resolve => setTimeout(resolve, 2000));
+
+ window.location.href = `/EventDetail/${HackathonID}`;
+ }
+ else{
+ Swal.fire({
+ title: "Sorry",
+ text: "You don't have permission to delete team !",
+ icon: "error"
+ });
+ setTimeout(() => {
+ Swal.close();
+ }, 3000);
+
+ await new Promise(resolve => setTimeout(resolve, 2000));
+
+ window.location.href = `/EventDetail/${HackathonID}`;
+ }} catch (error) {
+ console.error("Error deleting from team:", error);
+ }
+ }
+
+ //delete members from team
const deletefromteam = async (TeamID, UserID) => {
try {
const response = await Axios.delete(`http://localhost:3000/team/removeMember`, {
@@ -43,9 +110,9 @@ const EventDetail = () => {
});
setTimeout(() => {
Swal.close();
- }, 3000);
+ }, 1000);
- await new Promise(resolve => setTimeout(resolve, 2000));
+ await new Promise(resolve => setTimeout(resolve, 1000));
window.location.href = `/EventDetail/${HackathonID}`;
} catch (error) {
@@ -99,6 +166,19 @@ const EventDetail = () => {
window.location.href = `/EventDetail/${HackathonID}`;
}
else{
+
+ const payloadt = {
+ teamID: TeamID,
+ userID: UserID,
+ role: role
+ };
+ console.log('Payload:', payloadt);
+ await Axios.post('http://localhost:3000/team/addMember', payloadt);
+ setuserTeamlist((prev) => [
+ ...prev,
+ { teamID: TeamID, userID: UserID, role: role },
+ ]);
+
Swal.fire({
title: "Good job!",
text: "Join team Sucessful!",
@@ -112,18 +192,6 @@ const EventDetail = () => {
// localStorage.setItem('UserID', JSON.stringify(response.data.UserID));
window.location.href = `/EventDetail/${HackathonID}`;
-
- const payloadt = {
- teamID: TeamID,
- userID: UserID,
- role: role
- };
- console.log('Payload:', payloadt);
- await Axios.post('http://localhost:3000/team/addMember', payloadt);
- setuserTeamlist((prev) => [
- ...prev,
- { teamID: TeamID, userID: UserID, role: role },
- ]);
}
} catch (error) {
console.error("Error joining team:", error);
@@ -166,6 +234,18 @@ const addteam = async () => {
]);
console.log('Team created successfully');
+ Swal.fire({
+ title: "Congratulation",
+ text: "Create team success !",
+ icon: "success"
+ });
+ setTimeout(() => {
+ Swal.close();
+ }, 3000);
+
+ await new Promise(resolve => setTimeout(resolve, 2000));
+
+ window.location.href = `/EventDetail/${HackathonID}`;
} catch (error) {
console.error('Error creating team:', error.response?.data || error.message);
}
@@ -264,6 +344,19 @@ const addteam = async () => {
👥 {val.CurrentMember}/{val.MaxMember}
Team {val.TeamName}
+
+
+
+
+
+
+
+