Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐ŸŽ‰ ๋กœ๊ทธ์ธ ์œ ๋ฌด์— ๋”ฐ๋ผ ๋ณด์ด๋Š” UI ๋ณ€๊ฒฝ #42

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,29 @@ type TradeStateMap = {
}

const DescriptionSection = ({
itemData: { status, cardTitle, category, createdAt, dibs, content, cardId },
itemData: {
status,
cardTitle,
category,
createdAt,
dibs,
content,
cardId,
userId: authorId,
},
}: DescriptionSectionProps) => {
// FIX : ๋กœ๊ทธ์ธ ๊ด€๋ จ ์™„์„ฑ๋˜๋ฉด ์‹ค์ œ ๋ฐ์ดํ„ฐ๋กœ ์ˆ˜์ •
// const { isLoggedIn } = useAuth()
// const {currentUser} = useAuth();

const currentUser = {
imageUrl: 'http://asdf~',
nickname: '๋ณ‘์›์— ๊ฐ„ ๋ฏธ์–ด์บฃ',
userId: 3,
}
const isLoggedIn = true
const isMyItem = currentUser.userId === authorId

const tradeStateMap: TradeStateMap = {
TRADE_AVAILABLE: {
style: 'primary',
Expand All @@ -49,7 +70,7 @@ const DescriptionSection = ({
{tradeStateMap[status].text}
</Badge>
<h3 className={cn('ml-2', TYPHOGRAPHY.title)}>{cardTitle}</h3>
<MoreButton />
{isLoggedIn && isMyItem && <MoreButton />}
</div>
<div className="flex flex-row items-center">
<p
Expand All @@ -63,7 +84,7 @@ const DescriptionSection = ({
<p className={cn('text-text-secondary-color', TYPHOGRAPHY.description)}>
{createdAt}
</p>
<Dibs itemId={cardId} dibsData={dibs} />
{isLoggedIn && <Dibs itemId={cardId} dibsData={dibs} />}
</div>
<p className="">{content}</p>
</article>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Tabs, TabsTrigger, TabsList, TabsContent } from '@/components/ui/Tabs'
import { ItemSuggestion } from '@/types'

type SuggestListProps = {
suggestionData: []
suggestionData: ItemSuggestion[]
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
'use client'

import { useEffect, useState } from 'react'
import Button from '@/components/ui/Button'
import {
Dialog,
Expand All @@ -14,6 +17,7 @@ type TradeSectionProps = {
priceRange: string
tradeType: string
tradeArea: string
authorId: number
itemId: string
}

Expand All @@ -23,31 +27,57 @@ type TradeInfo = {
variant: 'primary' | 'information'
}

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)
}
}

const TradeSection = async ({
const TradeSection = ({
priceRange,
tradeType,
tradeArea,
authorId,
itemId,
}: TradeSectionProps) => {
const suggestions = await getSuggestionsValue(itemId)
// FIX : ๋กœ๊ทธ์ธ ๊ด€๋ จ ์™„์„ฑ๋˜๋ฉด ์‹ค์ œ ๋ฐ์ดํ„ฐ๋กœ ์ˆ˜์ •
// const { isLoggedIn } = useAuth()
// const {currentUser} = useAuth();

const currentUser = {
imageUrl: 'http://asdf~',
nickname: '๋ณ‘์›์— ๊ฐ„ ๋ฏธ์–ด์บฃ',
userId: 3,
}

const isLoggedIn = true
const isMyItem = currentUser.userId === authorId
const [suggestions, setSuggestions] = useState([])
const [open, setOpen] = useState(false)

const tradeInfo: TradeInfo[] = [
{ title: '๊ฐ€๊ฒฉ๋Œ€', content: priceRange, variant: 'primary' },
{ title: '๊ฑฐ๋ž˜ ๋ฐฉ์‹', content: tradeType, variant: 'information' },
{ title: '๊ฑฐ๋ž˜ ์ง€์—ญ', content: tradeArea, variant: 'information' },
]

const onClickButton = () => {
if (isMyItem) {
alert('์ œ์•ˆํ™•์ธ ํŽ˜์ด์ง€๋กœ ์ด๋™ํ•˜๊ธฐ')
} else {
setOpen(true)
}
}

useEffect(() => {
async function getSuggestionsValue(itemId: string) {
try {
const res = await getSuggestions(itemId)
if (res.status == 200) {
const data = await res.json()
setSuggestions(data.data.cardList)
}
} catch (e) {
console.log(e)
}
}
getSuggestionsValue(itemId)
}, [itemId])

return (
<section className="flex flex-col gap-2 w-full pt-4">
{tradeInfo.map((v, i) => (
Expand All @@ -58,13 +88,13 @@ const TradeSection = async ({
variant={v.variant}
/>
))}
{isLoggedIn && (
<Button className="mt-6" variant={'primary'} onClick={onClickButton}>
{isMyItem ? '์ œ์•ˆ ํ™•์ธํ•˜๊ธฐ' : '๊ฑฐ๋ž˜ ์ œ์•ˆํ•˜๊ธฐ'}
</Button>
)}

<Dialog>
<DialogTrigger asChild>
<Button className="mt-6" variant={'primary'}>
์ œ์•ˆ ํ™•์ธํ•˜๊ธฐ
</Button>
</DialogTrigger>
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent className="p-4 pt-14 gap-6 max-h-[576px]">
<DialogHeader>
<DialogTitle>์ œ์•ˆ ๊ฐ€๋Šฅํ•œ ๋‚ด ๋ฌผ๊ฑด ๋ณด๊ธฐ</DialogTitle>
Expand Down
3 changes: 2 additions & 1 deletion src/app/(root)/(routes)/items/[itemId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ async function getItemValue(itemId: string) {
const ItemPage = async ({ params }: ItemPageProps) => {
const data = await getItemValue(params.itemId)
console.log(data)
const { cardId, userName, priceRange, tradeType, tradeArea } = data
const { cardId, userName, priceRange, tradeType, tradeArea, userId } = data

return (
<main className="flex-col min-h-screen bg-background-color">
Expand All @@ -35,6 +35,7 @@ const ItemPage = async ({ params }: ItemPageProps) => {
priceRange={priceRange}
tradeType={tradeType}
tradeArea={tradeArea}
authorId={userId}
itemId={cardId}
/>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/lib/msw/mocks/itemHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const itemHandlers = [
modifiedAt: '2023-10-24-20:08',
},
],
userId: 1,
userId: 3,
userName: '์™•์ฉŒ๋Š” ๊ตฌ๋ฒ”๋ชจ',
tradeType: '์ง๊ฑฐ๋ž˜',
tradeArea: '์„œ์šธ์‹œ ์„ฑ๋™๊ตฌ',
Expand Down