From dbe40f6435c13ebfb289e9986b4568bf8d60ff78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=80=E1=85=B5=E1=86=B7=E1=84=8C=E1=85=B5=E1=84=8B?= =?UTF-8?q?=E1=85=AF=E1=86=AB?= Date: Tue, 26 Dec 2023 02:31:10 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=8C=8C=ED=8A=B8=EC=9E=A5=20=ED=88=AC?= =?UTF-8?q?=ED=91=9C=ED=95=98=EA=B8=B0=20=EA=B8=B0=EB=8A=A5=20API=20?= =?UTF-8?q?=EC=97=B0=EA=B2=B0=20=EB=B0=8F=20=ED=88=AC=ED=91=9C,=20?= =?UTF-8?q?=EC=A4=91=EB=B3=B5=ED=88=AC=ED=91=9C=EC=8B=9C=20alert=EC=B0=BD?= =?UTF-8?q?=20=EB=9D=84=EC=9A=B0=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/features/vote/queries/usePatchMemVote.tsx | 10 ++++ ...{usePatchVote.tsx => usePatchTeamVote.tsx} | 2 +- src/pages/vote/VoteDemoday.tsx | 4 +- src/pages/vote/VoteLeader.tsx | 49 ++++++++++++------- 4 files changed, 44 insertions(+), 21 deletions(-) create mode 100644 src/features/vote/queries/usePatchMemVote.tsx rename src/features/vote/queries/{usePatchVote.tsx => usePatchTeamVote.tsx} (76%) diff --git a/src/features/vote/queries/usePatchMemVote.tsx b/src/features/vote/queries/usePatchMemVote.tsx new file mode 100644 index 0000000..4018803 --- /dev/null +++ b/src/features/vote/queries/usePatchMemVote.tsx @@ -0,0 +1,10 @@ +import { axiosInstance } from "@/common/libs/axios"; + +export default async function usePatchMemVote(memberId: number) { + try { + const response = await axiosInstance.patch(`/app/member/${memberId}/vote`); + return response.data; + } catch (error) { + throw error; + } +} diff --git a/src/features/vote/queries/usePatchVote.tsx b/src/features/vote/queries/usePatchTeamVote.tsx similarity index 76% rename from src/features/vote/queries/usePatchVote.tsx rename to src/features/vote/queries/usePatchTeamVote.tsx index ac8c096..2a9d08e 100644 --- a/src/features/vote/queries/usePatchVote.tsx +++ b/src/features/vote/queries/usePatchTeamVote.tsx @@ -1,6 +1,6 @@ import { axiosInstance } from "@/common/libs/axios"; -export default async function usePatchVote(teamId: number) { +export default async function usePatchTeamVote(teamId: number) { try { const response = await axiosInstance.patch(`/app/team/${teamId}/vote`); return response.data; diff --git a/src/pages/vote/VoteDemoday.tsx b/src/pages/vote/VoteDemoday.tsx index e8af458..3eb95a2 100644 --- a/src/pages/vote/VoteDemoday.tsx +++ b/src/pages/vote/VoteDemoday.tsx @@ -7,7 +7,7 @@ import { SELECT_TYPE } from "@/features/vote/constants/select-vote-type"; import { styled } from "styled-components"; import React, { useState, useEffect } from "react"; import useGetResults from "@/features/vote/queries/useGetResults"; -import usePatchVote from "@/features/vote/queries/usePatchVote"; +import usePatchTeamVote from "@/features/vote/queries/usePatchTeamVote"; const VoteDemoday = () => { const { isMobile } = MediaQuery(); @@ -34,7 +34,7 @@ const VoteDemoday = () => { const handleVoteClick = async (teamId: number) => { try { - await usePatchVote(teamId); + await usePatchTeamVote(teamId); } catch (error) { alert("투표는 한 번만 가능합니다."); } diff --git a/src/pages/vote/VoteLeader.tsx b/src/pages/vote/VoteLeader.tsx index b4c51e0..662c238 100644 --- a/src/pages/vote/VoteLeader.tsx +++ b/src/pages/vote/VoteLeader.tsx @@ -5,27 +5,40 @@ import MediaQuery from "@/styles/mediaQuery"; import { SELECT_TYPE } from "@/features/vote/constants/select-vote-type"; import { styled } from "styled-components"; import { useLocation, useNavigate } from "react-router-dom"; +import React, { useState, useEffect } from "react"; +import useGetResults from "@/features/vote/queries/useGetResults"; +import usePatchMemVote from "@/features/vote/queries/usePatchMemVote"; const VoteLeader = () => { const { isMobile } = MediaQuery(); const navigate = useNavigate(); const location = useLocation(); const part = location.state; - const voteLeaderSelectClicked = (mainText: string) => { - console.log(mainText); + + const [data, setData] = useState([]); + useEffect(() => { + const devPartId = part === "BE" ? 1 : 2; + const url = `/app/member?devPartId=${devPartId}`; + + useGetResults(url) + .then((resultData) => { + const data = resultData.data; + setData(data); + console.log(data); + }) + .catch((error) => { + console.error("데이터를 불러오는 중 에러 발생:", error); + }); + }, []); + + const handleVoteClick = async (memberId: number) => { + try { + await usePatchMemVote(memberId); + alert("투표되었습니다."); + } catch (error) { + alert("투표는 한 번만 가능합니다."); + } }; - const leaders = [ - { mainText: "김현민", subText: "LocalMood" }, - { mainText: "김지원", subText: "LocalMood" }, - { mainText: "노이진", subText: "Reddigg" }, - { mainText: "신동현", subText: "Reddigg" }, - { mainText: "정인영", subText: "셰어마인드" }, - { mainText: "이규호", subText: "셰어마인드" }, - { mainText: "변지혜", subText: "Gotcha" }, - { mainText: "이은비", subText: "Gotcha" }, - { mainText: "오대균", subText: "Sniff" }, - { mainText: "송지석", subText: "Sniff" }, - ]; //API 연결 const navigateLeaderVoteResults = () => { navigate("/vote-results", { state: { type: "leader", part } }); @@ -38,13 +51,13 @@ const VoteLeader = () => { addClass="margin-bottom:3.2rem;" /> - {leaders.map((leader, index) => ( + {data.map((leader, index) => ( handleVoteClick(leader.id)} /> ))}