Skip to content

Commit

Permalink
feat: 포인트 기능 - 포인트로 결제 시 10% 할인되는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
userjmmm authored and userjmmm committed Aug 4, 2024
1 parent a876457 commit 4a41411
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 7 additions & 5 deletions src/components/features/Order/OrderForm/OrderInfo/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ export const OrderFormOrderInfo = ({ orderHistory }: Props) => {
return total + (selectedOption ? detail.price * order.quantity : 0);
}, 0);

const discountedPrice = Math.round(totalPrice * 0.9);

return (
<Wrapper>
<Title>
Expand All @@ -54,16 +56,16 @@ export const OrderFormOrderInfo = ({ orderHistory }: Props) => {
);
})}
<ItemWrapper>
<LabelText>메시지</LabelText>
<HeadingText>{orderHistory[0].message}</HeadingText>
<LabelText>총 결제금액</LabelText>
<HeadingText>{totalPrice}</HeadingText>
</ItemWrapper>
<ItemWrapper>
<LabelText>최종 결제금액</LabelText>
<HeadingText>{totalPrice}</HeadingText>
<LabelText>포인트 결제 금액</LabelText>
<HeadingText>{discountedPrice}</HeadingText>
</ItemWrapper>
<Divider color="#ededed" />
<Spacing height={32} />
<Button type="submit">{totalPrice}원 결제하기</Button>
<Button type="submit">{discountedPrice}원 결제하기</Button>
</Wrapper>
);
};
Expand Down
16 changes: 11 additions & 5 deletions src/components/features/Order/OrderForm/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,19 @@ export const OrderForm = ({ orderHistory }: Props) => {
credentials: 'include',
})
.then(async response => {
const status = response.status;
if (!response.ok) {
const errorBody = await response.text();
console.error(`옵션 ID ${order.optionId} 주문 실패:`, response.status, errorBody);
return { success: false, optionId: order.optionId, error: errorBody };
console.error(`옵션 ID ${order.optionId} 주문 실패:`, status, errorBody);
return { success: false, optionId: order.optionId, status, error: errorBody };
}
const data = await response.json();
console.log(`옵션 ID ${order.optionId} 주문 성공:`, data);
return { success: true, optionId: order.optionId, data };
return { success: true, optionId: order.optionId, status, data };
})
.catch(error => {
console.error(`옵션 ID ${order.optionId} 주문 에러:`, error);
return { success: false, optionId: order.optionId, error: error.message };
return { success: false, optionId: order.optionId, status: 500, error: error.message };
});
});

Expand All @@ -86,7 +87,12 @@ export const OrderForm = ({ orderHistory }: Props) => {

if (failedOrders.length > 0) {
console.error('실패한 주문:', failedOrders);
alert(`${failedOrders.length}개의 주문 중 오류가 발생했습니다.`);
const insufficientPoints = failedOrders.some(order => order.status === 400);
if (insufficientPoints) {
alert('포인트가 부족합니다.');
} else {
alert(`${failedOrders.length}개의 주문 중 오류가 발생했습니다.`);
}
}
} catch (error) {
console.error('주문 처리 중 예외 발생:', error);
Expand Down

0 comments on commit 4a41411

Please sign in to comment.