-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SKP-189-notification] 푸시 랜딩 및 리스트 화면 API 연결 (#66)
- Loading branch information
Showing
26 changed files
with
418 additions
and
86 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {useMutation} from '@tanstack/react-query'; | ||
import {BaseResponse, PATCH} from '../../../apis/client'; | ||
|
||
interface CheckNotificationRequest { | ||
id: number; | ||
type: string; | ||
} | ||
|
||
/** | ||
* 푸시 확인 API | ||
*/ | ||
export const checkNotification = async (req: CheckNotificationRequest) => { | ||
const res = await PATCH<string>(`/api/notification/check`, req); | ||
return res.data; | ||
}; | ||
|
||
interface PatchFCMTokenProps { | ||
onSuccess: (res: BaseResponse<string>) => void; | ||
onError: (e: Error) => void; | ||
} | ||
|
||
export const usePatchNotification = ({ | ||
onSuccess, | ||
onError, | ||
}: PatchFCMTokenProps) => { | ||
return useMutation({ | ||
mutationFn: (req: CheckNotificationRequest) => checkNotification(req), | ||
onSuccess: onSuccess, | ||
onError: onError, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import {useMutation} from '@tanstack/react-query'; | ||
import {BaseResponse, POST} from '../../../apis/client'; | ||
import {checkPermission} from '../../../utils/pushUtils'; | ||
|
||
interface SendFCMPushRequest { | ||
token: string; | ||
isCategory: boolean; | ||
} | ||
|
||
/** | ||
* 테스트 푸시 전송용 | ||
*/ | ||
export const sendFCMPush = async (req: SendFCMPushRequest) => { | ||
const res = await POST<string>(`/api/fcm/test`, req); | ||
return res.data; | ||
}; | ||
|
||
interface PatchFCMTokenProps { | ||
onSuccess: (res: BaseResponse<string>) => void; | ||
onError: (e: Error) => void; | ||
} | ||
|
||
export const usePatchFCMToken = ({onSuccess, onError}: PatchFCMTokenProps) => { | ||
return useMutation({ | ||
mutationFn: (req: SendFCMPushRequest) => sendFCMPush(req), | ||
onSuccess: onSuccess, | ||
onError: onError, | ||
}); | ||
}; | ||
|
||
export const sendCategoryPush = async () => { | ||
const token = await checkPermission(); | ||
await sendFCMPush({token: token, isCategory: true}); | ||
}; | ||
|
||
export const sendDetailPush = async () => { | ||
const token = await checkPermission(); | ||
await sendFCMPush({token: token, isCategory: false}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import {useInfiniteQuery} from '@tanstack/react-query'; | ||
import {GET} from '../../../apis/client'; | ||
import {useCallback} from 'react'; | ||
import {NOTIFICATION_KEYS} from '../QueryKeys'; | ||
|
||
const getNotificationList = async (page: number) => { | ||
const { | ||
data: {result}, | ||
} = await GET<GetNotificationResponse>(`/api/notification?page=${page}`); | ||
|
||
console.log('>', result); | ||
return { | ||
notificationList: result.notificationList, | ||
nextPage: result.totalPage > page ? page + 1 : undefined, | ||
totalPage: result.totalPage, | ||
}; | ||
}; | ||
|
||
export interface NotificationDTO { | ||
id: number; | ||
title: string; | ||
body: string; | ||
type: string; | ||
isChecked: boolean; | ||
createdAt: string; | ||
} | ||
|
||
interface GetNotificationResponse { | ||
totalPage: number; | ||
notificationList: NotificationDTO[]; | ||
} | ||
|
||
const useGetNotification = (page: number) => { | ||
const {data, hasNextPage, fetchNextPage, isFetching} = useInfiniteQuery({ | ||
queryKey: NOTIFICATION_KEYS.list({page: page}), | ||
queryFn: ({pageParam = 1}: {pageParam?: number}) => | ||
getNotificationList(pageParam), | ||
getNextPageParam: lastPage => lastPage.nextPage, | ||
select: data => ({ | ||
pages: data.pages.flatMap(page => page.notificationList), | ||
}), | ||
initialPageParam: page, | ||
}); | ||
|
||
const loadMore = useCallback(() => { | ||
if (hasNextPage) { | ||
fetchNextPage(); | ||
} | ||
}, [hasNextPage, fetchNextPage]); | ||
|
||
return { | ||
data: data?.pages, | ||
loadMore, | ||
isFetching, | ||
hasNextPage, | ||
}; | ||
}; | ||
|
||
export default useGetNotification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.