Skip to content

Commit

Permalink
feat: 상품 상세 페이지 api 연결 (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
shinhyojeong authored Dec 27, 2023
2 parents 772d64c + 8bfd960 commit dfbd073
Show file tree
Hide file tree
Showing 24 changed files with 287 additions and 408 deletions.
7 changes: 7 additions & 0 deletions src/apis/offer/apis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import type { GetPostOffersReq, GetPostOffersRes } from './types'
import { http } from '@utils/http'

export const getPostOffers = (postId: number) =>
http.get<GetPostOffersReq, GetPostOffersRes>(`/posts/${postId}/offers`, {
postId
})
1 change: 1 addition & 0 deletions src/apis/offer/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './types'
export * from './queries'
8 changes: 8 additions & 0 deletions src/apis/offer/queries.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { useQuery } from '@tanstack/react-query'
import { getPostOffers } from './apis'

export const useGetPostOffersQuery = (postId: number) =>
useQuery({
queryKey: ['getPostOffers', postId],
queryFn: () => getPostOffers(postId)
})
1 change: 0 additions & 1 deletion src/apis/offer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import type { CommonCreation, Offers, OfferSummaries } from '@types'

export type GetPostOffersReq = {
postId: number
page: number
}
export type GetPostOffersRes = Offers

Expand Down
6 changes: 5 additions & 1 deletion src/apis/post/apis.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import type {
GetCategoriesRes,
GetPostRes,
CreatePostReq,
CreatePostRes,
GetCategoriesRes,
GetPostsReq,
GetPostsRes
} from './types'
import { http } from '@utils/http'

export const getPost = (id: number) =>
http.get<null, GetPostRes>(`/posts/${id}`)

export const createPost = (param: CreatePostReq) =>
http.post<CreatePostReq, CreatePostRes>('/posts', param)

Expand Down
2 changes: 1 addition & 1 deletion src/apis/post/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './types'
export * from './queries'
export * from './types'
8 changes: 7 additions & 1 deletion src/apis/post/queries.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import { useMutation, useQuery, useInfiniteQuery } from '@tanstack/react-query'
import { getCategories, createPost, getPosts } from './apis'
import { getPost, getCategories, createPost, getPosts } from './apis'
import type { CreatePostReq, GetPostsReq, GetPostsRes } from './types'

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

export const useGetPostQuery = (id: number) =>
useQuery({
queryKey: ['getPost', id],
queryFn: () => getPost(id)
})

export const useGetCategoriesQuery = () =>
useQuery({
queryKey: ['getCategories'],
Expand Down
16 changes: 0 additions & 16 deletions src/components/post/PostField/PostField.stories.tsx

This file was deleted.

24 changes: 0 additions & 24 deletions src/components/post/PostField/index.tsx

This file was deleted.

7 changes: 0 additions & 7 deletions src/components/post/PostField/types.ts

This file was deleted.

21 changes: 21 additions & 0 deletions src/components/post/PostFieldList/PostFieldList.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { Meta, StoryObj } from '@storybook/react'
import { PostFieldList as PostFieldListComponent } from './index'

type PostFieldList = typeof PostFieldListComponent

const meta: Meta<PostFieldList> = {
component: PostFieldListComponent,
title: 'Post/PostFieldList'
}

export default meta

export const Default: StoryObj<PostFieldList> = {
args: {
date: '1시간 전',
productCondition: '새상품',
tradeType: '직거래',
location: '관악구'
},
render: args => <PostFieldListComponent {...args} />
}
46 changes: 46 additions & 0 deletions src/components/post/PostFieldList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { Divider, Text } from '@offer-ui/react'
import type { ReactElement } from 'react'
import { Styled } from './styled'
import type { PostFieldListProps } from './types'

const PostFieldList = ({
productCondition,
tradeType,
date,
location,
height = 50
}: PostFieldListProps): ReactElement => {
const fields = [
{
label: '작성일',
value: date
},
{
label: '상품 상태',
value: productCondition
},
{
label: '거래 방식',
value: tradeType
},
{ label: '거래 지역', value: location }
]

return (
<>
{fields.map(({ label, value }) => (
<Styled.PostFieldList key={label}>
<Divider direction="vertical" length={`${height}px`} />
<Styled.TextWrapper height={height}>
<Text color="grayScale70" styleType="body02M">
{label}
</Text>
<Text styleType="subtitle01B">{value}</Text>
</Styled.TextWrapper>
</Styled.PostFieldList>
))}
</>
)
}

export { PostFieldListProps, PostFieldList }
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import styled from '@emotion/styled'
import type { StyledTextWrapperProps } from './types'

const PostField = styled.div`
const PostFieldList = styled.div`
display: flex;
gap: 12px;
`
Expand All @@ -15,6 +15,6 @@ const TextWrapper = styled.div<StyledTextWrapperProps>`
`

export const Styled = {
PostField,
PostFieldList,
TextWrapper
}
14 changes: 14 additions & 0 deletions src/components/post/PostFieldList/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
export type PostField = {
label: string
value: string
}

export type PostFieldListProps = {
date: string
location: string
productCondition: string
tradeType: string
height?: number
}

export type StyledTextWrapperProps = StyledProps<PostFieldListProps, 'height'>
Loading

0 comments on commit dfbd073

Please sign in to comment.