|
| 1 | +import { ROUTES } from '@shared/constants'; |
| 2 | +import { Button } from '@shared/ui/Button'; |
| 3 | +import { Card } from '@shared/ui/Card'; |
| 4 | +import { FavoriteButton } from '@shared/ui/FavoriteButton'; |
| 5 | +import { Profile } from '@shared/ui/Profile'; |
| 6 | +import { useMemo } from 'react'; |
| 7 | +import { Link, useNavigate, useParams } from 'react-router'; |
| 8 | +import { buildDetailInfo } from '../model/buildDetailInfo'; |
| 9 | +import { getBuyItemById, getBuyItems } from '../model/buyRepository'; |
| 10 | + |
| 11 | +export default function BuyDetailPage() { |
| 12 | + const navigate = useNavigate(); |
| 13 | + const { id } = useParams(); |
| 14 | + |
| 15 | + const item = useMemo(() => getBuyItemById(id), [id]); |
| 16 | + |
| 17 | + const detailInfo = useMemo(() => (item ? buildDetailInfo(item) : ''), [item]); |
| 18 | + |
| 19 | + const similarItems = useMemo(() => { |
| 20 | + if (!item) { |
| 21 | + return []; |
| 22 | + } |
| 23 | + // NOTE: API 연동 시 추천/유사 상품 서버 로직으로 대체 |
| 24 | + return getBuyItems() |
| 25 | + .filter((entry) => entry.id !== item.id && entry.model === item.model) |
| 26 | + .slice(0, 4); |
| 27 | + }, [item]); |
| 28 | + |
| 29 | + if (!item) { |
| 30 | + return ( |
| 31 | + <main className="min-h-screen bg-white pb-20"> |
| 32 | + <div className="mx-auto w-full max-w-[1200px] px-4 pt-10"> |
| 33 | + <section className="bg-white px-6 py-16 text-center text-gray-600"> |
| 34 | + 상품을 찾을 수 없어요. |
| 35 | + <div className="mt-6 flex justify-center"> |
| 36 | + <Button size="auto" onClick={() => navigate(ROUTES.BUY, { viewTransition: true })}> |
| 37 | + 구매 목록으로 돌아가기 |
| 38 | + </Button> |
| 39 | + </div> |
| 40 | + </section> |
| 41 | + </div> |
| 42 | + </main> |
| 43 | + ); |
| 44 | + } |
| 45 | + |
| 46 | + return ( |
| 47 | + <main className="min-h-screen bg-white pb-20"> |
| 48 | + <div className="mx-auto w-full max-w-[1200px] px-4 pt-10"> |
| 49 | + <section className="bg-white pb-12"> |
| 50 | + <div className="grid gap-6 lg:grid-cols-[1fr_590px]"> |
| 51 | + <div className="h-[568px] overflow-hidden rounded-(--radius-l) bg-gray-50"> |
| 52 | + <img src={item.image} alt={item.title} className="h-full w-full object-cover" /> |
| 53 | + </div> |
| 54 | + <div className="flex flex-col gap-4"> |
| 55 | + <div> |
| 56 | + <h1 className="typo-title-2 text-gray-900">{item.title}</h1> |
| 57 | + <p className="mt-2 text-[20px] font-semibold text-gray-900">{item.priceLabel}</p> |
| 58 | + </div> |
| 59 | + |
| 60 | + <div className="border-y border-gray-100 py-4 text-[14px] text-gray-600"> |
| 61 | + <div className="flex flex-col gap-2"> |
| 62 | + <div className="flex gap-4"> |
| 63 | + <span className="w-16 text-gray-500">제조사</span> |
| 64 | + <span className="text-gray-800">{item.specs.manufacturer}</span> |
| 65 | + </div> |
| 66 | + <div className="flex gap-4"> |
| 67 | + <span className="w-16 text-gray-500">모델명</span> |
| 68 | + <span className="text-gray-800">{item.specs.model}</span> |
| 69 | + </div> |
| 70 | + <div className="flex gap-4"> |
| 71 | + <span className="w-16 text-gray-500">색상</span> |
| 72 | + <span className="text-gray-800">{item.specs.color}</span> |
| 73 | + </div> |
| 74 | + <div className="flex gap-4"> |
| 75 | + <span className="w-16 text-gray-500">저장</span> |
| 76 | + <span className="text-gray-800">{item.specs.storage}</span> |
| 77 | + </div> |
| 78 | + <div className="flex gap-4"> |
| 79 | + <span className="w-16 text-gray-500">배터리</span> |
| 80 | + <span className="text-gray-800">{item.specs.battery}</span> |
| 81 | + </div> |
| 82 | + </div> |
| 83 | + <p className="mt-3 text-[12px] text-gray-400">{detailInfo}</p> |
| 84 | + </div> |
| 85 | + |
| 86 | + <div className="text-[14px] text-gray-700"> |
| 87 | + <ul className="space-y-1 text-gray-700"> |
| 88 | + {item.description.map((line) => ( |
| 89 | + <li key={line}>{line}</li> |
| 90 | + ))} |
| 91 | + </ul> |
| 92 | + </div> |
| 93 | + |
| 94 | + <div className="mt-4 flex items-center gap-3"> |
| 95 | + <Button size="full">판매자와 연락하기</Button> |
| 96 | + <FavoriteButton ariaLabel="찜하기" /> |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </div> |
| 100 | + |
| 101 | + <div className="mt-6 flex items-center gap-3"> |
| 102 | + <Profile size="sm" image={item.seller.profileImage} alt={`${item.seller.nickname} 프로필`} /> |
| 103 | + <span className="typo-body-2 text-gray-900">{item.seller.nickname}</span> |
| 104 | + </div> |
| 105 | + |
| 106 | + <section className="mt-[157px]"> |
| 107 | + <h2 className="typo-title-3 text-gray-900">위 제품과 비슷한 상품</h2> |
| 108 | + <div className="mt-6 grid grid-cols-2 gap-6 md:grid-cols-3 lg:grid-cols-4 lg:gap-[22px]"> |
| 109 | + {similarItems.map((entry) => ( |
| 110 | + <Link key={entry.id} to={`${ROUTES.BUY}/${entry.id}`} className="block focus-visible:outline-none"> |
| 111 | + <Card |
| 112 | + image={entry.image} |
| 113 | + title={entry.title} |
| 114 | + price={entry.priceLabel} |
| 115 | + date={entry.dateLabel} |
| 116 | + className="h-[399px] w-[282px]" |
| 117 | + /> |
| 118 | + </Link> |
| 119 | + ))} |
| 120 | + </div> |
| 121 | + </section> |
| 122 | + </section> |
| 123 | + </div> |
| 124 | + </main> |
| 125 | + ); |
| 126 | +} |
0 commit comments