-
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.
- Loading branch information
1 parent
228f4d0
commit b63bb12
Showing
11 changed files
with
203 additions
and
32 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
src/app/(root)/(routes)/items/[itemId]/components/trade-section/SuggestList.tsx
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,56 @@ | ||
import SuggestCard from '@/components/domain/card/suggest-card' | ||
import { Tabs, TabsTrigger, TabsList, TabsContent } from '@/components/ui/Tabs' | ||
import { getSuggestions } from '@/services/suggest/suggest' | ||
import { ItemSuggestion } from '@/types' | ||
|
||
type SuggestListProps = { | ||
itemId: string | ||
} | ||
|
||
async function getSuggestionsValue(itemId: string) { | ||
try { | ||
const res = await getSuggestions(itemId) | ||
const data = await res.json() | ||
|
||
return data.data.cardList | ||
} catch (e) { | ||
console.log(e) | ||
} | ||
} | ||
/** | ||
* TODO : 스크롤바 디자인 수정 | ||
* TODO : 실제 API 연결(useMutation 사용해서) | ||
*/ | ||
const SuggestList = async ({ itemId }: SuggestListProps) => { | ||
const suggestions = await getSuggestionsValue(itemId) | ||
return ( | ||
<Tabs defaultValue="offer"> | ||
<TabsList> | ||
<TabsTrigger value="offer">오퍼하기</TabsTrigger> | ||
<TabsTrigger value="poke">찔러보기</TabsTrigger> | ||
</TabsList> | ||
{['offer', 'poke'].map((type) => ( | ||
<TabsContent | ||
key={type} | ||
value={type} | ||
className=" data-[state=inactive]:hidden h-[402px] overflow-y-auto" | ||
> | ||
{suggestions | ||
.filter((v: ItemSuggestion) => v.suggestionType === type) | ||
.map((v: ItemSuggestion) => ( | ||
<SuggestCard | ||
key={v.cardId} | ||
thumbNail={v.thumbNail} | ||
cardTitle={v.cardTitle} | ||
itemName={v.itemName} | ||
priceRange={v.priceRange} | ||
suggestionType={v.suggestionType} | ||
/> | ||
))} | ||
</TabsContent> | ||
))} | ||
</Tabs> | ||
) | ||
} | ||
|
||
export default SuggestList |
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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import authHandlers from './authHandlers' | ||
import { itemHandlers } from './itemHandlers' | ||
import { suggestHandlers } from './suggestHandlers' | ||
import { testHandlers } from './testHandler' | ||
|
||
export const handlers = [...testHandlers, ...authHandlers, ...itemHandlers] | ||
export const handlers = [ | ||
...testHandlers, | ||
...authHandlers, | ||
...itemHandlers, | ||
...suggestHandlers, | ||
] |
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,70 @@ | ||
import { rest } from 'msw' | ||
import ApiEndPoint from '@/config/apiEndPoint' | ||
import { Environment } from '@/config/environment' | ||
import { DEFAULT_ITEM_THUMBNAIL_IMG } from '@/constants/image' | ||
|
||
const baseUrl = Environment.apiAddress() | ||
|
||
export const suggestHandlers = [ | ||
rest.get( | ||
`${baseUrl}${ApiEndPoint.suggestions('3')}`, | ||
async (_req, res, ctx) => { | ||
return res( | ||
ctx.status(200), | ||
ctx.json({ | ||
code: 'S001', | ||
message: '성공했습니다.', | ||
data: { | ||
cardList: [ | ||
{ | ||
_id: 1, | ||
cardId: 1, | ||
thumbNail: DEFAULT_ITEM_THUMBNAIL_IMG, | ||
cardTitle: 'xxx', | ||
itemName: '다이슨 청소기', | ||
priceRange: '10만원대', | ||
suggestionType: 'offer', | ||
}, | ||
{ | ||
_id: 2, | ||
cardId: 2, | ||
thumbNail: DEFAULT_ITEM_THUMBNAIL_IMG, | ||
cardTitle: 'xxx', | ||
itemName: '애플 워치', | ||
priceRange: '20만원대', | ||
suggestionType: 'poke', | ||
}, | ||
{ | ||
_id: 3, | ||
cardId: 5, | ||
thumbNail: DEFAULT_ITEM_THUMBNAIL_IMG, | ||
cardTitle: 'xxx', | ||
itemName: '에어팟 프로', | ||
priceRange: '20만원대', | ||
suggestionType: 'poke', | ||
}, | ||
{ | ||
_id: 3, | ||
cardId: 6, | ||
thumbNail: DEFAULT_ITEM_THUMBNAIL_IMG, | ||
cardTitle: 'xxx', | ||
itemName: '에어팟 프로', | ||
priceRange: '20만원대', | ||
suggestionType: 'poke', | ||
}, | ||
{ | ||
_id: 3, | ||
cardId: 7, | ||
thumbNail: DEFAULT_ITEM_THUMBNAIL_IMG, | ||
cardTitle: 'xxx', | ||
itemName: '에어팟 프로', | ||
priceRange: '20만원대', | ||
suggestionType: 'poke', | ||
}, | ||
], | ||
}, | ||
}), | ||
) | ||
}, | ||
), | ||
] |
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,9 @@ | ||
import ApiEndPoint from '@/config/apiEndPoint' | ||
import apiClient from '../apiClient' | ||
|
||
const getSuggestions = async (itemId: string) => { | ||
const response = await apiClient.get(ApiEndPoint.suggestions(itemId)) | ||
return response | ||
} | ||
|
||
export { getSuggestions } |
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