Skip to content

Commit cb2051a

Browse files
authoredNov 5, 2023
게스트 모집 상세 페이지 api 연동 (#103)
* chore: 불필요한 파일 삭제 * fix: mockPostGameParticipate return문 추가 * feat: GamesDetailPage api 연동 * feat: 참여 신청하기 버튼 클릭 시 gameDetailQuery 무효화 * feat: 내가 작성한 모집글인지에 따라 ui 다르게 보여주는 기능
1 parent 47fa335 commit cb2051a

File tree

4 files changed

+70
-101
lines changed

4 files changed

+70
-101
lines changed
 

‎src/api/getMatch.ts

-68
This file was deleted.

‎src/hooks/queries/useMatchQuery.ts

-10
This file was deleted.

‎src/mocks/handlers/game.ts

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ const mockPostGameParticipate = http.post<
9494
addressDepth2: '강남구',
9595
positions: ['C', 'PF'],
9696
});
97+
98+
return HttpResponse.json();
9799
});
98100

99101
const mockGetGameMembers = http.get<

‎src/pages/GamesDetailPage/GamesDetailPage.tsx

+68-23
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
import { useNavigate, useParams } from 'react-router-dom';
22

3+
import { useQueryClient } from '@tanstack/react-query';
4+
35
import { Avatar } from '@components/Avatar';
46
import { Header } from '@components/Header';
57
import { Button } from '@components/shared/Button';
68
import { Flex } from '@components/shared/Flex';
79
import { Image } from '@components/shared/Image';
810
import { Text } from '@components/shared/Text';
911

10-
import { useMatchQuery } from '@hooks/queries/useMatchQuery';
12+
import { useGameParticipateCreateMutation } from '@hooks/mutations/useGameParticipateCreateMutation';
13+
import { useGameDetailQuery } from '@hooks/queries/useGameDetailQuery';
1114

1215
import { theme } from '@styles/theme';
1316

17+
import { Member } from '@type/models';
18+
1419
import { PATH_NAME } from '@consts/pathName';
1520
import { WEEKDAY } from '@consts/weekday';
1621

@@ -30,21 +35,39 @@ import {
3035
UserDataWrapper,
3136
} from './GamesDetailPage.styles';
3237

38+
const getMyInfo = (): Member | null => {
39+
const json = localStorage.getItem('USER_INFO');
40+
if (!json) {
41+
return null;
42+
}
43+
return JSON.parse(json);
44+
};
45+
3346
export const GamesDetailPage = () => {
3447
const { id } = useParams();
3548
if (id === undefined) {
3649
throw new Error('"match id" is undefined');
3750
}
51+
const gameId = Number(id);
3852

39-
const { data: match } = useMatchQuery(id);
53+
const navigate = useNavigate();
54+
const queryClient = useQueryClient();
55+
const { data: match } = useGameDetailQuery(gameId);
56+
const myInfo = getMyInfo();
57+
const isMyMatch = match.host.id === myInfo?.id;
58+
59+
const { mutate: participateMutate } = useGameParticipateCreateMutation();
60+
const onParticipateSuccess = () => {
61+
queryClient.invalidateQueries({
62+
queryKey: ['game-detail', gameId],
63+
});
64+
};
4065

4166
const [year, month, day] = match.playDate.split('-');
4267
const [hour, min] = match.playStartTime.split(':');
4368
const date = new Date(Number(year), Number(month) - 1, Number(day));
4469
const weekday = WEEKDAY[date.getDay()];
4570

46-
const navigate = useNavigate();
47-
4871
const handleClickMemberProfile = (id: number | string) =>
4972
navigate(PATH_NAME.GET_PROFILE_PATH(String(id)));
5073

@@ -83,19 +106,20 @@ export const GamesDetailPage = () => {
83106
<Text size={16}>{match.host.nickname}</Text>
84107
</Flex>
85108
</Flex>
86-
{/* TODO: 본인일 시 버튼 렌더링 안하게 */}
87109
{/* TODO: 버튼 클릭 핸들러 */}
88-
<Button
89-
fontWeight={500}
90-
width="80px"
91-
height="40px"
92-
borderColor={theme.PALETTE.GRAY_400}
93-
backgroundColor="white"
94-
textColor={theme.PALETTE.GRAY_400}
95-
onClick={() => {}}
96-
>
97-
대화하기
98-
</Button>
110+
{myInfo && !isMyMatch && (
111+
<Button
112+
fontWeight={500}
113+
width="80px"
114+
height="40px"
115+
borderColor={theme.PALETTE.GRAY_400}
116+
backgroundColor="white"
117+
textColor={theme.PALETTE.GRAY_400}
118+
onClick={() => {}}
119+
>
120+
대화하기
121+
</Button>
122+
)}
99123
</UserDataWrapper>
100124
<Text size={20} weight={700}>
101125
경기 정보
@@ -164,13 +188,34 @@ export const GamesDetailPage = () => {
164188
))}
165189
</Guests>
166190
</GuestsContainer>
167-
<Button
168-
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
169-
height="50px"
170-
// TODO: 클릭 핸들러
171-
>
172-
참여 신청하기
173-
</Button>
191+
{myInfo && !isMyMatch && (
192+
<Button
193+
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
194+
height="50px"
195+
onClick={() =>
196+
participateMutate(
197+
{
198+
gameId,
199+
payload: { memberId: myInfo.id },
200+
},
201+
{ onSuccess: onParticipateSuccess }
202+
)
203+
}
204+
>
205+
참여 신청하기
206+
</Button>
207+
)}
208+
{myInfo && isMyMatch && (
209+
<Button
210+
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
211+
height="50px"
212+
onClick={() =>
213+
navigate(PATH_NAME.GET_GAMES_MANAGE_PATH(String(gameId)))
214+
}
215+
>
216+
매치 관리
217+
</Button>
218+
)}
174219
</PageContent>
175220
</PageLayout>
176221
);

0 commit comments

Comments
 (0)
Please sign in to comment.