-
Notifications
You must be signed in to change notification settings - Fork 1
[Feature/#207] chat api 연동 - 아직 리뷰 x #208
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
base: develop
Are you sure you want to change the base?
Changes from all commits
f7e6d11
8ae9a7a
46d8a41
4cba13c
c1ba1e7
30710de
b4a97a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,16 +6,21 @@ import { Icon } from '@icon/Icon'; | |
| import OverlayModal from '@layout/overlay/Overlay'; | ||
| import Navigation from '@layout/navigation/Navigation'; | ||
| import Button from '@ui/button/Button'; | ||
| import { useGetChatList } from '@pages/chat-list/api/chat-list-api'; | ||
| import Loading from '@layout/loading/Loading'; | ||
|
|
||
| export default function ChatList() { | ||
| const navigate = useNavigate(); | ||
| const handleClickBack = () => navigate(-1); | ||
|
|
||
| //TODO: 유저,오너 구분 확인 로직 필요 | ||
| const isOwner = true; | ||
| const { data: chatListData, isPending, isError } = useGetChatList(isOwner); | ||
|
|
||
| const { | ||
| isEditing, | ||
| activeFilter, | ||
| setActiveFilter, | ||
| chatList, | ||
| selectChatList, | ||
| handleToggleEdit, | ||
| handleCheckChange, | ||
|
|
@@ -25,6 +30,13 @@ export default function ChatList() { | |
| handleCloseModal, | ||
| } = useChatList(); | ||
|
|
||
| //TODO: 에러 처리 필요 | ||
| if (isPending) { | ||
| return <Loading />; | ||
| } | ||
| if (isError) { | ||
| return <div>채팅 목록을 불러오는 중에 오류가 발생했습니다.</div>; | ||
| } | ||
| return ( | ||
| <> | ||
| <Navigation | ||
|
|
@@ -69,19 +81,19 @@ export default function ChatList() { | |
| </div> | ||
| </div> | ||
| </OverlayModal> | ||
| <div className='flex flex-col overflow-y-scroll pb-[2.4rem] pt-[7.8rem] scrollbar-hide'> | ||
| {(chatList ?? []).map(item => { | ||
| <div className='scrollbar-hide flex flex-col overflow-y-scroll pb-[2.4rem] pt-[7.8rem]'> | ||
| {(chatListData?.content ?? []).map(item => { | ||
| return ( | ||
| <ChatListItem | ||
| key={item.clientId} | ||
| key={item.id} | ||
| isEditing={isEditing} | ||
| clientName={item.clientName} | ||
| tagTitle={item.tagTitle} | ||
| lastChat={item.lastChat} | ||
| lastChatTime={item.lastChatTime} | ||
| unreadCount={item.unreadCount} | ||
| isChecked={selectChatList.has(item.clientId)} | ||
| handleCheckChange={() => handleCheckChange(item.clientId)} | ||
| name={item.name ?? ''} | ||
| foodTruckName={item.foodTruckName ?? ''} | ||
| lastMessage={item.lastMessage ?? ''} | ||
| lastMessageSendTime={item.lastMessageSendTime ?? ''} | ||
| unreadCount={item.unreadCount ?? 0} | ||
| isChecked={selectChatList.has(item.id ?? 0)} | ||
| handleCheckChange={() => handleCheckChange(item.id ?? 0)} | ||
|
Comment on lines
87
to
+96
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. profileImageUrl prop이 누락되었고 item.id 기본값 처리를 개선하세요.
다음과 같이 수정하세요: {(chatListData?.content ?? []).map(item => {
+ if (!item.id) {
+ console.warn('Chat item missing id:', item);
+ return null;
+ }
return (
<ChatListItem
key={item.id}
+ profileImageUrl={item.profileImageUrl}
isEditing={isEditing}
name={item.name ?? ''}
foodTruckName={item.foodTruckName ?? ''}
lastMessage={item.lastMessage ?? ''}
lastMessageSendTime={item.lastMessageSendTime ?? ''}
unreadCount={item.unreadCount ?? 0}
- isChecked={selectChatList.has(item.id ?? 0)}
- handleCheckChange={() => handleCheckChange(item.id ?? 0)}
+ isChecked={selectChatList.has(item.id)}
+ handleCheckChange={() => handleCheckChange(item.id)}
/>
);
})}
🤖 Prompt for AI Agents |
||
| /> | ||
| ); | ||
| })} | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,66 @@ | ||||||||||||||||||||||||||||||||||||||||||
| import { apiRequest } from '@api/apiRequest'; | ||||||||||||||||||||||||||||||||||||||||||
| import { USER_INFO } from '@shared/querykey/user-info'; | ||||||||||||||||||||||||||||||||||||||||||
| import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||||||||||||||||||||||||||||||||||||||||||
| import type { | ||||||||||||||||||||||||||||||||||||||||||
| CreateChatRoomData, | ||||||||||||||||||||||||||||||||||||||||||
| GetChatRoomsData, | ||||||||||||||||||||||||||||||||||||||||||
| MarkMessagesAsReadData, | ||||||||||||||||||||||||||||||||||||||||||
| } from 'apis/data-contracts'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const getChatList = async (isOwner: boolean) => { | ||||||||||||||||||||||||||||||||||||||||||
| const response = await apiRequest<GetChatRoomsData>({ | ||||||||||||||||||||||||||||||||||||||||||
| endPoint: '/chat/rooms', | ||||||||||||||||||||||||||||||||||||||||||
| method: 'GET', | ||||||||||||||||||||||||||||||||||||||||||
| params: { | ||||||||||||||||||||||||||||||||||||||||||
| isOwner, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| return response.data; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const postChatRoom = async (foodTruckId: number) => { | ||||||||||||||||||||||||||||||||||||||||||
| const response = await apiRequest<CreateChatRoomData>({ | ||||||||||||||||||||||||||||||||||||||||||
| endPoint: '/chat/rooms', | ||||||||||||||||||||||||||||||||||||||||||
| method: 'POST', | ||||||||||||||||||||||||||||||||||||||||||
| params: { | ||||||||||||||||||||||||||||||||||||||||||
| foodTruckId, | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| return response.data; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+21
to
+30
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. foodTruckId를 요청 바디에 포함해야 합니다.
다음과 같이 수정하세요: const postChatRoom = async (foodTruckId: number) => {
const response = await apiRequest<CreateChatRoomData>({
endPoint: '/chat/rooms',
method: 'POST',
- params: {
+ data: {
foodTruckId,
},
});
return response.data;
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| const patchChatRoom = async (chatRoomId: number) => { | ||||||||||||||||||||||||||||||||||||||||||
| const response = await apiRequest<MarkMessagesAsReadData>({ | ||||||||||||||||||||||||||||||||||||||||||
| endPoint: `/chat/rooms/${chatRoomId}/read`, | ||||||||||||||||||||||||||||||||||||||||||
| method: 'PATCH', | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| return response.data; | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export const useGetChatList = (isOwner: boolean) => { | ||||||||||||||||||||||||||||||||||||||||||
| return useQuery({ | ||||||||||||||||||||||||||||||||||||||||||
| // eslint-disable-next-line @tanstack/query/exhaustive-deps | ||||||||||||||||||||||||||||||||||||||||||
| queryKey: USER_INFO.CHATS(), | ||||||||||||||||||||||||||||||||||||||||||
| queryFn: () => getChatList(isOwner), | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+40
to
+46
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. queryKey에 isOwner를 포함해야 합니다.
예: 다음과 같이 수정하세요: export const useGetChatList = (isOwner: boolean) => {
return useQuery({
- // eslint-disable-next-line @tanstack/query/exhaustive-deps
- queryKey: USER_INFO.CHATS(),
+ queryKey: [...USER_INFO.CHATS(), isOwner],
queryFn: () => getChatList(isOwner),
});
};📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export const usePostChatRoom = (foodTruckId: number) => { | ||||||||||||||||||||||||||||||||||||||||||
| const queryClient = useQueryClient(); | ||||||||||||||||||||||||||||||||||||||||||
| return useMutation({ | ||||||||||||||||||||||||||||||||||||||||||
| mutationFn: () => postChatRoom(foodTruckId), | ||||||||||||||||||||||||||||||||||||||||||
| onSuccess: () => { | ||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: USER_INFO.CHATS() }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| export const usePatchChatRoom = (chatRoomId: number) => { | ||||||||||||||||||||||||||||||||||||||||||
| const queryClient = useQueryClient(); | ||||||||||||||||||||||||||||||||||||||||||
| return useMutation({ | ||||||||||||||||||||||||||||||||||||||||||
| mutationFn: () => patchChatRoom(chatRoomId), | ||||||||||||||||||||||||||||||||||||||||||
| onSuccess: () => { | ||||||||||||||||||||||||||||||||||||||||||
| queryClient.invalidateQueries({ queryKey: USER_INFO.CHATS() }); | ||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||
This file was deleted.
This file was deleted.
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.
null 예외처리를 빈 문자열 대신 '로딩중', '알 수 없음' 등은 어떨까요?