Skip to content

Commit

Permalink
resove conflict error
Browse files Browse the repository at this point in the history
  • Loading branch information
sonsurim committed Jan 21, 2024
2 parents 7063429 + 00b7f1e commit 20b6aa7
Show file tree
Hide file tree
Showing 29 changed files with 838 additions and 584 deletions.
29 changes: 28 additions & 1 deletion src/apis/message/apis.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
import type { CreateMessageRoomReq, CreateMessageRoomRes } from './types'
import type {
GetMessageRoomsReq,
GetMessageRoomsRes,
GetMessageReq,
GetMessageRes,
CreateMessageReq,
CreateMessageRes,
CreateMessageRoomReq,
CreateMessageRoomRes
} from './types'
import { http } from '@utils/http'

export const getMessageRooms = (params: GetMessageRoomsReq) =>
http.get<GetMessageRoomsReq, GetMessageRoomsRes>('/msgrooms', params)

export const getMessage = (params: GetMessageReq) =>
http.get<GetMessageReq, GetMessageRes>(
`/msgrooms/${params.msgRoomId}/msgs`,
params
)

export const createMessage = ({ messageRoomId, ...params }: CreateMessageReq) =>
http.post<Omit<CreateMessageReq, 'messageRoomId'>, CreateMessageRes>(
`/msgrooms/${messageRoomId}/msgs`,
params
)

export const deleteMessageRoom = (messageRoomId: number) =>
http.delete<null>(`/msgrooms/${messageRoomId}`)

export const createMessageRoom = (params: CreateMessageRoomReq) =>
http.post<CreateMessageRoomReq, CreateMessageRoomRes>('/msgrooms', params)
40 changes: 37 additions & 3 deletions src/apis/message/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
import { useMutation } from '@tanstack/react-query'
import { createMessageRoom } from './apis'
import type { CreateMessageRoomReq } from './types'
import { useMutation, useQuery } from '@tanstack/react-query'
import {
getMessageRooms,
getMessage,
createMessage,
deleteMessageRoom,
createMessageRoom
} from './apis'
import type {
CreateMessageReq,
GetMessageReq,
GetMessageRoomsReq,
CreateMessageRoomReq
} from './types'

export const useGetMessageRoomsQuery = (params: GetMessageRoomsReq) =>
useQuery({
queryKey: ['getMessageRooms', params],
queryFn: () => getMessageRooms(params)
})

export const useGetMessageQuery = (params: GetMessageReq) =>
useQuery({
queryKey: ['getMessage', params],
queryFn: () => getMessage(params),
enabled: typeof params.msgRoomId === 'number'
})

export const useCreateMessageMutation = () =>
useMutation({
mutationFn: (params: CreateMessageReq) => createMessage(params)
})

export const useDeleteMessageRoomMutation = (messageRoomId: number) =>
useMutation({
mutationFn: () => deleteMessageRoom(messageRoomId)
})

export const useCreateMessageRoomMutation = () =>
useMutation({
Expand Down
10 changes: 8 additions & 2 deletions src/apis/message/types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import type { CommonCreation, MessageRoomInfo, MessageInfo } from '@types'
import type {
CommonCreation,
MessageRoomInfo,
MessageInfo,
MessageSortTypeCodes
} from '@types'

export type GetMessageRoomsReq = {
sort: MessageSortTypeCodes
page: number
}
export type GetMessageRoomsRes = MessageRoomInfo[]
Expand All @@ -17,7 +23,7 @@ export type GetMessageReq = {
export type GetMessageRes = MessageInfo[]

export type CreateMessageReq = {
msgRoomId: number
messageRoomId: number
content: string
}
export type CreateMessageRes = CommonCreation
24 changes: 20 additions & 4 deletions src/apis/post/apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import type {
GetPostsReq,
GetPostsRes,
UpdateTradeStatusReq,
UpdateTradeStatusRes
UpdateTradeStatusRes,
DeletePostReq,
DeletePostRes,
UpdatePostReq,
UpdatePostRes
} from './types'
import { http } from '@utils/http'

Expand All @@ -16,14 +20,26 @@ export const getPost = (id: number) =>
export const createPost = (param: CreatePostReq) =>
http.post<CreatePostReq, CreatePostRes>('/posts', param)

export const updatePost = ({ postId, ...params }: UpdatePostReq) =>
http.put<Omit<UpdatePostReq, 'postId'>, UpdatePostRes>(
`/posts/${postId}`,
params
)

export const getCategories = () =>
http.get<null, GetCategoriesRes>('/categories')

export const getPosts = (params: GetPostsReq) =>
http.get<GetPostsReq, GetPostsRes>('/posts', params)

export const updatePostTradeStatus = (params: UpdateTradeStatusReq) =>
http.put<UpdateTradeStatusReq, UpdateTradeStatusRes>(
`/posts/trade-status/${params.postId}`,
export const updatePostTradeStatus = ({
postId,
...params
}: UpdateTradeStatusReq) =>
http.put<Omit<UpdateTradeStatusReq, 'postId'>, UpdateTradeStatusRes>(
`/posts/trade-status/${postId}`,
params
)

export const deletePost = (postId: DeletePostReq) =>
http.delete<DeletePostRes>(`/posts/${postId}`)
62 changes: 54 additions & 8 deletions src/apis/post/queries.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,70 @@
import type { DefaultError } from '@tanstack/react-query'
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query'
import {
getPost,
getCategories,
createPost,
getPosts,
updatePostTradeStatus
updatePostTradeStatus,
deletePost,
updatePost
} from './apis'
import type {
CreatePostReq,
DeletePostReq,
GetPostsReq,
GetPostsRes,
UpdateTradeStatusReq,
UpdateTradeStatusRes
UpdatePostReq,
UpdateTradeStatusReq
} from './types'

export const useCreatePostMutation = () =>
useMutation({
mutationFn: (param: CreatePostReq) => createPost(param)
})

export const useUpdatePostMutation = () =>
useMutation({
mutationFn: (params: UpdatePostReq) => updatePost(params)
})

export const useGetPostQuery = (id: number) =>
useQuery({
queryKey: ['getPost', id],
queryFn: () => getPost(id)
queryFn: () => getPost(id),
enabled: typeof id === 'number',
select: data => ({
...data,
postForm: {
category: data.category.code,
tradeType: data.tradeType.code,
productCondition: data.productCondition.code,
price: String(data.price),
imageInfos: [
{
id: '0',
isRepresent: true,
url: data.thumbnailImageUrl || ''
},
...(data.imageUrls.map((url, idx) => ({
id: String(idx + 1),
url
})) || [])
],
title: data.title,
description: data.description,
location: data.location
},
postImages: [
{
id: 0,
src: data.thumbnailImageUrl || ''
},
...(data.imageUrls.map((url, idx) => ({
id: idx + 1,
src: url
})) || [])
]
})
})

export const useGetCategoriesQuery = () =>
Expand All @@ -50,7 +91,12 @@ export const useGetInfinitePostsQuery = (params: GetPostsReq) =>
: undefined
})

export const usePostTradeStatusMutation = () =>
useMutation<UpdateTradeStatusRes, DefaultError, UpdateTradeStatusReq>({
mutationFn: params => updatePostTradeStatus(params)
export const useUpdateTradeStatusMutation = () =>
useMutation({
mutationFn: (params: UpdateTradeStatusReq) => updatePostTradeStatus(params)
})

export const useDeletePostMutation = (postId: DeletePostReq) =>
useMutation({
mutationFn: () => deletePost(postId)
})
8 changes: 3 additions & 5 deletions src/apis/post/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,27 @@ import type {
ProductConditionCodes,
SortOptionsShape,
TradeStatusCodes,
TradeStatusType,
TradeTypeCodes
} from '@types'

export type GetPostRes = PostDetail

export type UpdatePostReq = {
postId: number
title: string
category: string
price: number
location: string
productCondition: ProductConditionCodes
tradeStatus: TradeStatusType
tradeStatus: TradeStatusCodes
tradeType: TradeTypeCodes
thumbnailImageUrl: string
imageUrls: string[]
description: string
}
export type UpdatePostRes = PostDetail

export type DeletePostReq = {
postId: number
}
export type DeletePostReq = number
export type DeletePostRes = {
// TODO: 정확한 타입 BE 확인 필요
}
Expand Down
14 changes: 6 additions & 8 deletions src/components/common/Dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@ import type { DialogProps } from './types'

const Dialog = ({ onClose, dialogPositionStyle, children }: DialogProps) => {
return (
<>
<Styled.DialogWrapper style={dialogPositionStyle}>
<Styled.DialogOverlay onClick={onClose} />
<Styled.DialogBox>
<Styled.DialogContent>{children}</Styled.DialogContent>
</Styled.DialogBox>
</Styled.DialogWrapper>
</>
<Styled.DialogWrapper style={dialogPositionStyle}>
<Styled.DialogOverlay onClick={onClose} />
<Styled.DialogBox>
<Styled.DialogContent>{children}</Styled.DialogContent>
</Styled.DialogBox>
</Styled.DialogWrapper>
)
}

Expand Down
25 changes: 16 additions & 9 deletions src/components/common/Header/SideBar/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Avatar, Divider, Icon, Badge } from '@offer-ui/react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import type { ReactElement } from 'react'
import React from 'react'
Expand All @@ -21,7 +20,7 @@ const NAV_DATA: NavDataType = [
},
{
content: '쪽지함',
url: '/message',
url: '/messagebox',
iconType: 'message'
}
]
Expand All @@ -32,11 +31,19 @@ export const SideBar = ({ isOpen, onClose }: SideBarProps): ReactElement => {

const handleClickLogin = () => {
router.replace(OAUTH_URL.KAKAO)

onClose()
}

const handleClickButton = (url: string) => {
router.push(url)

onClose()
}

const handleClickLogout = () => {
handleLogout()

onClose()
}

Expand Down Expand Up @@ -64,14 +71,14 @@ export const SideBar = ({ isOpen, onClose }: SideBarProps): ReactElement => {
)}
<Divider direction="horizontal" gap={16} length="259px" />
<Styled.SidebarMenuSection>
{NAV_DATA.map((item, index) => {
{NAV_DATA.map(({ iconType, content, url }) => {
return (
<Link key={index} href={item.url}>
<Styled.SidebarMenu>
<Icon size={16} type={item.iconType} />
{item.content}
</Styled.SidebarMenu>
</Link>
<Styled.SidebarMenu
key={content}
onClick={() => handleClickButton(url)}>
<Icon size={16} type={iconType} />
{content}
</Styled.SidebarMenu>
)
})}
</Styled.SidebarMenuSection>
Expand Down
2 changes: 2 additions & 0 deletions src/components/common/Header/SideBar/styled.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const SidebarMenu = styled.li`
align-items: center;
${({ theme }): string => theme.fonts.body01B};
color: ${({ theme }): string => theme.colors.grayScale90};
cursor: pointer;
`

const SidebarLogoutButton = styled.button`
Expand Down
Loading

0 comments on commit 20b6aa7

Please sign in to comment.