|
| 1 | +import { Metadata } from 'next'; |
| 2 | +import Image from 'next/image'; |
| 3 | +import Link from 'next/link'; |
| 4 | +import { getOrderDetail } from '@/app/actions/order'; |
| 5 | +import { CloseButton } from '@/components/ui/close-button'; |
| 6 | +import { notFound } from 'next/navigation'; |
| 7 | + |
| 8 | +export const metadata: Metadata = { |
| 9 | + title: '주문 상세 | OnGil', |
| 10 | + description: '주문 상세 정보입니다.', |
| 11 | +}; |
| 12 | + |
| 13 | +interface OrderPageProps { |
| 14 | + params: Promise<{ orderId: string }>; |
| 15 | +} |
| 16 | + |
| 17 | +export default async function OrderDetailPage({ params }: OrderPageProps) { |
| 18 | + const { orderId } = await params; |
| 19 | + const numericId = Number(orderId); |
| 20 | + if (Number.isNaN(numericId)) { |
| 21 | + notFound(); |
| 22 | + } |
| 23 | + const order = await getOrderDetail(numericId); |
| 24 | + |
| 25 | + const formatDate = (dateString: string) => { |
| 26 | + const date = new Date(dateString); |
| 27 | + return date.toLocaleDateString('ko-KR', { |
| 28 | + year: 'numeric', |
| 29 | + month: 'long', |
| 30 | + day: 'numeric', |
| 31 | + hour: '2-digit', |
| 32 | + minute: '2-digit', |
| 33 | + }); |
| 34 | + }; |
| 35 | + |
| 36 | + const formatPrice = (price: number) => { |
| 37 | + return price.toLocaleString('ko-KR'); |
| 38 | + }; |
| 39 | + |
| 40 | + return ( |
| 41 | + <main className="mx-auto min-h-screen max-w-2xl bg-white"> |
| 42 | + <header className="sticky top-0 z-20 flex h-24 w-full items-center justify-center bg-white"> |
| 43 | + <div className="absolute top-1/2 left-4 ml-3 -translate-y-1/2"> |
| 44 | + <CloseButton /> |
| 45 | + </div> |
| 46 | + <h1 className="text-3xl leading-[18px] font-semibold">주문 상세</h1> |
| 47 | + </header> |
| 48 | + |
| 49 | + <div className="px-6 pb-32"> |
| 50 | + {/* 주문 번호 및 날짜 */} |
| 51 | + <section className="border-b border-gray-200 pb-6"> |
| 52 | + <p className="text-sm text-gray-500">주문번호</p> |
| 53 | + <p className="mt-1 text-lg font-semibold">{order.orderNumber}</p> |
| 54 | + <p className="mt-2 text-sm text-gray-500"> |
| 55 | + {formatDate(order.createdAt)} |
| 56 | + </p> |
| 57 | + </section> |
| 58 | + |
| 59 | + {/* 주문 상품 목록 */} |
| 60 | + <section className="border-b border-gray-200 py-6"> |
| 61 | + <h2 className="mb-4 text-xl font-semibold">주문 상품</h2> |
| 62 | + <ul className="space-y-4"> |
| 63 | + {order.orderItems.map((item, index) => ( |
| 64 | + <li key={index} className="flex gap-4"> |
| 65 | + <Link href={`/product/${item.productId}`}> |
| 66 | + <div className="relative h-24 w-24 overflow-hidden rounded-lg bg-gray-100"> |
| 67 | + <Image |
| 68 | + src={item.imageUrl} |
| 69 | + alt={item.productName} |
| 70 | + fill |
| 71 | + className="object-cover" |
| 72 | + /> |
| 73 | + </div> |
| 74 | + </Link> |
| 75 | + <div className="flex flex-1 flex-col justify-center"> |
| 76 | + <p className="text-sm text-gray-500">{item.brandName}</p> |
| 77 | + <Link |
| 78 | + href={`/product/${item.productId}`} |
| 79 | + className="font-medium hover:underline" |
| 80 | + > |
| 81 | + {item.productName} |
| 82 | + </Link> |
| 83 | + <p className="mt-1 text-sm text-gray-500"> |
| 84 | + {item.selectedColor} / {item.selectedSize} / {item.quantity} |
| 85 | + 개 |
| 86 | + </p> |
| 87 | + <p className="mt-1 font-semibold"> |
| 88 | + {formatPrice(item.priceAtOrder * item.quantity)}원 |
| 89 | + </p> |
| 90 | + </div> |
| 91 | + </li> |
| 92 | + ))} |
| 93 | + </ul> |
| 94 | + </section> |
| 95 | + |
| 96 | + {/* 배송 정보 */} |
| 97 | + <section className="border-b border-gray-200 py-6"> |
| 98 | + <h2 className="mb-4 text-xl font-semibold">배송 정보</h2> |
| 99 | + <dl className="space-y-2 text-sm"> |
| 100 | + <div className="flex"> |
| 101 | + <dt className="w-24 text-gray-500">받는 분</dt> |
| 102 | + <dd>{order.recipient}</dd> |
| 103 | + </div> |
| 104 | + <div className="flex"> |
| 105 | + <dt className="w-24 text-gray-500">연락처</dt> |
| 106 | + <dd>{order.recipientPhone}</dd> |
| 107 | + </div> |
| 108 | + <div className="flex"> |
| 109 | + <dt className="w-24 text-gray-500">배송지</dt> |
| 110 | + <dd>{order.deliveryAddress}</dd> |
| 111 | + </div> |
| 112 | + {order.deliveryMessage && ( |
| 113 | + <div className="flex"> |
| 114 | + <dt className="w-24 text-gray-500">배송 메모</dt> |
| 115 | + <dd>{order.deliveryMessage}</dd> |
| 116 | + </div> |
| 117 | + )} |
| 118 | + </dl> |
| 119 | + </section> |
| 120 | + |
| 121 | + {/* 결제 금액 */} |
| 122 | + <section className="py-6"> |
| 123 | + <h2 className="mb-4 text-xl font-semibold">결제 금액</h2> |
| 124 | + <div className="flex items-center justify-between text-2xl font-bold"> |
| 125 | + <span>총 결제금액</span> |
| 126 | + <span className="text-blue-600"> |
| 127 | + {formatPrice(order.totalAmount)}원 |
| 128 | + </span> |
| 129 | + </div> |
| 130 | + </section> |
| 131 | + </div> |
| 132 | + </main> |
| 133 | + ); |
| 134 | +} |
0 commit comments