-
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 #24 from team-nabi/NABI-60
🎉 TradeStateCard 컴포넌트 구현
- Loading branch information
Showing
7 changed files
with
128 additions
and
3 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/components/domain/card/trade-state-card/TradeStateCard.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,74 @@ | ||
import formatDistanceToNow from 'date-fns/formatDistanceToNow' | ||
import koLocale from 'date-fns/locale/ko' | ||
import Badge from '@/components/ui/Badge' | ||
import Card from '@/components/ui/Card' | ||
import { CardFlex, CardImage, CardText } from '@/components/ui/Card/Card' | ||
import { Item } from '@/types' | ||
|
||
type TradeStateCardProps = { | ||
item: Item | ||
} | ||
type TradeStateMap = { | ||
[key: string]: { | ||
style: | ||
| 'primary' | ||
| 'secondary' | ||
| 'gradation' | ||
| 'information' | ||
| null | ||
| undefined | ||
text: string | ||
} | ||
} | ||
|
||
const TradeStateCard = ({ | ||
item: { image, cardTitle, tradeState, itemName, priceRange, createdAt }, | ||
}: TradeStateCardProps) => { | ||
const tradeStateMap: TradeStateMap = { | ||
possible: { | ||
style: 'primary', | ||
text: '거래가능', | ||
}, | ||
impossible: { | ||
style: 'secondary', | ||
text: '예약중', | ||
}, | ||
} | ||
|
||
return ( | ||
<Card size={'sm'}> | ||
<CardFlex | ||
direction={'row'} | ||
justify={'start'} | ||
align={'center'} | ||
gap={'space'} | ||
className="h-full" | ||
> | ||
<div className="h-full w-32 relative"> | ||
<CardImage | ||
src={image} | ||
alt="이미지가 없습니다." | ||
layout="fill" | ||
objectFit="cover" | ||
/> | ||
</div> | ||
|
||
<CardFlex direction={'col'} justify={'between'} className="h-full"> | ||
<CardFlex align={'center'} gap={'space'}> | ||
<CardText type={'title'}>{cardTitle}</CardText> | ||
<Badge variant={tradeStateMap[tradeState].style}> | ||
{tradeStateMap[tradeState].text} | ||
</Badge> | ||
</CardFlex> | ||
<CardText type={'description'}>{itemName}</CardText> | ||
<CardText type={'description'}>{priceRange}</CardText> | ||
<CardText type={'date'}> | ||
{formatDistanceToNow(new Date(createdAt), { locale: koLocale })} | ||
</CardText> | ||
</CardFlex> | ||
</CardFlex> | ||
</Card> | ||
) | ||
} | ||
|
||
export default TradeStateCard |
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,3 @@ | ||
import { default as TradeStateCard } from './TradeStateCard' | ||
|
||
export default TradeStateCard |
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,12 @@ | ||
export interface Item { | ||
_id: number | ||
cardId: number | ||
cardTitle: string | ||
itemName: string | ||
createdAt: string | ||
modifiedAt: string | ||
dibCount: number | ||
priceRange: string | ||
image: string | ||
tradeState: 'possible' | 'impossible' | ||
} |