Skip to content

Commit

Permalink
Refactor: useGetVote params 변경, 배경색 css 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
goeun208 committed Mar 28, 2024
1 parent 946e6d7 commit f04f9d3
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 15 deletions.
6 changes: 2 additions & 4 deletions src/apis/getGroupVote.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// 투표 현황 조회 API
import customedAxios from './customedAxios';

export const getGroupVote = async (token: string, groupId: number) => {
export const getGroupVote = async (groupId: number, userId: number) => {
try {
const res = await customedAxios.get(`/group/${groupId}/vote`, {
headers: {
Authorization: 'Bearer ' + token,
},
params: { user: userId },
});
return res.data;
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/components/common/header/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const Header = () => {
<LogoComponent />
</div>
{token !== undefined && (
<div onClick={onClickLogout} className="font-normal font-Pretendard text-font_gray text-b2">
<div onClick={onClickLogout} className="font-normal font-Pretendard text-font_gray text-b2 cursor-pointer">
로그아웃
</div>
)}
Expand Down
4 changes: 1 addition & 3 deletions src/components/vote/detail/VoteProgressBar.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { useGetGroupVote } from '@/hooks/useGetGroupVote';
import api from '@/services/TokenService';
import { groupIdAtom } from '@/states/groupIdAtom';
import { useEffect, useState } from 'react';
import { useRecoilValue } from 'recoil';

// 투표율 표시를 위한 진행바
const VoteProgressBar = ({ votes }: any) => {
const token = api.getToken();
const group = useRecoilValue(groupIdAtom);
const response: any = useGetGroupVote(token, group.groupId);
const response: any = useGetGroupVote(group.groupId);
const [votePeopleData, setVotePeopleData] = useState<any>();
useEffect(() => {
if (response.data?.message === '성공') setVotePeopleData(response.data?.data);
Expand Down
4 changes: 2 additions & 2 deletions src/hooks/useGetGroupVote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { getGroupVote } from '@/apis/getGroupVote';
import { GetVoteRes } from '@/types/VoteType';
import { useQuery } from '@tanstack/react-query';

export const useGetGroupVote = (token: string, groupId: number) => {
return useQuery<GetVoteRes>(['get-group-vote'], () => getGroupVote(token, groupId));
export const useGetGroupVote = (groupId: number, userId: number = 0) => {
return useQuery<GetVoteRes>(['get-group-vote'], () => getGroupVote(groupId, userId));
};
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
src: url('https://cdn.jsdelivr.net/gh/Project-Noonnu/[email protected]/Pretendard-Regular.woff') format('woff');
font-weight: normal;
font-style: normal;
}

body {
background-color: white;
}
2 changes: 1 addition & 1 deletion src/pages/vote/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import NotFound from '../404';
const VotePage = () => {
const token = api.getToken();
const group = useRecoilValue(groupIdAtom);
const { data: response, isLoading, isError } = useGetGroupVote(token, group.groupId);
const { data: response, isLoading, isError } = useGetGroupVote(group.groupId);
const [voteData, setVoteData] = useState<any>(null);

useEffect(() => {
Expand Down
5 changes: 3 additions & 2 deletions src/pages/vote/detail/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const VoteDetailPage = () => {
const groupAdminId = typeof window !== 'undefined' ? sessionStorage.getItem('adminId') : null;
const [voteIds, setVoteIds] = useState<any>([]);

const response = useGetGroupVote(token, groupIdData.groupId);
const response = useGetGroupVote(groupIdData.groupId);
const currentId = api.getEmail();
const voteP: voteSelectPlaceData = {
groupId: groupIdData.groupId,
Expand Down Expand Up @@ -80,8 +80,9 @@ const VoteDetailPage = () => {
useEffect(() => {
console.log('voteIDS... : ', voteIds);
}, [voteIds]);

//투표 참여 API react-query mutation
const postGroupVoteSelectMutation = useMutation((data: VoteSelectData) => postGroupVoteSelect(token, data), {
const postGroupVoteSelectMutation: any = useMutation((data: VoteSelectData) => postGroupVoteSelect(token, data), {
onSuccess: () => {
alert('투표 참여 완료!');
location.reload();
Expand Down
3 changes: 1 addition & 2 deletions src/pages/vote/wait/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ import { useRecoilValue } from 'recoil';
const VoteWaitPage = () => {
const currentUserEmail = api.getEmail();
const router = useRouter();
const token = api.getToken();
const [voteData, setVoteData] = useState<VoteData>();
const [groupData, setGroupData] = useState<ParticipationProps>();
const [adminEmail, setAdminEmail] = useState<string | undefined>('');
const group = useRecoilValue(groupIdAtom);
const response = useGetGroupVote(token, group.groupId);
const response = useGetGroupVote(group.groupId);
const getGroup = useGetGroup(group.groupId);
const [sumParticipant, setSumParticipant] = useState<number>(0);
useEffect(() => {
Expand Down

0 comments on commit f04f9d3

Please sign in to comment.