generated from Bside-Team-Four/nextjs-starter
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from Bside-Team-Four/feature/101
feat: reward api
- Loading branch information
Showing
12 changed files
with
193 additions
and
62 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,12 +1,9 @@ | ||
'use client'; | ||
|
||
import RewardHistory from '@/components/reward-history'; | ||
import fixtures from '@/fixtures'; | ||
|
||
export default function RewardHistoryPage() { | ||
const { reward } = fixtures; | ||
|
||
return ( | ||
<RewardHistory reward={reward} /> | ||
<RewardHistory /> | ||
); | ||
} |
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
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,38 @@ | ||
import { useInView } from 'react-intersection-observer'; | ||
|
||
import { renderHook, waitFor } from '@testing-library/react'; | ||
|
||
import fixtures from '@/fixtures'; | ||
import { apiService } from '@/lib/api/ApiService'; | ||
import wrapper from '@/test/ReactQueryWrapper'; | ||
|
||
import useGetInfiniteReward from './useGetInfiniteRewards'; | ||
|
||
jest.mock('@/lib/api/ApiService'); | ||
|
||
describe('useGetInfiniteRewards', () => { | ||
const renderUseGetRewardsHook = () => renderHook(() => useGetInfiniteReward(), { | ||
wrapper, | ||
}); | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
|
||
(apiService.fetchGetRewards as jest.Mock).mockImplementation(() => ( | ||
{ | ||
value: fixtures.reward, | ||
} | ||
)); | ||
(useInView as jest.Mock).mockImplementation(() => ({ | ||
ref: jest.fn(), | ||
inView: given.inView, | ||
})); | ||
}); | ||
|
||
it('returns reward data', async () => { | ||
const { result } = renderUseGetRewardsHook(); | ||
await waitFor(() => { | ||
expect(result.current.rewards).toEqual(fixtures.reward); | ||
}); | ||
}); | ||
}); |
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,43 @@ | ||
import { useInfiniteQuery } from '@tanstack/react-query'; | ||
import _ from 'lodash/fp'; | ||
|
||
import useIntersectionObserver from '@/hooks/useIntersectionObserver'; | ||
import { apiService } from '@/lib/api/ApiService'; | ||
|
||
export const GET_INFINITE_REWARD_KEY = 'getInfiniteRewards'; | ||
|
||
export default function useGetInfiniteRewards() { | ||
const query = useInfiniteQuery( | ||
[GET_INFINITE_REWARD_KEY], | ||
async ({ pageParam: lastId }) => apiService.fetchGetRewards(lastId), | ||
{ | ||
getNextPageParam: (res) => { | ||
if (res.value.length < 30) return undefined; | ||
const lastId = res.value[res.value.length - 1].historyId; | ||
return lastId; | ||
}, | ||
}, | ||
); | ||
|
||
const refState = useIntersectionObserver<HTMLDivElement>({ | ||
intersectionOptions: { | ||
rootMargin: '20px', | ||
}, | ||
isRoot: true, | ||
fetchNextPage: query.fetchNextPage, | ||
hasNextPage: query.hasNextPage, | ||
}); | ||
|
||
const rewards = query.data ? _.flatten( | ||
query.data.pages.map((res) => res.value), | ||
) : []; | ||
|
||
const isEmpty = rewards.length === 0; | ||
|
||
return { | ||
...query, | ||
rewards, | ||
isEmpty, | ||
refState, | ||
}; | ||
} |
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
Oops, something went wrong.
5d5c5e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
popo-client – ./
popo-client-popo.vercel.app
popo-client.vercel.app
popo-client-git-main-popo.vercel.app