Skip to content

Commit 15ebd2e

Browse files
committed
feat: 나의 판매 내역 완성
1 parent aaf52a2 commit 15ebd2e

11 files changed

Lines changed: 175 additions & 14 deletions

File tree

src/features/home/components/ItemCard/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import type { ItemInterface } from '@/features/home/types';
66
import ItemTokenList from '@/common/components/ItemTokenList';
77
import PriceToken from '@/features/home/components/ItemCard/PriceToken';
88
import getImageUrl from '@/common/utils/getImageUrl';
9+
import type { UserItemInterface } from '@/features/myTrade/types';
910

1011
interface Props {
11-
data: ItemInterface;
12+
data: ItemInterface | UserItemInterface;
1213
}
1314
const ItemCard = ({ data }: Props) => {
1415
const isRental = data.transactionTypes.includes('RENTAL');
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import client from '@/common/utils/client';
2+
import { useQuery } from '@tanstack/react-query';
3+
import { QUERY_KEYS } from '@/libs/queryKeys';
4+
import type { UserItemInterface } from '../types';
5+
6+
export interface UserItemResponse {
7+
message: string;
8+
data: UserItemInterface[];
9+
}
10+
11+
const getUserItem = async (userId: number) => {
12+
const res = await client.get<UserItemResponse>(`/api/v1/user/${userId}/item`);
13+
14+
console.log(res);
15+
16+
return res.data.data;
17+
};
18+
19+
export const useGetUserItem = (userId: number) => {
20+
return useQuery({
21+
queryKey: [QUERY_KEYS.USER_ITEM_LIST, userId],
22+
queryFn: () => getUserItem(userId),
23+
staleTime: 0,
24+
});
25+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import NoResult from '@/common/components/NoResult';
2+
import ItemCard from '@/features/home/components/ItemCard';
3+
4+
import * as s from './style.css';
5+
import { useGetUserItem } from '../../apis/useGetUserItem';
6+
import { useNavigate } from 'react-router';
7+
import NotFoundPage from '@/pages/NotFoundPage';
8+
import Btn from '@/common/components/Button';
9+
10+
interface Props {
11+
userId: number;
12+
}
13+
14+
const UserItemList = ({ userId }: Props) => {
15+
const { data: userItems, isSuccess, isLoading } = useGetUserItem(userId);
16+
const navigate = useNavigate();
17+
18+
if (isLoading) return null;
19+
if (!userItems) return <NotFoundPage />;
20+
21+
const isEmpty = isSuccess && userItems.length === 0;
22+
23+
return (
24+
<div className={s.Content({ isEmpty })}>
25+
{isEmpty ? (
26+
<div className={s.NoResult}>
27+
<NoResult type="like" />
28+
<Btn mode="main" className={s.Button} onClick={() => navigate('/')}>
29+
홈으로 돌아가기
30+
</Btn>
31+
</div>
32+
) : (
33+
userItems.map(item => <ItemCard key={item.itemId} data={item} />)
34+
)}
35+
</div>
36+
);
37+
};
38+
39+
export default UserItemList;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { css, cva } from '@styled-system/css';
2+
3+
export const Container = cva({
4+
base: {
5+
display: 'flex',
6+
flexDir: 'column',
7+
gap: '1rem',
8+
},
9+
variants: {
10+
isEmpty: {
11+
true: {
12+
justifyContent: 'center',
13+
alignItems: 'center',
14+
height: '100%',
15+
},
16+
},
17+
},
18+
});
19+
20+
export const Wrapper = css({
21+
display: 'flex',
22+
flexDir: 'column',
23+
flex: 1,
24+
h: '100%',
25+
});
26+
27+
export const NoResult = css({
28+
display: 'flex',
29+
flexDir: 'column',
30+
gap: '1rem',
31+
alignItems: 'center',
32+
});
33+
34+
export const Content = cva({
35+
base: {
36+
display: 'flex',
37+
flexDir: 'column',
38+
p: '1rem',
39+
overflowY: 'auto',
40+
gap: '1rem',
41+
},
42+
variants: {
43+
isEmpty: {
44+
true: {
45+
justifyContent: 'center',
46+
alignItems: 'center',
47+
height: '100%',
48+
},
49+
},
50+
},
51+
});
52+
53+
export const Button = css({
54+
width: '17rem',
55+
});

src/features/myTrade/types.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import type { Color, ProductType, Quality, Size, TradeMethods, TransactionType } from '@/libs/types/item';
2+
3+
export interface UserItemInterface {
4+
itemId: number;
5+
productTypes: ProductType[];
6+
transactionTypes: TransactionType[];
7+
thumbnail: string;
8+
title: string;
9+
rentalFee: number;
10+
salePrice: number;
11+
deposit: number;
12+
size: Size;
13+
color: Color;
14+
quality: Quality;
15+
tradeMethods: TradeMethods[];
16+
likeCount: number;
17+
chatRoomCount: number;
18+
repostDate: string;
19+
isSold: boolean;
20+
}

src/libs/queryKeys.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export const QUERY_KEYS = {
99
ITEM_COUNT: 'item-count', // 상품 검색 결과 개수
1010
ITEM_CHAT_LIST: 'item-chat', // 특정 아이템에 대한 채팅 리스트
1111
LIKE_LIST: 'like', // 내 좋아요 목록
12+
USER_ITEM_LIST: 'user-item-list', // 특정 유저의 아이템 리스트
1213
USER: 'user', // 내 정보
1314
PICK_DETAIL: 'pick', // 특정 id에 해당하는 약속 상세
1415
APPOINTMENT_LIST: 'pick-list', // 나의 픽 페이지 리스트

src/pages/MyItemPage/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import CustomHeader from '@/common/components/CustomHeader';
2+
import SafeArea from '@/common/components/SafeArea';
3+
import { useGetUser } from '@/features/my/apis/useGetUser';
4+
import UserItemList from '@/features/myTrade/components/myTradeItemList';
5+
import { useNavigate } from 'react-router';
6+
import NotFoundPage from '../NotFoundPage';
7+
import * as s from './style.css';
8+
9+
const MyItemPage = () => {
10+
const navigate = useNavigate();
11+
const { data: getUser } = useGetUser();
12+
13+
if (!getUser) return <NotFoundPage />;
14+
15+
return (
16+
<SafeArea>
17+
<CustomHeader onClick={() => navigate(-1)} title="나의 판매 내역" />
18+
<div className={s.Wrapper}>
19+
<UserItemList userId={getUser?.id} />
20+
</div>
21+
</SafeArea>
22+
);
23+
};
24+
25+
export default MyItemPage;

src/pages/MyItemPage/style.css.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { css } from '@styled-system/css';
2+
3+
export const Wrapper = css({
4+
display: 'flex',
5+
flex: 1,
6+
height: 'calc(100% - {sizes.HEADER_HEIGHT})',
7+
});

src/pages/MyTradePage/index.tsx

Lines changed: 0 additions & 12 deletions
This file was deleted.

src/pages/MyTradePage/style.css.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)