diff --git a/frontend/src/Rating.jsx b/frontend/src/Rating.jsx index 36b42c3..7f9576e 100644 --- a/frontend/src/Rating.jsx +++ b/frontend/src/Rating.jsx @@ -2,8 +2,10 @@ import { useState, useEffect } from 'react'; import Axios from 'axios'; const Rating = () => { - const [TeamName, setTeamname] = useState(''); - const [UserName, setUsername] = useState(''); + const [teams, setTeams] = useState([]); + const [users, setUsers] = useState([]); + const [selectedTeam, setSelectedTeam] = useState(''); + const [selectedUser, setSelectedUser] = useState(''); const [RatingValue, setRatingValue] = useState(''); const [Comment, setComment] = useState(''); const [errorMessage, setErrorMessage] = useState(''); @@ -16,8 +18,35 @@ const Rating = () => { } else { console.warn('UserID not found in localStorage'); } + + const fetchTeams = async () => { + try { + const response = await Axios.get('http://localhost:3000/team'); + setTeams(response.data); + } catch (error) { + console.error('Error fetching teams:', error); + } + }; + + fetchTeams(); }, []); + useEffect(() => { + const fetchUsers = async () => { + if (selectedTeam) { + try { + const response = await Axios.get(`http://localhost:3000/team/users/${selectedTeam}`); + setUsers(response.data); + } catch (error) { + console.error('Error fetching users:', error); + } + } + console.log(selectedTeam) + }; + + fetchUsers(); + }, [selectedTeam]); + const addrating = async () => { try { if (!UserID) { @@ -30,22 +59,40 @@ const Rating = () => { return; } - // ดึง UserID จาก Username ที่กรอก - const userResponse = await Axios.get(`http://localhost:3000/user/UserID`, { - params: { username: UserName }, + // Fetch TeamID from TeamName + const teamResponse = await Axios.get(`http://localhost:3000/team/getTeam`, { + params: { TeamID: selectedTeam }, }); - const ratedUserID = userResponse.data.userID; + 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; } - // ตรวจสอบว่า UserID ของ Username ที่กรอกอยู่ในทีมมั้ย - const checkTeam = await Axios.post(`http://localhost:3000/team`, { - teamname: TeamName, - userid: ratedUserID, // ตรวจสอบ 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, + }, }); if (!checkTeam.data.valid) { @@ -53,50 +100,37 @@ const Rating = () => { return; } - // เพิ่ม ratedUserID ลงในตาราง userteam - await Axios.post( - `http://localhost:3000/userteam`, - { - teamname: TeamName, - ratedUserID, // UserID ของผู้ที่ได้รับคะแนน - rateByID: UserID, // UserID ของผู้ให้คะแนน - }, - { - headers: { - Authorization: `Bearer ${localStorage.getItem('token')}`, + console.log(UserID) + console.log(ratedUserID) + console.log(RatingValue) + console.log(Comment) + + // Add rating + // Add rating + await Axios.post(`http://localhost:3000/rating/rateuser`, { + ratedByID: UserID, + ratedUserID: ratedUserID, + ratingValue: RatingValue, + comment: Comment, }, - } - ); - - // add คะแนนลง userrating - await Axios.post( - `http://localhost:3000/userrating`, - { - TeamName, - UserName, - RatingValue: parseInt(RatingValue), - Comment, - ratedUserID, - rateByID: UserID, - }, - { - headers: { - Authorization: `Bearer ${localStorage.getItem('token')}`, - }, - } - ); - - // รีเซ็ตฟอร์ม - setTeamname(''); - setUsername(''); - setRatingValue(''); - setComment(''); - setErrorMessage(''); - alert('บันทึกคะแนนสำเร็จ'); - } catch (error) { - console.error('Error:', error); - setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล'); - } + { + headers: { + Authorization: `Bearer ${localStorage.getItem('token')}`, + }, + } + ); + + // Reset form + setSelectedTeam(''); + setSelectedUser(''); + setRatingValue(''); + setComment(''); + setErrorMessage(''); + alert('บันทึกคะแนนสำเร็จ'); + } catch (error) { + console.error('Error:', error); + setErrorMessage('เกิดข้อผิดพลาดในการบันทึกข้อมูล'); + } }; return ( @@ -108,20 +142,30 @@ const Rating = () => {
- setTeamname(event.target.value)} + setUsername(event.target.value)} + > + + {teams.map((team) => ( + + ))} + + { ); }; -export default Rating; +export default Rating; \ No newline at end of file diff --git a/frontend/src/Swipe.jsx b/frontend/src/Swipe.jsx index 4a45441..6229c15 100644 --- a/frontend/src/Swipe.jsx +++ b/frontend/src/Swipe.jsx @@ -113,7 +113,7 @@ const Swipe = () => { const rotation = dragDelta.x / 20; return ( -
+
{/* Header */}
diff --git a/frontend/src/components/ChatBox.jsx b/frontend/src/components/ChatBox.jsx index 73c006b..5af88f7 100644 --- a/frontend/src/components/ChatBox.jsx +++ b/frontend/src/components/ChatBox.jsx @@ -3,7 +3,6 @@ import { useState, useEffect } from 'react'; import axios from 'axios'; const ChatBox = ({ activeUser, messages, handleSendMessage }) => { - const UserID = localStorage.getItem('UserID'); const [senderImage, setSenderImage] = useState(null); const [newMessage, setNewMessage] = useState(''); @@ -34,69 +33,84 @@ const ChatBox = ({ activeUser, messages, handleSendMessage }) => { if (!activeUser) { return ( -
-

Select a chat to start messaging

+
+
+

+ Select a chat to start messaging +

+
); } return ( -
+
{/* Chat Header */} -
-

{activeUser.UserName}

+
+
+ {activeUser.UserName} +

+ {activeUser.UserName} +

+
{/* Chat Messages */} -
-
- {messages.map((msg) => ( -
- {msg.SenderID === activeUser.UserID ? ( - <> -
- {activeUser.UserName} -
- {msg.MessageContent} +
+
+ {messages.map((msg) => ( +
+ {msg.SenderID === activeUser.UserID ? ( +
+ {activeUser.UserName} +
+ {msg.MessageContent} +
-
- - ) : ( - <> -
-
- {msg.MessageContent} + ) : ( +
+
+ {msg.MessageContent} +
+ Sender
- {senderImage} -
- - )} -
- ))} -
+ )} +
+ ))}
+
- {/* Message Input */} -
-
+ {/* Message Input */} +
+ setNewMessage(e.target.value)} placeholder="Type a message..." - className="w-full border rounded-md p-2 focus:outline-none focus:ring-2 focus:ring-blue-500" + className="w-full border rounded-full p-3 focus:outline-none focus:ring-2 focus:ring-blue-500 transition-all duration-300 hover:shadow-md" /> @@ -111,7 +125,6 @@ ChatBox.propTypes = { UserID: PropTypes.string.isRequired, UserName: PropTypes.string.isRequired, ProfileImage: PropTypes.string.isRequired, - MessageContent: PropTypes.string.isRequired, }), messages: PropTypes.arrayOf( PropTypes.shape({ diff --git a/frontend/src/components/ChatList.jsx b/frontend/src/components/ChatList.jsx index ea1544d..afe10f8 100644 --- a/frontend/src/components/ChatList.jsx +++ b/frontend/src/components/ChatList.jsx @@ -2,32 +2,156 @@ import PropTypes from 'prop-types'; const ChatList = ({ chats, onSelectChat }) => { return ( -
-

Chats

-
    +
    + {/* Header with Gradient and Animated Title */} +

    + + + + + Chats + + ({chats.length}) +

    + + {/* Chat List with Enhanced Interactions */} +
      {chats.map((chat) => (
    • onSelectChat(chat)} - className="p-4 border-b hover:bg-gray-200 cursor-pointer flex items-center" + className=" + p-4 + flex items-center + cursor-pointer + group + transition-all + duration-300 + ease-in-out + hover:bg-gradient-to-r + hover:from-blue-50 + hover:to-purple-50 + transform + hover:-translate-y-1 + hover:shadow-lg + relative + overflow-hidden + " > - {`${chat.UserName}'s -
      -

      {chat.UserName}

      -

      {chat.MessageContent}

      + {/* Subtle Background Hover Effect */} +
      + + {/* Profile Image with Hover Effect */} +
      + {`${chat.UserName}'s + {/* Online Status Indicator */} + +
      + + {/* Chat Info */} +
      +
      +

      + {chat.UserName} +

      +

      + {/* You could add timestamp here */} + Just now +

      +
      +

      + {chat.MessageContent} +

      + + {/* Unread Messages Badge with Animated Pulse */} {chat.UnreadMessages > 0 && ( - + {chat.UnreadMessages} )}
    • ))}
    + + {/* Empty State */} + {chats.length === 0 && ( +
    + + + + No chats yet +
    + )}
    ); }; diff --git a/frontend/src/profile.jsx b/frontend/src/profile.jsx index 660f8b8..5249ff8 100644 --- a/frontend/src/profile.jsx +++ b/frontend/src/profile.jsx @@ -4,7 +4,7 @@ import { MdEmail } from "react-icons/md"; import Axios from 'axios'; import PropTypes from 'prop-types'; import Swal from 'sweetalert2' -import image from '../../public/uploads/profiles/5psgeommk-b1715b66-2c24-49ee-b16e-37ab0ba43ea0.jpeg' +// import image from '../../public/uploads/profiles/5psgeommk-b1715b66-2c24-49ee-b16e-37ab0ba43ea0.jpeg' // EditProfileModal component const EditProfileModal = ({ isOpen, onClose, onSave, user }) => { @@ -566,7 +566,7 @@ const Profile = () => { flex items-center justify-center overflow-hidden"> {user.ProfileImage ? ( Profile { + +// Rate someone +.post("/rateuser", async ({ body, error }) => { const { ratedByID, ratedUserID, ratingValue, comment } = body; // Check if the user exists @@ -71,6 +72,8 @@ ratingController.post("/", async ({ body, error }) => { }), }) +// Other endpoints... + // Update rating .put("/:userRatingID", async ({ params, body, error }) => { const { userRatingID } = params; diff --git a/src/controllers/teamController.ts b/src/controllers/teamController.ts index cd94c5b..7800cab 100644 --- a/src/controllers/teamController.ts +++ b/src/controllers/teamController.ts @@ -8,12 +8,33 @@ export const teamController = new Elysia({ prefix: "/team" }) return teams; }) -// Get TeamID from name and hackathon -.get("/find", async ({ query: { teamName, hackathonID }, error }) => { +// Get users in a team +.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 Team by TeamID +.get("/getTeam", async ({ query: { TeamID }, error }) => { const team = await prisma.team.findFirst({ where: { - TeamName: teamName, - HackathonID: hackathonID, + TeamID: TeamID, }, }); @@ -24,11 +45,11 @@ export const teamController = new Elysia({ prefix: "/team" }) return team; }, { query: t.Object({ - teamName: t.String(), - hackathonID: t.Number(), + TeamID: t.Number(), }), }) +<<<<<<< HEAD .get("/findteambyuser/:userID", async ({ params, error }) => { const team = await prisma.userTeam.findMany({ @@ -49,6 +70,52 @@ export const teamController = new Elysia({ prefix: "/team" }) }) +======= +// 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 teamMember = await prisma.userTeam.findFirst({ + where: { + TeamID: TeamID, + UserID: UserID, + }, + }); + + if (!teamMember) { + return error(404, "User is not part of the team"); + } + + 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(), + }), + }) +>>>>>>> 0c457d5157841e83fd2b56984d6e5332b4c37aeb .get("/finduserteam/:teamID", async ({ params, error }) => { const teamID = parseInt(params.teamID, 10); // Ensure teamID is a number if (isNaN(teamID)) { diff --git a/src/controllers/userController.ts b/src/controllers/userController.ts index 00f0188..39a795e 100644 --- a/src/controllers/userController.ts +++ b/src/controllers/userController.ts @@ -255,6 +255,27 @@ export const userController = new Elysia({ prefix: "/user" }) return users; // Return all users with related skills and notifications }) + + // Get user details from Username + .get("/getUserID/:UserID", async ({params, error }) => { + const user = await prisma.user.findFirst({ + where: { + UserID: params.UserID, + }, + }); + + if (!user) { + return error(404, "User not found"); + } + + return { UserID : user.UserID , UserName : user.UserName}; + }, { + params: t.Object({ + UserID: t.String(), + }), + }) + + // Delete user profile .delete( "/:userID", @@ -280,4 +301,10 @@ export const userController = new Elysia({ prefix: "/user" }) userID: t.String(), }), } - ); \ No newline at end of file + ); + + + + // .get ( + // "/GetId", + // ) \ No newline at end of file