From 72be9b52417f6fd80aca5b839349b26cf25ac4fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=20=EC=B0=AC?= Date: Tue, 17 Dec 2024 01:24:12 +0900 Subject: [PATCH 1/2] =?UTF-8?q?feat=20:=20api=EC=97=B0=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/package-lock.json | 1 + user/src/apis/club.js | 2 +- user/src/pages/SeeAllPage.jsx | 67 +++++++++++++++++++++++++++------- user/src/pages/siwootest.jsx | 30 +++++++++++++++ user/{ => src}/utils/cookie.js | 0 5 files changed, 85 insertions(+), 15 deletions(-) create mode 100644 user/src/pages/siwootest.jsx rename user/{ => src}/utils/cookie.js (100%) diff --git a/user/package-lock.json b/user/package-lock.json index f586bdb..57bf2ce 100644 --- a/user/package-lock.json +++ b/user/package-lock.json @@ -1526,6 +1526,7 @@ "version": "1.7.9", "resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz", "integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==", + "license": "MIT", "dependencies": { "follow-redirects": "^1.15.6", "form-data": "^4.0.0", diff --git a/user/src/apis/club.js b/user/src/apis/club.js index 700aed3..1f0cb66 100644 --- a/user/src/apis/club.js +++ b/user/src/apis/club.js @@ -10,4 +10,4 @@ export const getClub = async () => { export const getClubDetail = async (clubname) => { const response = await instance.get(`${router}/info/${clubname}`); return response.data; -}; +}; \ No newline at end of file diff --git a/user/src/pages/SeeAllPage.jsx b/user/src/pages/SeeAllPage.jsx index 45b3bdd..7ca2a15 100644 --- a/user/src/pages/SeeAllPage.jsx +++ b/user/src/pages/SeeAllPage.jsx @@ -1,11 +1,42 @@ -import React from "react"; +import React, { useEffect, useState } from "react"; import styled from "styled-components"; import { Header } from "../components/Header"; import { CollectBtn } from "../components/SeeallPage/CollectBtn"; import { Pagefooter } from "../components/PageFooter"; +import { getClub } from "../apis/club"; // API 호출 함수 가져오기 import searchBtn from "../assets/searchBtn.svg"; export const SeeAll = () => { + const [clubs, setClubs] = useState([]); // 동아리 데이터를 저장할 상태 + const [loading, setLoading] = useState(true); // 로딩 상태 관리 + + // 데이터를 가져오는 함수 + const fetchClubs = async ({ clubName , clubBanner , title , setData }) => { + try { + const data = await instance.post('../apis/club.js', { + clubName, + title, + clubBanner + }); // API 호출 + setClubs(data); // 데이터를 상태에 저장 + + setData({ + clubName: '', + title: '', + clubBanner: '', + }); + + } catch (error) { + console.error("동아리 데이터를 가져오는 데 실패했습니다...", error); + } finally { + setLoading(false); // 로딩 상태 종료 + } + }; + + useEffect(() => { + fetchClubs(); // 컴포넌트가 렌더링될 때 API 호출 + }, []); + return (
@@ -18,25 +49,33 @@ export const SeeAll = () => { - - {Array.from({ length: 8 }).map((_, index) => ( - - - - - -

대동여지도

-

대동여지도와 실록 서비스를 개발 및 운영 중인 동아리

-
-
- ))} -
+ {loading ? ( // 로딩 중일 때 표시 + 로딩 중... + ) : ( + + {clubs.map((club) => ( + + + + + +

{club.name}

+

{club.description}

+
+
+ ))} +
+ )} ); }; +const LoadingMessage = styled.div` + +`; + const Container = styled.div` margin: 0; padding: 0; diff --git a/user/src/pages/siwootest.jsx b/user/src/pages/siwootest.jsx new file mode 100644 index 0000000..85adf99 --- /dev/null +++ b/user/src/pages/siwootest.jsx @@ -0,0 +1,30 @@ +import { instance } from './instance'; + +export const apiSignUp = async ({ email, password, setModal, setInputs }) => { + try { + const response = await instance.post('/auth/signup', { + email, + password, + }); + + if (response.status === 200) { + console.log('회원가입 성공'); + + setInputs({ + email: '', + code: '', + password1: '', + password2: '', + }); + setModal(true); + } + } catch (error) { + if (error.response) { + if (error.response.status === 400) { + alert('비밀번호는 최대 64글자이고, 특수문자 한개가 포함되어야 합니다.'); + } else if (error.response.status === 409) { + alert('이미 가입된 유저입니다.'); + } + } + } +}; \ No newline at end of file diff --git a/user/utils/cookie.js b/user/src/utils/cookie.js similarity index 100% rename from user/utils/cookie.js rename to user/src/utils/cookie.js From 9bfb94766833e972e6aabccecf7c2f8cbc13c13d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=20=EC=B0=AC?= Date: Tue, 17 Dec 2024 12:29:21 +0900 Subject: [PATCH 2/2] =?UTF-8?q?fix=20:=20=EC=BD=94=EB=A9=98=ED=8A=B8?= =?UTF-8?q?=EC=9A=94=EA=B5=AC=EC=82=AC=ED=95=AD=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- user/src/pages/SeeAllPage.jsx | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/user/src/pages/SeeAllPage.jsx b/user/src/pages/SeeAllPage.jsx index 7ca2a15..511ecd2 100644 --- a/user/src/pages/SeeAllPage.jsx +++ b/user/src/pages/SeeAllPage.jsx @@ -10,31 +10,8 @@ export const SeeAll = () => { const [clubs, setClubs] = useState([]); // 동아리 데이터를 저장할 상태 const [loading, setLoading] = useState(true); // 로딩 상태 관리 - // 데이터를 가져오는 함수 - const fetchClubs = async ({ clubName , clubBanner , title , setData }) => { - try { - const data = await instance.post('../apis/club.js', { - clubName, - title, - clubBanner - }); // API 호출 - setClubs(data); // 데이터를 상태에 저장 - - setData({ - clubName: '', - title: '', - clubBanner: '', - }); - - } catch (error) { - console.error("동아리 데이터를 가져오는 데 실패했습니다...", error); - } finally { - setLoading(false); // 로딩 상태 종료 - } - }; - useEffect(() => { - fetchClubs(); // 컴포넌트가 렌더링될 때 API 호출 + getClub(); // 컴포넌트가 렌더링될 때 API 호출 }, []); return (