Skip to content

Commit 60f29e8

Browse files
authored
Merge pull request #223 from DevKor-github/fix/#221/notificaiton-apo
[fix] notification 바뀐 api λŒ€μ‘
2 parents fdaef0e + 17e6349 commit 60f29e8

5 files changed

Lines changed: 102 additions & 40 deletions

File tree

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,57 @@
11
import client from '@/common/utils/client';
22
import { QUERY_KEYS } from '@/libs/queryKeys';
3-
import { useQuery } from '@tanstack/react-query';
3+
import { useInfiniteQuery } from '@tanstack/react-query';
44
import type { NotificationInterface } from '../types';
55

6+
export interface GetNotificationRequest {
7+
pageSize: number;
8+
cursorId?: string | null;
9+
cursorCreatedAt?: string | null;
10+
}
11+
612
export interface NotificationResponse {
713
message: string;
8-
data: NotificationInterface[];
14+
data: {
15+
notifications: NotificationInterface[];
16+
pageInfo: {
17+
hasNext: boolean;
18+
cursorCreatedAt: string | null;
19+
cursorId: string | null;
20+
};
21+
};
22+
version: string;
23+
}
24+
25+
interface PageParam {
26+
cursorid?: string | null;
27+
cursorCreatedAt?: string | null;
928
}
1029

11-
const getNotification = async () => {
12-
const res = await client.get<NotificationResponse>('api/v1/notification');
30+
const getNotification = async (params: GetNotificationRequest) => {
31+
const res = await client.get<NotificationResponse>('api/v1/notification', {
32+
params,
33+
});
34+
1335
return res.data.data;
1436
};
1537

16-
export const useGetNotification = () => {
17-
return useQuery({
18-
queryKey: [QUERY_KEYS.NOTIFICATION_LIST],
19-
queryFn: getNotification,
38+
export const useGetNotification = (params: GetNotificationRequest) => {
39+
const initialPageParam: PageParam = {};
40+
41+
return useInfiniteQuery({
42+
queryKey: [QUERY_KEYS.APPOINTMENT_LIST, params],
43+
queryFn: ({ pageParam }) => getNotification({ ...params, ...pageParam }),
44+
getNextPageParam: lastPage =>
45+
lastPage.pageInfo.hasNext
46+
? {
47+
cursorId: lastPage.pageInfo.cursorId,
48+
cursorCreatedAt: lastPage.pageInfo.cursorCreatedAt,
49+
}
50+
: undefined,
51+
initialPageParam,
52+
select: data => data.pages.flatMap(page => page.notifications),
2053
staleTime: 0,
2154
});
2255
};
56+
57+
export default useGetNotification;

β€Žsrc/features/notification/components/NotificationItemCard/index.tsxβ€Ž

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ interface Props {
1212
}
1313

1414
const NotificationItemCard = ({ data }: Props) => {
15-
const isRental = data.item.transactionTypes.includes('RENTAL');
16-
const isSale = data.item.transactionTypes.includes('SALE');
17-
const isDirect = data.item.tradeMethods.includes('DIRECT');
18-
const type = data.type;
15+
const isRental = data.itemInfo.transactionTypes.includes('RENTAL');
16+
const isSale = data.itemInfo.transactionTypes.includes('SALE');
17+
const isDirect = data.itemInfo.tradeMethods.includes('DIRECT');
18+
const type = data.notificationInfo.type;
1919
const isRemind = type === 'APPOINTMENT_RENTAL_REMIND' || type === 'APPOINTMENT_RETURN_REMIND';
20-
const remindDate = type === 'APPOINTMENT_RENTAL_REMIND' ? data.rentalDate : data.returnDate;
20+
const remindDate =
21+
type === 'APPOINTMENT_RENTAL_REMIND' ? data.appointmentInfo.rentalDate : data.appointmentInfo.returnDate;
2122

2223
const label = (() => {
2324
if (type === 'APPOINTMENT_CANCEL') return 'λ‚˜μ˜ Pick이 μ·¨μ†Œλμ–΄μš”.';
@@ -55,37 +56,37 @@ const NotificationItemCard = ({ data }: Props) => {
5556
</div>
5657
)}
5758
</div>
58-
<Link className={s.Container} to={`/pick-detail/${data.appointmentId}`}>
59-
<img className={s.Image} src={getImageUrl(data.item.thumbnail)} aria-hidden />
59+
<Link className={s.Container} to={`/pick-detail/${data.appointmentInfo.id}`}>
60+
<img className={s.Image} src={getImageUrl(data.itemInfo.thumbnail)} aria-hidden />
6061
<div className={s.Info}>
6162
<div className={s.Header}>
62-
<h2 className={s.Title}>{data.item.title}</h2>
63+
<h2 className={s.Title}>{data.itemInfo.title}</h2>
6364
<div className={s.Price}>
64-
{isRental && <PriceToken price={data.item.rentalFee} deposit={data.item.deposit} />}
65-
{isSale && <PriceToken price={data.item.salePrice} />}
65+
{isRental && <PriceToken price={data.itemInfo.rentalFee} deposit={data.itemInfo.deposit} />}
66+
{isSale && <PriceToken price={data.itemInfo.salePrice} />}
6667
</div>
6768
</div>
6869
<div className={s.Footer}>
6970
<div className={s.Tokens}>
7071
<ItemTokenList
7172
showCount={3}
7273
itemInfo={{
73-
productTypes: data.item.productTypes,
74-
quality: data.item.quality,
75-
size: data.item.size,
76-
color: data.item.color,
77-
tradeMethods: data.item.tradeMethods,
74+
productTypes: data.itemInfo.productTypes,
75+
quality: data.itemInfo.quality,
76+
size: data.itemInfo.size,
77+
color: data.itemInfo.color,
78+
tradeMethods: data.itemInfo.tradeMethods,
7879
}}
7980
/>
8081
</div>
8182
<div className={s.Interactions}>
8283
<div className={s.InteractionItem}>
8384
<span className="mgc_heart_fill" />
84-
<p>{data.item.likeCount}</p>
85+
<p>{data.itemInfo.likeCount}</p>
8586
</div>
8687
<div className={s.InteractionItem}>
8788
<span className="mgc_chat_2_fill" />
88-
<p>{data.item.chatRoomCount}</p>
89+
<p>{data.itemInfo.chatRoomCount}</p>
8990
</div>
9091
</div>
9192
</div>

β€Žsrc/features/notification/components/NotificationList/index.tsxβ€Ž

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import type { NotificationInterface } from '../../types';
22
import NotificationItemCard from '../NotificationItemCard';
33

44
interface Props {
5-
notifications: NotificationInterface[];
5+
notification: NotificationInterface;
66
}
77

8-
const NotificationList = ({ notifications }: Props) => {
8+
const NotificationList = ({ notification }: Props) => {
99
return (
1010
<>
11-
{notifications.map(item => (
12-
<NotificationItemCard data={item} />
13-
))}
11+
{/* {notifications.map(item => ( */}
12+
<NotificationItemCard data={notification} />
13+
{/* ))} */}
1414
</>
1515
);
1616
};

β€Žsrc/features/notification/types.tsβ€Ž

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const NOTIFICATION_TYPE_ARRAY = [
1212
] as const;
1313
export type NotificationType = (typeof NOTIFICATION_TYPE_ARRAY)[number];
1414

15-
export interface ItemNotificationInterface {
15+
export interface ItemInfoInterface {
1616
itemId: number;
1717
productTypes: ProductType[];
1818
transactionTypes: TransactionType[];
@@ -28,14 +28,23 @@ export interface ItemNotificationInterface {
2828
likeCount: number;
2929
chatRoomCount: number;
3030
repostDate: string;
31+
isDeleted: boolean;
3132
}
3233

33-
export interface NotificationInterface {
34-
notificationId: number;
35-
item: ItemNotificationInterface;
36-
appointmentId: number;
37-
rentalDate: string;
38-
returnDate: string;
34+
export interface notificationInfoInterface {
35+
id: number;
3936
type: NotificationType;
4037
createdAt: string;
4138
}
39+
40+
export interface appointmentInfoInterface {
41+
id: number;
42+
rentalDate: string;
43+
returnDate: string;
44+
}
45+
46+
export interface NotificationInterface {
47+
notificationInfo: notificationInfoInterface;
48+
appointmentInfo: appointmentInfoInterface;
49+
itemInfo: ItemInfoInterface;
50+
}

β€Žsrc/pages/NotificationPage/index.tsxβ€Ž

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,26 @@ import NotFoundPage from '../NotFoundPage';
77
import Btn from '@/common/components/Button';
88
import NoResult from '@/common/components/NoResult';
99
import NotificationList from '@/features/notification/components/NotificationList';
10+
import { CHAT_PAGING_SIZE } from '@/libs/constants';
11+
import Pagination from '@/common/components/Pagination';
1012

1113
const NotigicationPage = () => {
1214
const navigate = useNavigate();
13-
const { data: notifications, isLoading } = useGetNotification();
15+
const {
16+
data: notifications = [],
17+
isSuccess,
18+
hasNextPage,
19+
isFetchingNextPage,
20+
fetchNextPage,
21+
isLoading,
22+
} = useGetNotification({
23+
pageSize: CHAT_PAGING_SIZE,
24+
});
1425

1526
if (isLoading) return null;
1627
if (!notifications) return <NotFoundPage />;
1728

18-
const isEmpty = notifications.length === 0;
29+
const isEmpty = (isSuccess && notifications.length) === 0;
1930

2031
return (
2132
<SafeArea>
@@ -30,7 +41,13 @@ const NotigicationPage = () => {
3041
</Btn>
3142
</div>
3243
) : (
33-
<NotificationList notifications={notifications} />
44+
<Pagination
45+
fetchNextPage={fetchNextPage}
46+
items={notifications}
47+
render={item => <NotificationList key={item.appointmentInfo.id} notification={item} />}
48+
hasNextPage={hasNextPage}
49+
isFetchingNextPage={isFetchingNextPage}
50+
/>
3451
)}
3552
</div>
3653
</div>

0 commit comments

Comments
Β (0)