Skip to content

Commit

Permalink
decorate eventdetail
Browse files Browse the repository at this point in the history
  • Loading branch information
kirigayaxy committed Nov 27, 2024
2 parents e46220c + b9ece08 commit db10c23
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 79 deletions.
49 changes: 24 additions & 25 deletions frontend/src/Rating.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,34 @@ const Rating = () => {

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

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

// Reset form
setSelectedTeam('');
setSelectedUser('');
setRatingValue('');
setComment('');
setErrorMessage('');
alert('บันทึกคะแนนสำเร็จ');
} catch (error) {
console.error('Error:', error);
setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล');
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('');
alert('บันทึกคะแนนสำเร็จ');
} catch (error) {
console.error('Error:', error);
setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล');
}
};

return (
Expand Down
53 changes: 45 additions & 8 deletions frontend/src/eventdetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const EventDetail = () => {
const [isCreateTeamModalOpen, setIsCreateTeamModalOpen] = useState(false);
const [isjoinTeamModalOpen, setIsjoinTeamModalOpen] = useState([false,'']);
const [isleaveTeamModalOpen, setleaveTeamModalOpen] = useState([false,'']);
const [isshowTeamModalOpen, setshowTeamModalOpen] = useState([false,'']);
const [Teamlist, setTeamlist] = useState([]);
const [userTeamlist, setuserTeamlist] = useState([]);
const [member, setmember] = useState([]);
Expand Down Expand Up @@ -332,14 +333,19 @@ const addteam = async () => {
))}

{/* Teams Section */}
<div id="teamlist" className="px-8 py-16 lg:px-24 bg-white">
<div id="teamlist" className="px-8 py-16 lg:px-24 bg-white ">
<h2 className="text-3xl font-bold text-gray-800 mb-6">
ทีมที่เปิดรับสมาชิก
</h2>
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-8">

{Teamlist.map((val, key) => (
<div key={key} className="relative bg-gray-100 rounded-lg p-6 shadow-md hover:shadow-lg transition">
<div key={key} className="relative bg-gray-100 rounded-lg p-6 shadow-md hover:shadow-lg transition"
onClick={async () => {
await setshowTeamModalOpen([true, val.TeamID])
showmember(val.TeamID)
}}
>
<div className="absolute top-4 left-4 text-gray-700 text-sm font-semibold py-1 px-3 rounded-full shadow-md">
<span>👥 {val.CurrentMember}/{val.MaxMember}</span>
</div>
Expand Down Expand Up @@ -381,20 +387,51 @@ const addteam = async () => {

</div>
))}

{isshowTeamModalOpen[0] == true && (
<div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div className="w-full max-w-lg bg-gradient-to-b from-blue-500 to-sky-500 text-white rounded-lg p-6 shadow-lg">
<h1 className="text-3xl font-bold text-center mb-6 ">member</h1>

{member.map((val,key) => (
<div key={key} className="flex justify-between items-center">

<p className="font-semibold text-lg">Username: {val.userName}</p>
<p className="text-lg">Role: {val.role}</p>




</div>
))}

{/* Buttons */}

<div className="flex justify-between mt-6">
<button
onClick={() => setshowTeamModalOpen(false)}
className="w-1/3 h-12 bg-gray-300 text-black font-bold rounded-full shadow-md hover:bg-gray-400 transition duration-300"
>
Close
</button>

</div>
</div>
</div>
)}

{/* leave team popup */}
{isleaveTeamModalOpen[0] == true && (
<div className="fixed inset-0 flex items-center justify-center bg-black bg-opacity-50 z-50">
<div className="w-full max-w-lg bg-gradient-to-b from-blue-500 to-sky-500 text-white rounded-lg p-6 shadow-lg">
<h1 className="text-3xl font-bold text-center mb-6 ">Show member</h1>
<h1 className="text-3xl font-bold text-center mb-6 ">member</h1>

{member.filter(val => val.userID !== UserID).map((val,key) => (
<div key={key} className="flex justify-between items-center">
<div>
<h3>{val.teamID}</h3>
<p>UserID: {val.userID}</p>
<p>Username: {val.userName}</p>
</div>

<p className="font-semibold text-lg">Username: {val.userName}</p>
<p className="text-lg">Role: {val.role}</p>


{currentUserRole === 'head' && (
<button
Expand Down
138 changes: 92 additions & 46 deletions src/controllers/teamController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ export const teamController = new Elysia({ prefix: "/team" })
return teams;
})


.get("/getTeam", async ({ query: { TeamID }, error }) => {
const team = await prisma.team.findFirst({
where: {
TeamID: TeamID,
},
});

if (!team) {
return error(404, "Team not found");
}

return team;
}, {
query: t.Object({
TeamID: t.Number(),
}),
})

.get("/users/:teamID", async ({ params: { teamID }, error }) => {
const users = await prisma.userTeam.findMany({
where: {
TeamID: parseInt(teamID, 10),
},
include: {
User: true,
},
});

if (!users || users.length === 0) {
return error(404, "Users not found");
}

return users.map(userTeam => userTeam.User);
}, {
params: t.Object({
teamID: t.String(),
}),
})

// Get TeamID from name and hackathon
.get("/find", async ({ query: { teamName, hackathonID }, error }) => {
const team = await prisma.team.findFirst({
Expand All @@ -29,24 +69,51 @@ export const teamController = new Elysia({ prefix: "/team" })
}),
})

// .get("/findteambyuser/:userID", async ({ params, error }) => {
// Check if a user is part of a team
.get("/checkteam", async ({ query: { TeamID, UserID }, error }) => {
if (!TeamID || !UserID) {
return error(400, "TeamID and UserID are required");
}

// const team = await prisma.userTeam.findMany({
// where: {
// UserID: params.userID,
// },
// });
const teamMember = await prisma.userTeam.findFirst({
where: {
TeamID: TeamID,
UserID: UserID,
},
});

// if (!team || team.length === 0) {
// return error(404, "Team not found");
// }
if (!teamMember) {
return error(404, "User is not part of the team");
}

// return team;
// }, {
// params: t.Object({
// userID: t.String(), // userID is a string in the URL params
// }),
// })
return { valid: true };
}, {
query: t.Object({
TeamID: t.Number(),
UserID: t.String(),
}),
})

// Other endpoints...
// Get TeamID from TeamName
.get("/getTeamID", async ({ query: { TeamName }, error }) => {
const team = await prisma.team.findFirst({
where: {
TeamName: TeamName,
},
});

if (!team) {
return error(404, "Team not found");
}

return {TeamID: team.TeamID};
}, {
query: t.Object({
TeamName: t.String(),
}),
})

.get("/finduserteam/:teamID", async ({ params, error }) => {
const teamID = parseInt(params.teamID, 10); // Ensure teamID is a number
if (isNaN(teamID)) {
Expand Down Expand Up @@ -150,40 +217,19 @@ export const teamController = new Elysia({ prefix: "/team" })
}),
})

.delete('/delete/:teamID', async ({ params, error }) => {
.delete("/delete/:teamID", async ({ params, error }) => {
const { teamID } = params;

try {
const teamIDNumber = parseInt(teamID, 10); // Ensure teamID is a number
if (isNaN(teamIDNumber)) {
return error(400, 'Invalid teamID');
}

const team = await prisma.team.findUnique({
where: { TeamID: teamIDNumber },
});


if (!team) {
return error(404, 'Team not found');
}
await prisma.userTeam.deleteMany({
where: { TeamID: teamIDNumber },
})
await prisma.team.delete({
where: { TeamID: teamIDNumber },
});

return { message: 'Team deleted successfully' };
} catch (err) {
console.error('Error deleting team:', err);
return error(500, 'Internal Server Error');
}
}, {

const team = await prisma.team.delete({
where: { TeamID: teamID },
});

return team;
}, {
params: t.Object({
teamID: t.String(), // teamID is a string in the URL params
teamID: t.Number(),
}),
})
})

.post("/addMember", async ({ body, error }) => {
const { teamID, userID, role } = body;
Expand Down

0 comments on commit db10c23

Please sign in to comment.