diff --git a/src/components/features/Order/OrderForm/OrderInfo/index.tsx b/src/components/features/Order/OrderForm/OrderInfo/index.tsx index a7c92c490..c4cad9f6d 100644 --- a/src/components/features/Order/OrderForm/OrderInfo/index.tsx +++ b/src/components/features/Order/OrderForm/OrderInfo/index.tsx @@ -32,7 +32,7 @@ export const OrderFormOrderInfo = ({ orderHistory }: Props) => { return total + (selectedOption ? detail.price * order.quantity : 0); }, 0); - const discountedPrice = Math.round(totalPrice * 0.9); + const discountedPrice = Math.round(totalPrice * 0.95); return ( diff --git a/src/components/features/Order/OrderForm/index.tsx b/src/components/features/Order/OrderForm/index.tsx index f11872092..b9bddf6d1 100644 --- a/src/components/features/Order/OrderForm/index.tsx +++ b/src/components/features/Order/OrderForm/index.tsx @@ -40,7 +40,8 @@ export const OrderForm = ({ orderHistory }: Props) => { const orders = orderHistorySessionStorage.get() as OrderHistory[]; - const requests = orders.map(order => { + const results = []; + for (const order of orders) { const requestBody = { optionId: order.optionId, quantity: order.quantity, @@ -49,54 +50,43 @@ export const OrderForm = ({ orderHistory }: Props) => { console.log('서버로 전송하는 요청 데이터:', JSON.stringify(requestBody, null, 2)); - return fetch(`${getBaseUrl()}/api/orders`, { - method: 'POST', - headers: { - Authorization: `Bearer ${authInfo?.token}`, - 'Content-Type': 'application/json', - }, - body: JSON.stringify(requestBody), - credentials: 'include', - }) - .then(async response => { - const status = response.status; + try { + const response = await fetch(`${getBaseUrl()}/api/orders`, { + method: 'POST', + headers: { + Authorization: `Bearer ${authInfo?.token}`, + 'Content-Type': 'application/json', + }, + body: JSON.stringify(requestBody), + credentials: 'include', + }); + if (!response.ok) { const errorBody = await response.text(); - console.error(`옵션 ID ${order.optionId} 주문 실패:`, status, errorBody); - return { success: false, optionId: order.optionId, status, error: errorBody }; + console.error(`옵션 ID ${order.optionId} 주문 실패:`, response.status, errorBody); + results.push({ success: false, optionId: order.optionId, error: errorBody }); + } else { + const data = await response.json(); + console.log(`옵션 ID ${order.optionId} 주문 성공:`, data); + results.push({ success: true, optionId: order.optionId, data }); } - const data = await response.json(); - console.log(`옵션 ID ${order.optionId} 주문 성공:`, data); - return { success: true, optionId: order.optionId, status, data }; - }) - .catch(error => { + } catch (error) { console.error(`옵션 ID ${order.optionId} 주문 에러:`, error); - return { success: false, optionId: order.optionId, status: 500, error: error.message }; - }); - }); - - try { - const results = await Promise.all(requests); - const successfulOrders = results.filter(result => result.success); - const failedOrders = results.filter(result => !result.success); - - if (successfulOrders.length > 0) { - console.log('성공한 주문:', successfulOrders); - alert(`${successfulOrders.length}개의 주문이 완료되었습니다.`); + results.push({ success: false, optionId: order.optionId, error: error}); } + } - if (failedOrders.length > 0) { - console.error('실패한 주문:', failedOrders); - const insufficientPoints = failedOrders.some(order => order.status === 400); - if (insufficientPoints) { - alert('포인트가 부족합니다.'); - } else { - alert(`${failedOrders.length}개의 주문 중 오류가 발생했습니다.`); - } - } - } catch (error) { - console.error('주문 처리 중 예외 발생:', error); - alert('주문 처리 중 예기치 않은 오류가 발생했습니다.'); + const successfulOrders = results.filter(result => result.success); + const failedOrders = results.filter(result => !result.success); + + if (successfulOrders.length > 0) { + console.log('성공한 주문:', successfulOrders); + alert(`${successfulOrders.length}개의 주문이 완료되었습니다.`); + } + + if (failedOrders.length > 0) { + console.error('실패한 주문:', failedOrders); + alert(`${failedOrders.length}개의 주문 중 오류가 발생했습니다.`); } };