Skip to content

Commit 94f02a7

Browse files
committed
fix: 코드래빗 반영
1 parent c95be73 commit 94f02a7

File tree

8 files changed

+38
-32
lines changed

8 files changed

+38
-32
lines changed

src/app/actions/order.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,10 @@ export async function fetchDirectOrderItems(
9595

9696
let selections: { color: string; size: string; quantity: number }[];
9797
try {
98-
selections = JSON.parse((params.selections as string) || '[]');
98+
const raw = Array.isArray(params.selections)
99+
? params.selections[0]
100+
: params.selections;
101+
selections = JSON.parse(raw || '[]');
99102
} catch {
100103
notFound();
101104
}

src/app/payment/_components/order-items.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ export default function OrderItemsSection({ items }: Props) {
6464
))}
6565
</ul>
6666
{hasDiscount && (
67-
<p className="text-red text-center text-xl leading-normal font-medium">
67+
<p className="text-center text-xl leading-normal font-medium text-red-500">
6868
최대 할인이 적용 됐어요
6969
</p>
7070
)}

src/app/payment/_components/payment-context.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,20 @@ export function PaymentProvider({
7474
const [usedPoints, setUsedPoints] = useState(0);
7575

7676
const totalItemPrice = items.reduce((acc, item) => acc + item.totalPrice, 0);
77-
const finalPrice = totalItemPrice - usedPoints;
77+
const finalPrice = Math.max(0, totalItemPrice - usedPoints);
7878

7979
/**
8080
* 결제 처리 함수
8181
* - 배송지 정보 유효성 검증 후 주문 생성
8282
*/
8383
const handlePayment = async () => {
8484
if (isSubmitting) return;
85-
86-
if (!shippingInfo.deliveryAddress || !shippingInfo.postalCode) {
85+
if (
86+
!shippingInfo.recipient.trim() ||
87+
!shippingInfo.recipientPhone.trim() ||
88+
!shippingInfo.deliveryAddress ||
89+
!shippingInfo.postalCode
90+
) {
8791
alert('배송지 정보를 모두 입력해주세요.');
8892
scrollToId(SECTIONS.SHIPPING);
8993
return;
@@ -95,7 +99,9 @@ export function PaymentProvider({
9599

96100
if (orderType === 'cart') {
97101
orderId = await createOrderFromCart({
98-
cartItemIds: items.map((item) => item.cartItemId!),
102+
cartItemIds: items
103+
.map((item) => item.cartItemId)
104+
.filter((id): id is number => id != null),
99105
usedPoints,
100106
...shippingInfo,
101107
});

src/app/payment/_components/payment-info.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,12 @@ export default function PaymentInfoSection({
3131
<div className="mb-6">
3232
<div className="flex justify-around">
3333
<Input
34-
value={usedPoints}
34+
value={usedPoints || ''}
3535
onChange={handlePointChange}
3636
className="h-[87px] w-[239px] rounded-lg border border-black text-left text-3xl leading-normal font-medium placeholder:text-black"
3737
placeholder="0원"
38+
aria-label="적립금 사용 금액"
39+
inputMode="numeric"
3840
/>
3941
<button
4042
onClick={() => onPointsChange(Math.min(userPoints, totalPrice))}

src/app/payment/_components/step-navigator.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ export default function StepNavigator({ activeStep, onStepChange }: Props) {
5050
return (
5151
<div
5252
key={step.id}
53-
className="bg- relative z-10 flex flex-col items-center"
53+
className="relative z-10 flex flex-col items-center"
5454
>
5555
<button
5656
type="button"
@@ -86,7 +86,7 @@ export default function StepNavigator({ activeStep, onStepChange }: Props) {
8686
</header>
8787

8888
{/* 헤더 높이만큼 공간 확보 */}
89-
<div className="h-52 w-full" aria-hidden="true" />
89+
<div className="h-[220px] w-full" aria-hidden="true" />
9090
</>
9191
);
9292
}

src/app/payment/_components/use-payment-scroll-spy.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,19 @@ export default function usePaymentScrollSpy(ids: string[]) {
1414
const timeoutRef = useRef<ReturnType<typeof setTimeout> | null>(null);
1515

1616
const scrollToId = (id: string) => {
17-
isClickScrolling.current = true;
18-
1917
startTransition(() => {
2018
setActiveId(id);
2119
});
22-
2320
const element = document.getElementById(id);
24-
if (element) {
25-
const top =
26-
element.getBoundingClientRect().top + window.scrollY - HEADER_HEIGHT;
27-
window.scrollTo({ top, behavior: 'smooth' });
28-
29-
if (timeoutRef.current) clearTimeout(timeoutRef.current);
30-
timeoutRef.current = setTimeout(() => {
31-
isClickScrolling.current = false;
32-
}, 1000);
33-
}
21+
if (!element) return;
22+
isClickScrolling.current = true;
23+
const top =
24+
element.getBoundingClientRect().top + window.scrollY - HEADER_HEIGHT;
25+
window.scrollTo({ top, behavior: 'smooth' });
26+
if (timeoutRef.current) clearTimeout(timeoutRef.current);
27+
timeoutRef.current = setTimeout(() => {
28+
isClickScrolling.current = false;
29+
}, 1000);
3430
};
3531

3632
useEffect(() => {

src/app/payment/complete/page.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { notFound } from 'next/navigation';
33
import type { Metadata } from 'next';
44
import { getOrderDetail } from '@/app/actions/order';
55
import Image from 'next/image';
6+
import { auth } from '/auth';
7+
import { redirect } from 'next/navigation';
68

79
export const metadata: Metadata = {
810
title: '주문 완료 - 온길',
@@ -13,12 +15,12 @@ interface PageProps {
1315
}
1416

1517
export default async function OrderCompletePage({ searchParams }: PageProps) {
18+
const session = await auth();
19+
if (!session) redirect('/login');
1620
const { orderId } = await searchParams;
17-
1821
if (!orderId || isNaN(Number(orderId))) {
1922
notFound();
2023
}
21-
2224
const order = await getOrderDetail(Number(orderId));
2325

2426
return (
@@ -36,7 +38,7 @@ export default async function OrderCompletePage({ searchParams }: PageProps) {
3638
주문번호: <span className="">{order.orderNumber}</span>
3739
</p>
3840

39-
<div className="mt-5 grid max-w-sm grid-cols-2 gap-3 text-xl font-medium text-white">
41+
<div className="mx-auto mt-5 grid max-w-sm grid-cols-2 gap-3 text-xl font-medium text-white">
4042
<Link
4143
href={`/orders/${order.id}`}
4244
className="bg-ongil-teal flex items-center justify-center rounded-md px-6 py-2"
@@ -87,7 +89,7 @@ export default async function OrderCompletePage({ searchParams }: PageProps) {
8789
<div className="mt-4 flex items-center justify-between pt-3 text-lg font-bold">
8890
<span>총 결제금액</span>
8991
<span className="text-xl text-blue-600">
90-
{order.totalAmount.toLocaleString()}
92+
{(order.totalAmount ?? 0).toLocaleString()}
9193
</span>
9294
</div>
9395
</div>

src/app/payment/page.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default async function PaymentPage({ searchParams }: PageProps) {
3737
]);
3838

3939
return (
40-
<main className="max-h-screen">
40+
<main className="min-h-screen">
4141
<PaymentProvider
4242
user={user}
4343
items={items}
@@ -46,14 +46,11 @@ export default async function PaymentPage({ searchParams }: PageProps) {
4646
<ConnectedStepNavigator />
4747

4848
<div className="mx-auto mt-4 max-w-xl space-y-8 pb-32">
49-
<section id={SECTIONS.ITEMS} className="min-h-auto scroll-mt-[120px]">
49+
<section id={SECTIONS.ITEMS} className="scroll-mt-[120px]">
5050
<OrderItemsSection items={items} />
5151
</section>
5252

53-
<section
54-
id={SECTIONS.SHIPPING}
55-
className="min-h-auto scroll-mt-[120px]"
56-
>
53+
<section id={SECTIONS.SHIPPING} className="scroll-mt-[120px]">
5754
<ConnectedShippingSection />
5855
</section>
5956

0 commit comments

Comments
 (0)