-
Notifications
You must be signed in to change notification settings - Fork 5
[FE] feat: 친구 관련 및 DM api 연동 #105
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
c5fe867
[FE] feat: 친구 관련 타입 및 api 함수 정의 (#89)
chysis e39761f
[FE] fix: 토큰을 포함한 요청에서 로그인 시 받은 토큰을 사용하도록 수정 (#89)
chysis e5bcd9b
[FE] feat: 사용자 정보 요청 api 함수 및 관련 타입 정의 (#89)
chysis 1064ac1
[FE] refactor: 사용자 정보 요청 api 연동 및 userId를 전역 상태로 관리해서 사용 (#89)
chysis 935350d
[FE] fix: 친구 관련 요청 api 함수 및 타입 수정 (#89)
chysis 313fb90
[FE] feat: 친구 목록 api 연동 (#89)
chysis c260d1c
[FE] design: 친구 목록 프로필이 찌그러지는 문제 수정 (#89)
chysis 80f7c0e
[FE] fix: api 함수명 camelCase로 수정 (#89)
chysis a175e86
[FE] feat: 대기 중인 친구 목록 api 연동 (#89)
chysis 7e9075d
[FE] refactor: 받은 요청, 보낸 요청, 받은 요청에 수락/거절 로직 훅으로 분리 (#89)
chysis 9bcf46f
[FE] feat: 요청 수락/거절 실패 시 에러 메시지 추가 및 요청 중일 때 버튼 클릭할 수 없게 수정 (#89)
chysis 443e849
[FE] fix: api 응답 데이터 수정 (#89)
chysis d3a4153
[FE] refactor: 훅 이름 변경 및 적용 (#89)
chysis 1a33dc3
[FE] refactor: 친구 목록 요청을 훅으로 분리 (#89)
chysis 1046cc5
[FE] feat: 친구 추가 api 연동 및 유효성 검사 로직 구현 (#89)
chysis be2094a
[FE] refactor: 친구 요청 폼이 뜰 때마다 요청 보내지 않도록 수정 (#89)
chysis 8305a5b
[FE] feat: DM 카테고리 영역에 친구 탭 추가 (#89)
chysis dc4a63b
[FE] design: 카테고리 텍스트 폰트 크기 조절 (#89)
chysis 278affd
[FE] feat: DM 관련 api 함수 및 타입 추가 (#89)
chysis e25d1b4
[FE] feat: DM 목록 api 연동 (#89)
chysis 7eea5dd
[FE] refactor: 구조 분해를 통해 접근하는 데이터의 depth 감소 (#89)
chysis 078bcbb
[FE] design: 공통 모달 컴포넌트 footerWrapper margin 제거, padding 수정 (#89)
chysis bdeb27c
[FE] refactor: AuthCheckbox의 id를 optional로 수정 (#89)
chysis da876dd
[FE] fix: text ellipsis 가능하도록 css 수정 (#89)
chysis d9df4c9
[FE] fix: name이 아닌 nickname이 노출되도록 수정 (#89)
chysis db3f4be
[FE] fix: closeModal key를 camelCase로 수정 (#89)
chysis ccd684e
[FE] feat: DM 채팅방 생성 모달 구현 및 api 연동 (#89)
chysis 248ff9b
[FE] feat: 받은 친구 요청 수락 시 DM이 자동으로 생성되도록 구현 (#89)
chysis 07d7ed6
[FE] feat: DM 생성 모달에서 친구의 name을 함께 보여주도록 설정 (#89)
chysis c400e3a
[FE] design: online 색상 코드 추가 및 적용, nickname 자리에 id를 출력하는 버그 수정 (#89)
chysis a5be360
[FE] refactor: 회원 정보 검색 api 수정 반영 (#89)
chysis d5670c8
[FE] design: 친구 목록에 padding 추가 (#89)
chysis ecd35cc
[FE] feat: 친구 목록에서 삭제 기능 구현 (#89)
chysis 34e5075
[FE] feat: 계정 탈퇴 기능 구현 (#89)
chysis 41ab164
[FE] fix: 로그아웃 후 다른 계정으로 로그인 했을 때 이전 계정의 사용자 정보와 친구 목록이 뜨는 오류 수정 (#89)
chysis 59c5d6c
[FE] fix: 본인을 친구 추가하지 못하도록 수정 (#89)
chysis f7ec3ef
[FE] refactor: usePostDirect 및 관련 모달 리팩토링 (#89)
chysis 95ed854
[FE] refactor: 친구 삭제 요청을 useMutation을 사용하여 훅으로 분리 (#89)
chysis a24e54d
[FE] refactor: DM 리스트에서 나를 제외한 다른 멤버 리스트를 변수로 분리 (#89)
chysis d532252
[FE] refactor: userInfo 전역 상태로 set 할 때 기존 데이터와 달라졌는지 확인하는 로직 추가 (#89)
chysis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { endPoint } from '@/constants/endPoint'; | ||
| import { GetDirectMessagesResponse, PostDirectMessageRequest } from '@/types/directMessages'; | ||
| import { tokenAxios } from '@/utils/axios'; | ||
|
|
||
| export const getDirects = async () => { | ||
| const { data } = await tokenAxios.get<GetDirectMessagesResponse>(endPoint.directMessages.GET_DIRECTS); | ||
| return data.result.directResponses; | ||
| }; | ||
|
|
||
| interface PostDirectParams { | ||
| bodyRequest: PostDirectMessageRequest; | ||
| } | ||
|
|
||
| export const postDirect = async ({ bodyRequest }: PostDirectParams) => { | ||
| const { data } = await tokenAxios.post(endPoint.directMessages.POST_DIRECT, bodyRequest); | ||
| return data.result; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| import { endPoint } from '@/constants/endPoint'; | ||
| import { | ||
| DeleteFriendResponse, | ||
| GetFriendsListResponse, | ||
| GetFriendInfoResponse, | ||
| GetReceivedRequestsResponse, | ||
| GetSentRequestsResponse, | ||
| PostAcceptResponse, | ||
| PostRejectResponse, | ||
| PostRequestResponse, | ||
| } from '@/types/friends'; | ||
| import { tokenAxios } from '@/utils/axios'; | ||
|
|
||
| interface DeleteFriendParams { | ||
| friendId: string; | ||
| } | ||
|
|
||
| export const deleteFriend = async ({ friendId }: DeleteFriendParams) => { | ||
| const { data } = await tokenAxios.delete<DeleteFriendResponse>(endPoint.friends.DELETE_FRIEND(friendId)); | ||
| return data; | ||
| }; | ||
|
|
||
| interface GetFriendInfoParams { | ||
| email: string; | ||
| } | ||
|
|
||
| export const getFriendInfo = async ({ email }: GetFriendInfoParams) => { | ||
| const { data } = await tokenAxios.get<GetFriendInfoResponse>(endPoint.friends.GET_FRIENDS, { params: { email } }); | ||
| return data.result; | ||
| }; | ||
|
|
||
| export const getSentRequest = async () => { | ||
| const { data } = await tokenAxios.get<GetSentRequestsResponse>(endPoint.friends.GET_SENT_REQUESTS); | ||
| return data.result.friends; | ||
| }; | ||
|
|
||
| export const getReceivedRequest = async () => { | ||
| const { data } = await tokenAxios.get<GetReceivedRequestsResponse>(endPoint.friends.GET_RECEIVED_REQUESTS); | ||
| return data.result.friends; | ||
| }; | ||
|
|
||
| export const getFriendsList = async () => { | ||
| const { data } = await tokenAxios.get<GetFriendsListResponse>(endPoint.friends.GET_FRIENDS_LIST); | ||
| return data.result.friends; | ||
| }; | ||
|
|
||
| interface PostFriendRequestParams { | ||
| toUserId: string; | ||
| } | ||
|
|
||
| export const postFriendRequest = async ({ toUserId }: PostFriendRequestParams) => { | ||
| const { data } = await tokenAxios.post<PostRequestResponse>(endPoint.friends.POST_REQUEST(toUserId)); | ||
| return data.result; | ||
| }; | ||
|
|
||
| interface PostRejectRequestParams { | ||
| friendId: string; | ||
| } | ||
|
|
||
| export const postRejectRequest = async ({ friendId }: PostRejectRequestParams) => { | ||
| const { data } = await tokenAxios.post<PostRejectResponse>(endPoint.friends.POST_REJECT_REQUEST(friendId)); | ||
| return data.result; | ||
| }; | ||
|
|
||
| interface PostAcceptRequestParams { | ||
| friendId: string; | ||
| } | ||
|
|
||
| export const postAcceptRequest = async ({ friendId }: PostAcceptRequestParams) => { | ||
| const { data } = await tokenAxios.post<PostAcceptResponse>(endPoint.friends.POST_ACCEPT_REQUEST(friendId)); | ||
| return data.result; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
src/frontend/src/components/friend/CreateDirectMessageModal/hooks/usePostDirect.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
|
||
| import { postDirect } from '@/api/directMessages'; | ||
| import useModalStore from '@/stores/modalStore'; | ||
|
|
||
| const usePostDirect = () => { | ||
| const queryClient = useQueryClient(); | ||
| const { closeAllModal } = useModalStore(); | ||
|
|
||
| const createDirectMessageMutation = useMutation({ | ||
| mutationFn: postDirect, | ||
| mutationKey: ['createDirectMessage'], | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ['directMessagesList'] }); | ||
| closeAllModal(); | ||
| }, | ||
| onError: (error) => { | ||
| console.error('DM 생성 실패', error); | ||
| }, | ||
| }); | ||
|
|
||
| const createDirectMessage = (memberIds: string[]) => { | ||
| createDirectMessageMutation.mutate({ bodyRequest: { memberIds } }); | ||
| }; | ||
|
|
||
| return { createDirectMessage, isPending: createDirectMessageMutation.isPending }; | ||
| }; | ||
|
|
||
| export default usePostDirect; |
67 changes: 67 additions & 0 deletions
67
src/frontend/src/components/friend/CreateDirectMessageModal/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| import { useState } from 'react'; | ||
|
|
||
| import AuthCheckbox from '@/components/common/AuthCheckbox'; | ||
| import Modal from '@/components/common/Modal'; | ||
|
|
||
| import useGetFriendsList from '../FriendsList/hooks/useGetFriendsList'; | ||
|
|
||
| import usePostDirect from './hooks/usePostDirect'; | ||
| import * as S from './styles'; | ||
|
|
||
| const MAX_DIRECT_MESSAGE_FRIENDS = 9; | ||
|
|
||
| const CreateDirectMessageModal = () => { | ||
| const [selectedFriends, setSelectedFriends] = useState<string[]>([]); | ||
| const { createDirectMessage, isPending } = usePostDirect(); | ||
| const { friends } = useGetFriendsList(); | ||
| if (!friends) return null; | ||
|
|
||
| const handleCheckboxClick = (userId: string) => { | ||
| // 이미 선택된 친구를 누르면 선택 해제 가능 | ||
| if (selectedFriends.length === MAX_DIRECT_MESSAGE_FRIENDS) { | ||
| if (!selectedFriends.includes(userId)) return; | ||
| } | ||
|
|
||
| setSelectedFriends((prev) => (prev.includes(userId) ? prev.filter((id) => id !== userId) : [...prev, userId])); | ||
| }; | ||
|
|
||
| const handleCreateDirectMessage = async () => { | ||
| createDirectMessage(selectedFriends); | ||
| }; | ||
|
|
||
| const isButtonDisabled = !selectedFriends.length || isPending; | ||
|
|
||
| return ( | ||
| <Modal name="withFooter"> | ||
| <Modal.Header> | ||
| <S.ModalTitle>친구 선택하기</S.ModalTitle> | ||
| <S.SelectedFriendsCount> | ||
| 친구를 {MAX_DIRECT_MESSAGE_FRIENDS - selectedFriends.length}명 더 선택할 수 있어요. | ||
| </S.SelectedFriendsCount> | ||
| </Modal.Header> | ||
| <Modal.Content> | ||
| <S.FriendList> | ||
| {friends.map((friend) => ( | ||
| <S.FriendItem key={friend.userId} onClick={() => handleCheckboxClick(friend.userId)}> | ||
| <S.FriendProfileImage $imageUrl={friend.profileImageUrl}> | ||
| <S.FriendStatusMark $isOnline={true} /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 네 맞아요! 상태 관리가 도입되면 수정할 예정이에요 |
||
| </S.FriendProfileImage> | ||
| <S.FriendInfo> | ||
| <S.FriendNickname>{friend.nickname}</S.FriendNickname> | ||
| <S.FriendName>{friend.name}</S.FriendName> | ||
| </S.FriendInfo> | ||
| <AuthCheckbox isChecked={selectedFriends.includes(friend.userId)} /> | ||
| </S.FriendItem> | ||
| ))} | ||
| </S.FriendList> | ||
| </Modal.Content> | ||
| <Modal.Footer> | ||
| <S.CreateButton disabled={isButtonDisabled} $isDisabled={isButtonDisabled} onClick={handleCreateDirectMessage}> | ||
| {isPending ? '요청 중...' : 'DM 생성'} | ||
| </S.CreateButton> | ||
| </Modal.Footer> | ||
| </Modal> | ||
| ); | ||
| }; | ||
|
|
||
| export default CreateDirectMessageModal; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
친구 검색 버튼을 누르기 전에 불필요한 요청이 가지 않도록
Promise.all을 사용했어요.