Skip to content

Commit

Permalink
Merge branch 'dev' into feat/#334-redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
1g2g committed Nov 27, 2023
2 parents 3fdc6f3 + 58984fd commit 48d2fd1
Show file tree
Hide file tree
Showing 26 changed files with 578 additions and 168 deletions.
2 changes: 1 addition & 1 deletion src/api/chat/getPersonalChatRoomExisted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const getPersonalChatRoomExisted = async ({
receiverId,
}: GetPersonalChatRoomExistedRequest) => {
const { data } = await axiosInstance.get<GetPersonalChatRoomExistedResponse>(
'/rooms/personal/existed',
'/rooms/personal',
{ params: { receiver: receiverId } }
);

Expand Down
17 changes: 17 additions & 0 deletions src/api/member/getCrewRegistrationStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { axiosInstance } from '@api/axiosInstance';

import {
GetCrewRegistrationStatusRequest,
GetRegistrationStatusResponse,
} from '@type/api/member';

export const getCrewRegistrationStatus = async ({
memberId,
crewId,
}: GetCrewRegistrationStatusRequest) => {
const { data } = await axiosInstance.get<GetRegistrationStatusResponse>(
`/members/${memberId}/crews/${crewId}/registration-status`
);

return data;
};
17 changes: 17 additions & 0 deletions src/api/member/getGameRegistrationStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { axiosInstance } from '@api/axiosInstance';

import {
GetGameRegistrationStatusRequest,
GetRegistrationStatusResponse,
} from '@type/api/member';

export const getGameRegistrationStatus = async ({
memberId,
gameId,
}: GetGameRegistrationStatusRequest) => {
const { data } = await axiosInstance.get<GetRegistrationStatusResponse>(
`/members/${memberId}/games/${gameId}/registration-status`
);

return data;
};
6 changes: 6 additions & 0 deletions src/components/Participation/Participation.style.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import styled from '@emotion/styled';

import { Text } from '@components/shared/Text';

export const ManageContainer = styled.div`
${({ theme }) => theme.STYLES.LAYOUT}
min-height: 100dvh;
Expand All @@ -15,3 +17,7 @@ export const AllowCardGroup = styled.div`
flex-wrap: wrap;
gap: 0.75rem;
`;

export const InformText = styled(Text)`
padding: 16px;
`;
37 changes: 24 additions & 13 deletions src/components/Participation/Participation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import { useNavigate } from 'react-router-dom';
import { useLoginInfoStore } from '@/stores/loginInfo.store';

import { AllowCard } from '@components/Participation/components/AllowCard';
import { Flex } from '@components/shared/Flex';

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

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

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

import { AllowCardGroup, Main } from './Participation.style';
import { AllowCardGroup, InformText, Main } from './Participation.style';

type ParticipationProps = {
id: Member['id'];
Expand All @@ -36,25 +39,33 @@ export const Participation = ({
navigate(PATH_NAME.LOGIN);
return;
}
}, [id, navigate]);
}, [id, loginInfo, navigate]);

const moveToProfile = (memberId: number) => {
navigate(PATH_NAME.GET_PROFILE_PATH(String(memberId)));
};

return (
<Main>
<AllowCardGroup>
{waitingMembers.map(({ ...props }: Member) => (
<AllowCard
key={props.id}
member={props}
onClickProfile={() => moveToProfile(props.id)}
onClickAllowButton={() => handleGuestAction(props.id, '확정')}
onClickDisallowButton={() => handleGuestAction(props.id, '거절')}
/>
))}
</AllowCardGroup>{' '}
{waitingMembers.length > 0 ? (
<AllowCardGroup>
{waitingMembers.map(({ ...props }: Member) => (
<AllowCard
key={props.id}
member={props}
onClickProfile={() => moveToProfile(props.id)}
onClickAllowButton={() => handleGuestAction(props.id, '확정')}
onClickDisallowButton={() => handleGuestAction(props.id, '거절')}
/>
))}
</AllowCardGroup>
) : (
<Flex justify="center" gap={16}>
<InformText size={theme.FONT_SIZE.XS} weight={300}>
수락 대기중인 인원이 없습니다
</InformText>
</Flex>
)}
</Main>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export const AllowCard = ({
size={40}
onClick={onClickProfile}
/>
&nbsp;
<Text
size={12}
weight={500}
Expand Down
16 changes: 15 additions & 1 deletion src/hooks/mutations/useCrewParticipateCreateMutation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { postCrewParticipate } from '@api/crews/postCrewParticipate';

import { useLoginInfoStore } from '@stores/loginInfo.store';

export const useCrewParticipateCreateMutation = () => {
const queryClient = useQueryClient();
const id = useLoginInfoStore((state) => state.loginInfo?.id);

return useMutation({
mutationFn: postCrewParticipate,
onSuccess: (_, { crewId }) => {
queryClient.invalidateQueries({
queryKey: ['crew-detail', crewId],
});
id &&
queryClient.invalidateQueries({
queryKey: ['crew-registration', id, crewId],
});
},
});
};
16 changes: 15 additions & 1 deletion src/hooks/mutations/useGameParticipateCreateMutation.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import { useMutation } from '@tanstack/react-query';
import { useMutation, useQueryClient } from '@tanstack/react-query';

import { postGameParticipate } from '@api/games/postGameParticipate';

import { useLoginInfoStore } from '@stores/loginInfo.store';

export const useGameParticipateCreateMutation = () => {
const queryClient = useQueryClient();
const id = useLoginInfoStore((state) => state.loginInfo?.id);

return useMutation({
mutationFn: postGameParticipate,
onSuccess: (_, { gameId }) => {
queryClient.invalidateQueries({
queryKey: ['game-detail', gameId],
});
id &&
queryClient.invalidateQueries({
queryKey: ['game-registration', id, gameId],
});
},
});
};
15 changes: 15 additions & 0 deletions src/hooks/queries/useCrewRegistrationStatusQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { getCrewRegistrationStatus } from '@api/member/getCrewRegistrationStatus';

import { GetCrewRegistrationStatusRequest } from '@type/api/member';

export const useCrewRegistrationStatusQuery = ({
memberId,
crewId,
}: GetCrewRegistrationStatusRequest) => {
return useSuspenseQuery({
queryKey: ['crew-registration', memberId, crewId],
queryFn: () => getCrewRegistrationStatus({ memberId, crewId }),
});
};
15 changes: 15 additions & 0 deletions src/hooks/queries/useGameRegistrationStatusQuery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { useSuspenseQuery } from '@tanstack/react-query';

import { getGameRegistrationStatus } from '@api/member/getGameRegistrationStatus';

import { GetGameRegistrationStatusRequest } from '@type/api/member';

export const useGameRegistrationStatusQuery = ({
memberId,
gameId,
}: GetGameRegistrationStatusRequest) => {
return useSuspenseQuery({
queryKey: ['game-registration', memberId, gameId],
queryFn: () => getGameRegistrationStatus({ memberId, gameId }),
});
};
113 changes: 46 additions & 67 deletions src/hooks/useChatOnButtonClick.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { useQuery } from '@tanstack/react-query';
import { AxiosError } from 'axios';
import SockJS from 'sockjs-client';
import Stomp from 'stompjs';

import { getAllChatRoomList } from '@api/chat/getAllChatRoomList';
import { getPersonalChatRoomExisted } from '@api/chat/getPersonalChatRoomExisted';

import {
Expand All @@ -19,7 +19,6 @@ import { Member } from '@type/models';
import { ChatMessage } from '@type/models/ChatMessage';
import { ChatRoom } from '@type/models/ChatRoom';

import { CHAT_ROOM_TAB_TITLE } from '@consts/chatRoomTabTitle';
import { PATH_NAME } from '@consts/pathName';

type useChatOnButtonClickProps = {
Expand All @@ -31,7 +30,6 @@ type useChatOnButtonClickProps = {

export const useChatOnButtonClick = ({
targetId,
targetNickname,
myId = null,
navigate: moveToPage,
}: useChatOnButtonClickProps) => {
Expand All @@ -41,60 +39,38 @@ export const useChatOnButtonClick = ({
enabled: false,
});

const { refetch: fetchAllChatRoomList } = useQuery({
queryKey: ['all-chat-room-list', CHAT_ROOM_TAB_TITLE.INDIVIDUAL],
queryFn: () => getAllChatRoomList({ type: CHAT_ROOM_TAB_TITLE.INDIVIDUAL }),
enabled: false,
});

const { mutateAsync } = useCreatePersonalChatRoomMutation();

const handleExistingRoom = async (
individualRooms: ChatRoom[],
isSenderActive: boolean
) => {
const { id: roomId } =
individualRooms.find(
({ roomName }: { roomName: string }) => roomName === targetNickname
) || {};
if (!roomId) {
return;
}

if (isSenderActive) {
moveToPage(PATH_NAME.GET_CHAT_PATH(String(roomId)));
} else {
const sock = new SockJS(stompConfig.webSocketEndpoint);
const stompClient = Stomp.over(sock);

connect({
stompClient,
connectEvent: () => {
subscribe({
stompClient,
roomId,
subscribeEvent: (received: ChatMessage) => {
const {
type,
sender: { id: senderId },
} = received;

if (type === '입장' && senderId === myId) {
moveToPage(PATH_NAME.GET_CHAT_PATH(String(received.roomId)));
sock.close();
}
},
});

const sendData: SendMessageRequest = {
senderId: myId!,
content: null,
};

enter({ stompClient, roomId, sendData });
},
});
}
const enterChatRoom = async (roomId: ChatRoom['id']) => {
const sock = new SockJS(stompConfig.webSocketEndpoint);
const stompClient = Stomp.over(sock);

connect({
stompClient,
connectEvent: () => {
subscribe({
stompClient,
roomId,
subscribeEvent: (received: ChatMessage) => {
const {
type,
sender: { id: senderId },
} = received;

if (type === '입장' && senderId === myId) {
sock.close();
}
},
});

const sendData: SendMessageRequest = {
senderId: myId!,
content: null,
};

enter({ stompClient, roomId, sendData });
},
});
};

const handleClickChattingButton = async () => {
Expand All @@ -103,21 +79,24 @@ export const useChatOnButtonClick = ({
return;
}

const { data } = await fetchPersonalChatRoomExisted();
if (!data) return;
const { data, error } = await fetchPersonalChatRoomExisted();

const { isRoomExisted, isSenderActive } = data;
if (data) {
const { roomId } = data;

await enterChatRoom(roomId);

if (isRoomExisted) {
const { data: individualRooms } = await fetchAllChatRoomList();
if (individualRooms) {
handleExistingRoom(individualRooms, isSenderActive);
}
} else {
const { id: roomId } = await mutateAsync({
receiverId: targetId,
});
moveToPage(PATH_NAME.GET_CHAT_PATH(String(roomId)));
} else {
if (error instanceof AxiosError) {
if (error.response?.data.code === 'CHT-003') {
const { id: roomId } = await mutateAsync({
receiverId: targetId,
});

moveToPage(PATH_NAME.GET_CHAT_PATH(String(roomId)));
}
}
}
};

Expand Down
Loading

0 comments on commit 48d2fd1

Please sign in to comment.