From 14ab2890c3c5220bca8ca255078f696f94b24863 Mon Sep 17 00:00:00 2001 From: DingX2 <96682768+DingX2@users.noreply.github.com> Date: Wed, 16 Aug 2023 18:44:39 +0900 Subject: [PATCH] =?UTF-8?q?[FIX]=20API=20=EA=B4=80=EB=A6=AC=EB=B2=95=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 수정사항 발견 - 관리자 생성페이지 input 같이 움직임 - 호출되면서 빈 배열이 다시 들어감 - src/apis를 만들어 관리하기로 함 - 중복되는 api 문제를 모듈화해서 해결하기로 함 --- src/apis/axiosBookingApi.jsx | 43 +++++++++++++++++++++ src/components/LoginComponent.jsx | 22 +---------- src/components/ReservationDetails.jsx | 46 +++++++++++----------- src/components/ReservationLists.jsx | 55 ++++++++++++++++++++++++++- src/pages/ApiTest.jsx | 17 +-------- src/styles/ReservationDetails.scss | 1 + 6 files changed, 124 insertions(+), 60 deletions(-) create mode 100644 src/apis/axiosBookingApi.jsx diff --git a/src/apis/axiosBookingApi.jsx b/src/apis/axiosBookingApi.jsx new file mode 100644 index 0000000..31390ab --- /dev/null +++ b/src/apis/axiosBookingApi.jsx @@ -0,0 +1,43 @@ +import React, { useEffect, useState } from "react"; +import axios from "axios"; + +const URL = "booking/"; + +const JsonBookingResource = (() => { + // const [bookingData, setBookingData] = useState([]); + // const [bookingDataAry, setBookingDataAry] = useState([]); + // const [loading, setLoading] = useState(false); + + const instance = axios.create({ + baseURL: "/booking", + withCredentials: true, + }); + + // useEffect(() => { + // fetchBooking(); + // }, []); + + const fetchBooking = async () => { + return (await instance.get("/booking")).data; + // try { + // // setBookingData(bookingData); + // // setBookingDataAry(bookingData.content); + + // console.log(bookingData); + // // console.log(bookingDataAry); + // } catch (error) { + // console.error(error); + // } + }; + + const fetchBookingAry = async () => { + return (await instance.get("/booking")).data.content; + }; + + return { + booking: fetchBooking, + bookingAry: fetchBookingAry, + }; +})(); + +export default JsonBookingResource; diff --git a/src/components/LoginComponent.jsx b/src/components/LoginComponent.jsx index 5459b1b..714acd0 100644 --- a/src/components/LoginComponent.jsx +++ b/src/components/LoginComponent.jsx @@ -1,5 +1,4 @@ import React, { useNavigate, useEffect, axios } from "react"; -import { getCookie } from "./cookieUtils"; // Import the getCookie function import "../styles/fonts.scss"; import "../styles/LoginComponent.scss"; @@ -7,26 +6,11 @@ import "../styles/LoginComponent.scss"; export default function LoginComponents() { const imgSrcKakao = "/img/kakaobtn-img.png"; const REST_API_KEY = "b5d91872e5fa2c8c0a684e8f5c696e16"; - // const REDIRECT_URI = "http://localhost:3000/kakaoLogin"; const REDIRECT_URI = "http://localhost:8080/kakao"; - // const link = `https://kauth.kakao.com/oauth/authorize?client_id=${REST_API_KEY}&redirect_uri=${REDIRECT_URI}&response_type=code`; const link = REDIRECT_URI; // const code = window.location.search; // code?=이상한코드가한가득 - const code = "b5d91872e5fa2c8c0a684e8f5c696e16"; - // const navigate = useNavigate(); - - // useEffect(() => { - // console.log(process.env.REACT_APP_URL); - // axios.post(`${process.env.REACT_APP_URL}kakaoLogin${code}`).then((r) => { - // console.log(r.data); - - // // 토큰을 받아서 localStorage같은 곳에 저장하는 코드를 여기에 쓴다. - // // localStorage.setItem("name", r.data.user_name); // 일단 이름만 저장했다. - - // // navigate("/loginSuccess"); - // }); - // }, []); + // const code = "b5d91872e5fa2c8c0a684e8f5c696e16"; const loginHandler = () => { window.location.href = link; @@ -56,10 +40,6 @@ export default function LoginComponents() { 카카오 계정으로 1초 로그인 - - ); } diff --git a/src/components/ReservationDetails.jsx b/src/components/ReservationDetails.jsx index 41c9539..f8f74a6 100644 --- a/src/components/ReservationDetails.jsx +++ b/src/components/ReservationDetails.jsx @@ -3,34 +3,38 @@ import axios from "axios"; import "../styles/ReservationDetails.scss"; import PassDetailContainer from "./PassDetailContainer"; +import JsonBookingResource from "../apis/axiosBookingApi"; export default function ReservationDetails() { const URL = "booking/"; + const bookingCheck = JsonBookingResource.booking; + const [bookingData, setBookingData] = useState([]); const [bookingDataAry, setBookingDataAry] = useState([]); const [loading, setLoading] = useState(false); const [pass, setPass] = useState([]); + const [passtypeText, setPasstypeText] = useState([]); - async function fetchDataPass() { - console.log("Fetching data..."); - try { - const response = await axios.get("/pass?page=1&size=4&sort=startedDay", { - withCredentials: true, - }); + // async function fetchDataPass() { + // console.log("Fetching data..."); + // try { + // const response = await axios.get("/pass?page=1&size=4&sort=startedDay", { + // withCredentials: true, + // }); - if (!response.data) { - throw new Error("Failed to fetch data from the server"); - } - setPass((predata) => response.data); - console.log("pass check"); - console.log(pass); - setLoading((preloading) => true); - } catch (error) { - console.error(error); - } /// - } + // if (!response.data) { + // throw new Error("Failed to fetch data from the server"); + // } + // setPass((predata) => response.data); + // console.log("pass check"); + // console.log(pass); + // setLoading((preloading) => true); + // } catch (error) { + // console.error(error); + // } /// + // } async function fetchData() { console.log("Fetching data..."); @@ -55,13 +59,11 @@ export default function ReservationDetails() { useEffect(() => { fetchData(); - // fetchDataCheck(); - fetchDataPass(); - console.log(bookingData); + // fetchDataPass(); + // console.log(bookingData); }, [loading]); const text = "생성"; - const passtypeText = "예약 등록 - 필라테스 이용권1"; const date = "2023-06-09"; const time = "13:00~14:00"; const trainer = "오영선"; @@ -70,7 +72,7 @@ export default function ReservationDetails() {