Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: 예약하기 페이지 API 연결 #39

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7e02138
Feat: Discount 폴더 생성과 작업
syb0127 Dec 26, 2023
b17388b
Feat: Discount Item 작업
syb0127 Dec 26, 2023
f3144eb
Feat: DiscountItem 폴더 분리 및 props 설정
syb0127 Dec 26, 2023
4c4b101
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 26, 2023
5304920
Feat: 드롭다운 작업 진행
syb0127 Dec 26, 2023
831720b
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 26, 2023
55c4a33
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 27, 2023
97e1009
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 27, 2023
77954b4
Chore: Discount constant 수정, 구조 재설계
syb0127 Dec 27, 2023
c615f02
Feat: 드롭다운 기능 구현
syb0127 Dec 27, 2023
f1b767f
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 27, 2023
cf27c4f
Style: 드롭다운 스타일 추가
syb0127 Dec 27, 2023
1539c10
Style: 드롭박스 스타일링 완료
syb0127 Dec 27, 2023
3e49b88
Feat: 할인 쿠폰 dummy data 파일 생성
syb0127 Dec 27, 2023
7695845
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 28, 2023
671f0fd
Chore: 불필요한 부분 제거
syb0127 Dec 28, 2023
0d2d98e
Feat: 변수 네이밍 수정 및 쿠폰 리스트 불러오기 작업
syb0127 Dec 28, 2023
359963b
Feat: 쿠폰 리스트 불러오기
syb0127 Dec 29, 2023
7f4867d
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 29, 2023
2f24002
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 29, 2023
9356116
Style: 드롭다운 옵션과 가격 동기화 작업
syb0127 Dec 29, 2023
7974224
Fix: 자잘한 버그 수정
syb0127 Dec 29, 2023
514cf08
Chore: 주석 해제
syb0127 Dec 29, 2023
cb1db9a
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Dec 29, 2023
522c2ac
Style: 쿠폰 적용시 가격 스타일 수정
tkyoun0421 Dec 29, 2023
23416a5
Feat: 쿠폰 드랍 박스 선택 안함 선택시 선택 안함 선택 아이템 삭제
tkyoun0421 Dec 29, 2023
1b2ceac
Feat: 룸 옵션 추가
tkyoun0421 Dec 29, 2023
32a5f22
Chore: 안쓰는 console.log 삭제
tkyoun0421 Dec 29, 2023
5e597cb
Fix: Option 타입 에러 수정
tkyoun0421 Dec 29, 2023
4c0b55f
Feat: 예약하기 API 연결
syb0127 Dec 29, 2023
ddb9ffa
Merge branch 'feature/reservation-publishing' of https://github.com/U…
syb0127 Dec 29, 2023
67e957d
Merge branch 'main' into feature/reservation-API
syb0127 Jan 1, 2024
683afe4
Merge branch 'main' of https://github.com/Upjuyanolja/FastCatch-Front…
syb0127 Jan 2, 2024
959b12f
Feat: 불필요한 파일 제거
syb0127 Jan 2, 2024
dd183c5
Fix: 불필요한 함수 제거
syb0127 Jan 2, 2024
05e2831
Merge branch 'feature/reservation-API' of https://github.com/Upjuyano…
syb0127 Jan 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 0 additions & 25 deletions src/api/getOrderApi.ts

This file was deleted.

3 changes: 1 addition & 2 deletions src/api/postOrderApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,11 @@ export const postOrderApi = async (
}
};

interface PostOrderApiRequestBodyType {
export interface PostOrderApiRequestBodyType {
visitorName: string;
visitorPhone: string;
roomId: number;
startDate: string;
//orderItems?: OrderItemType[];
endDate: string;
couponId: number;
totalPrice: number;
Expand Down
4 changes: 4 additions & 0 deletions src/constant/discount.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const discount = [
{ label: "10% 할인쿠폰 (5,000원 할인)", value: "10_percent" },
{ label: "20,000원 할인쿠폰", value: "20k_coupon" },
];
9 changes: 0 additions & 9 deletions src/mocks/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import accommodationDetailData from "../../public/data/accommodationDetailData.j
import couponData from "../../public/data/couponData.json";
import successLoginData from "../../public/data/successLoginData.json";
import failLoginData from "../../public/data/failLoginData.json";
import reservationList from "../../public/data/reservationList.json";
import cancelReservationList from "../../public/data/cancelReservationList.json";
import successCancelReservation from "../../public/data/successCancelReservation.json";
import successTokenData from "../../public/data/successTokenData.json";
Expand Down Expand Up @@ -49,10 +48,6 @@ const getLoginResolver = async () => {
return HttpResponse.json(successLoginData, { status: 200 });
};

const getReservationListResolver = () => {
return HttpResponse.json(reservationList);
};

const getCancelReservationListResolver = () => {
return HttpResponse.json(cancelReservationList);
};
Expand Down Expand Up @@ -90,10 +85,6 @@ export const handlers = [
),
http.get(`${import.meta.env.VITE_API_BASE_URL}/api/coupons`, getCouponsData),
http.post(`/api/members/signin`, getLoginResolver),
http.get(
`${import.meta.env.VITE_API_BASE_URL}/api/reservations`,
getReservationListResolver
),
http.get(
`${import.meta.env.VITE_API_BASE_URL}/api/reservations/cancel`,
getCancelReservationListResolver
Expand Down
81 changes: 24 additions & 57 deletions src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { memo, useEffect, useState } from "react";
import { useRecoilValue, useSetRecoilState } from "recoil";
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
import { OrderItemTypes, orderState } from "@/states/orderState";
import { PostOrderApiErrorResponse } from "@/api/postOrderApi";
import { postOrderApi } from "@/api/postOrderApi";
import { useNavigate } from "react-router-dom";
import _debounce from "lodash/debounce";

import TermsAgreement from "@/components/termsAgreement/TermsAgreement";

import numberFormat from "@/utils/numberFormat";
import { discountState } from "@/states/discountState";

import { orderErrorMsgState } from "@/states/orderErrorMsgState";
import { couponState } from "@/states/couponState";
import { Button } from "@/components/common";
import {
BookerInformation,
Expand All @@ -33,73 +30,43 @@ const Order = memo(() => {
const [isBookerValidationPass, setIsBookerValidationPass] = useState(false);
const [isAllValidationPass, setIsAllValidationPass] = useState(false);
const orderData: OrderItemTypes[] = useRecoilValue(orderState);
const setOrderErrorMsg = useSetRecoilState(orderErrorMsgState);
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const cartParam = urlParams.get("cart");
const discountAmt = useRecoilValue(discountState);
const [discountAmt, setDiscountAmt] = useRecoilState(discountState);

const totalOrderPrice =
discountAmt !== 0
? discountAmt
: orderData.reduce((total, item) => total + item.price, 0);

const orderDetail = useRecoilValue(orderState);
const orderStartDate = orderDetail.length > 0 ? orderDetail[0].startDate : "";
const orderEndDate = orderDetail.length > 0 ? orderDetail[0].endDate : "";
const orderRoomId = orderDetail.length > 0 ? orderDetail[0].id : 0;
const [selectedCoupon, setSelectedCoupon] = useRecoilState(couponState);

useEffect(() => {
localStorage.setItem("orderState", JSON.stringify(orderData));
}, [orderData]);

const handleClick = () => {
if (cartParam === "true") {
postOrderApiFromCart();
}
if (cartParam === "false") {
postOrderApiFromAccommodation();
}
};

const postOrderApiFromCart = async () => {
const cartItemIds: number[] = orderData
.map(item => {
return item.cartItemId;
})
.filter((cartId): cartId is number => typeof cartId === "number");
const requestBody = {
ageConsent: isAllCheck,
reservationPersonName: userName,
reservationPhoneNumber: userPhoneNumber,
totalPrice: totalOrderPrice,
cartItemIds: cartItemIds,
};
try {
// const res = await postOrderApi("/api/orders/carts", requestBody);
// navigate(`/order/result?result=true&orderid=${res.data.orderId}`);
} catch (error) {
navigate("/order/result?=false");
const postOrderApiError = error as PostOrderApiErrorResponse;
setOrderErrorMsg(postOrderApiError.response.data.errorMessage);
}
postReservationsApiFromAccommodation();
};

const postOrderApiFromAccommodation = async () => {
const postReservationsApiFromAccommodation = async () => {
const requestBody = {
ageConsent: isAllCheck,
reservationPersonName: userName,
reservationPhoneNumber: userPhoneNumber,
totalPrice: totalOrderPrice,
orderItems: orderData.map(item => ({
roomId: item.id,
startDate: item.startDate,
endDate: item.endDate,
headCount: item.defaultCapacity,
orderPrice: item.price,
})),
visitorName: userName,
visitorPhone: userPhoneNumber,
roomId: orderRoomId,
startDate: orderStartDate,
endDate: orderEndDate,
couponId: selectedCoupon ? selectedCoupon.id : -1,
totalPrice: totalPrice,
};
try {
// const res = await postOrderApi("/api/orders", requestBody);
// navigate(`/order/result?result=true&orderid=${res.data.orderId}`);
const res = await postOrderApi("/api/reservations", requestBody);
navigate(`/`);
//navigate(`/order/result?result=true&orderid=${res.data.orderId}`); 결제 완료 메세지는 다른 백엔드, 프론트엔드 팀원들과 상의 후 결정
} catch (error) {
navigate("/order/result?=false");
const postOrderApiError = error as PostOrderApiErrorResponse;
setOrderErrorMsg(postOrderApiError.response.data.errorMessage);
navigate(`/`);
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/pages/order/bookerInformation/BookerInformation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const BookerInformation = ({
useEffect(() => {
if (userState) {
setUserName(userInfo?.name || "");
setUserPhoneNumber(userInfo?.phoneNumber || "");
setUserPhoneNumber(userInfo?.phone || "");
setIsBookerValidationPass(true);
}
}, [userState]);
Expand Down
12 changes: 12 additions & 0 deletions src/states/couponState.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { atom } from "recoil";

type CouponType = {
id: number;
name: string;
price: number;
};

export const couponState = atom<CouponType | null>({
key: "couponState",
default: null,
});
6 changes: 3 additions & 3 deletions src/types/order.ts → src/types/reservation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export interface Order {
export interface Reservation {
orderId: number;
orderStatus: string;
orderDate: string;
Expand All @@ -22,9 +22,9 @@ export interface OrderItem {
orderPrice: number;
}

export interface OrderDataTypes {
export interface ReservationsTypes {
status: string;
pageSize: number;
pageNum: number;
orderResponses: Order[];
orderResponses: Reservation[];
}