Skip to content

Commit

Permalink
Feat: 파트장 투표하기 기능 API 연결 및 투표, 중복투표시 alert창 띄우기
Browse files Browse the repository at this point in the history
  • Loading branch information
geeoneee committed Dec 25, 2023
1 parent 3a59ae8 commit dbe40f6
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 21 deletions.
10 changes: 10 additions & 0 deletions src/features/vote/queries/usePatchMemVote.tsx
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/pages/vote/VoteDemoday.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -34,7 +34,7 @@ const VoteDemoday = () => {

const handleVoteClick = async (teamId: number) => {
try {
await usePatchVote(teamId);
await usePatchTeamVote(teamId);
} catch (error) {
alert("투표는 한 번만 가능합니다.");
}
Expand Down
49 changes: 31 additions & 18 deletions src/pages/vote/VoteLeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 } });
Expand All @@ -38,13 +51,13 @@ const VoteLeader = () => {
addClass="margin-bottom:3.2rem;"
/>
<LeaderContainer $isMobile={isMobile}>
{leaders.map((leader, index) => (
{data.map((leader, index) => (
<VoteSelect
key={index}
type={SELECT_TYPE.PartLeader}
mainText={leader.mainText}
subText={leader.subText}
onClick={voteLeaderSelectClicked}
mainText={leader.name}
subText={leader.teamName}
onClick={() => handleVoteClick(leader.id)}
/>
))}
</LeaderContainer>
Expand Down

0 comments on commit dbe40f6

Please sign in to comment.