Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

게스트 모집 상세 페이지 api 연동 #103

Merged
merged 5 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions src/api/getMatch.ts

This file was deleted.

10 changes: 0 additions & 10 deletions src/hooks/queries/useMatchQuery.ts

This file was deleted.

2 changes: 2 additions & 0 deletions src/mocks/handlers/game.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ const mockPostGameParticipate = http.post<
addressDepth2: '강남구',
positions: ['C', 'PF'],
});

return HttpResponse.json();
});

const mockGetGameMembers = http.get<
Expand Down
91 changes: 68 additions & 23 deletions src/pages/GamesDetailPage/GamesDetailPage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { useNavigate, useParams } from 'react-router-dom';

import { useQueryClient } from '@tanstack/react-query';

import { Avatar } from '@components/Avatar';
import { Header } from '@components/Header';
import { Button } from '@components/shared/Button';
import { Flex } from '@components/shared/Flex';
import { Image } from '@components/shared/Image';
import { Text } from '@components/shared/Text';

import { useMatchQuery } from '@hooks/queries/useMatchQuery';
import { useGameParticipateCreateMutation } from '@hooks/mutations/useGameParticipateCreateMutation';
import { useGameDetailQuery } from '@hooks/queries/useGameDetailQuery';

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

import { Member } from '@type/models';

import { PATH_NAME } from '@consts/pathName';
import { WEEKDAY } from '@consts/weekday';

Expand All @@ -30,21 +35,39 @@ import {
UserDataWrapper,
} from './GamesDetailPage.styles';

const getMyInfo = (): Member | null => {
const json = localStorage.getItem('USER_INFO');
if (!json) {
return null;
}
return JSON.parse(json);
};

export const GamesDetailPage = () => {
const { id } = useParams();
if (id === undefined) {
throw new Error('"match id" is undefined');
}
const gameId = Number(id);

const { data: match } = useMatchQuery(id);
const navigate = useNavigate();
const queryClient = useQueryClient();
const { data: match } = useGameDetailQuery(gameId);
const myInfo = getMyInfo();
const isMyMatch = match.host.id === myInfo?.id;

const { mutate: participateMutate } = useGameParticipateCreateMutation();
const onParticipateSuccess = () => {
queryClient.invalidateQueries({
queryKey: ['game-detail', gameId],
});
};

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

const navigate = useNavigate();

const handleClickMemberProfile = (id: number | string) =>
navigate(PATH_NAME.GET_PROFILE_PATH(String(id)));

Expand Down Expand Up @@ -83,19 +106,20 @@ export const GamesDetailPage = () => {
<Text size={16}>{match.host.nickname}</Text>
</Flex>
</Flex>
{/* TODO: 본인일 시 버튼 렌더링 안하게 */}
{/* TODO: 버튼 클릭 핸들러 */}
<Button
fontWeight={500}
width="80px"
height="40px"
borderColor={theme.PALETTE.GRAY_400}
backgroundColor="white"
textColor={theme.PALETTE.GRAY_400}
onClick={() => {}}
>
대화하기
</Button>
{myInfo && !isMyMatch && (
<Button
fontWeight={500}
width="80px"
height="40px"
borderColor={theme.PALETTE.GRAY_400}
backgroundColor="white"
textColor={theme.PALETTE.GRAY_400}
onClick={() => {}}
>
대화하기
</Button>
)}
</UserDataWrapper>
<Text size={20} weight={700}>
경기 정보
Expand Down Expand Up @@ -164,13 +188,34 @@ export const GamesDetailPage = () => {
))}
</Guests>
</GuestsContainer>
<Button
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
height="50px"
// TODO: 클릭 핸들러
>
참여 신청하기
</Button>
{myInfo && !isMyMatch && (
<Button
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
height="50px"
onClick={() =>
participateMutate(
{
gameId,
payload: { memberId: myInfo.id },
},
{ onSuccess: onParticipateSuccess }
)
}
>
참여 신청하기
</Button>
)}
{myInfo && isMyMatch && (
<Button
{...theme.BUTTON_PROPS.LARGE_RED_BUTTON_PROPS}
height="50px"
onClick={() =>
navigate(PATH_NAME.GET_GAMES_MANAGE_PATH(String(gameId)))
}
>
매치 관리
</Button>
)}
</PageContent>
</PageLayout>
);
Expand Down