From 20abc2753e193a9c3417973827248fa664fd1131 Mon Sep 17 00:00:00 2001 From: jiho0419 <127321491+jiho0419@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:46:04 +0900 Subject: [PATCH 1/3] =?UTF-8?q?=EB=A9=94=EC=9D=B8=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=88=98=EC=A0=95=20=20#1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/containers/Mainpage/Mainpage.tsx | 79 ++----------------- 1 file changed, 8 insertions(+), 71 deletions(-) diff --git a/frontend/src/containers/Mainpage/Mainpage.tsx b/frontend/src/containers/Mainpage/Mainpage.tsx index cb37c23..fffb83f 100644 --- a/frontend/src/containers/Mainpage/Mainpage.tsx +++ b/frontend/src/containers/Mainpage/Mainpage.tsx @@ -1,14 +1,7 @@ -<<<<<<< HEAD -import React, { useState, useEffect } from 'react'; -import styled from 'styled-components'; -import Nav from '../../components/NavBar'; -import axios from 'axios'; -======= import React, { useState, useEffect } from "react"; import styled from "styled-components"; import Nav from "../../components/NavBar"; import axios from "axios"; ->>>>>>> e49d78dfdd2e19aebd690bc66fdb9180308d74e9 const images = [ "https://pimg.hackers.com/land/main/land_default.jpg", @@ -34,34 +27,10 @@ const Mainpage = () => { const onSubmit = async (data: any) => { if (NFC) { return; -<<<<<<< HEAD - - } - - try { - const response = await axios.post("http://isaacnas.duckdns.org:8083/attendance/nfc", { - mac_address: data.address, - nfc_position: data.position, - attendanceTime: new Date().toISOString() // or any appropriate time format - }, { - headers: { - 'Authorization': 'Bearer your-auth-token' // Include your token here - } - }); - console.log('Response:', response.data);//응답처리 - //응답 실패 - } catch (error) { - console.error(error); - } - }; - - - const attendanceStatuses = ['present', 'absent', 'late']; // Updated to 3 statuses -======= } try { - const nfc = await axios.post( + const response = await axios.post( "http://isaacnas.duckdns.org:8083/attendance/nfc", { mac_address: data.address, @@ -74,19 +43,14 @@ const Mainpage = () => { }, } ); + console.log("Response:", response.data); //응답처리 + //응답 실패 } catch (error) { - alert("오류가 발생했습니다"); + console.error(error); } }; - const attendanceStatuses = [ - "present", - "absent", - "late", - "present", - "present", - ]; ->>>>>>> e49d78dfdd2e19aebd690bc66fdb9180308d74e9 + const attendanceStatuses = ["present", "absent", "late"]; // Updated to 3 statuses const getColor = (status: string): string => { switch (status) { @@ -103,17 +67,10 @@ const Mainpage = () => { // Example data for buttons from the backend const buttonsData = [ -<<<<<<< HEAD - { label: 'Menu 1' }, - { label: 'Menu 2' }, - { label: 'Menu 3' }, - { label: 'Menu 4' }, -======= { label: "Menu 1" }, { label: "Menu 2" }, { label: "Menu 3" }, { label: "Menu 4" }, ->>>>>>> e49d78dfdd2e19aebd690bc66fdb9180308d74e9 ]; return ( @@ -133,9 +90,9 @@ const Mainpage = () => { - - 채플현황 - + + 채플현황 + @@ -147,11 +104,6 @@ const Mainpage = () => { {buttonsData.map((button, index) => ( -<<<<<<< HEAD - onSubmit({ address: 'exampleAddress', position: 'examplePosition' }) : undefined}> -======= { : undefined } > ->>>>>>> e49d78dfdd2e19aebd690bc66fdb9180308d74e9 {button.label} ))} @@ -303,23 +254,9 @@ const Box4MainAButton = styled.div` color: black; box-shadow: 0 2px 4px rgba(76, 76, 76, 0), 0 -2px 4px rgba(76, 76, 76, 0.1), 2px 0 4px rgba(76, 76, 76, 0.1), -2px 0 4px rgba(76, 76, 76, 0.1); -<<<<<<< HEAD text-align: center; -======= - //background-color: #f0f0f0; ->>>>>>> e49d78dfdd2e19aebd690bc66fdb9180308d74e9 cursor: pointer; &:hover { background-color: #f0f0f0; } `; -<<<<<<< HEAD - - - - - - - -======= ->>>>>>> e49d78dfdd2e19aebd690bc66fdb9180308d74e9 From 5e687420f5afeb7c94dfa36588f4aca43c5a0b2a Mon Sep 17 00:00:00 2001 From: jiho0419 <127321491+jiho0419@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:46:39 +0900 Subject: [PATCH 2/3] =?UTF-8?q?=EA=B4=80=EB=A6=AC=EC=9E=90=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=93=B1=EB=A1=9D,=20=EC=82=AD=EC=A0=9C,?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=20=EA=B8=B0=EB=8A=A5=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8=20=20=20#24?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/containers/AdminPage/AdminPage.tsx | 177 ++++++++++++------ 1 file changed, 121 insertions(+), 56 deletions(-) diff --git a/frontend/src/containers/AdminPage/AdminPage.tsx b/frontend/src/containers/AdminPage/AdminPage.tsx index b3cc0f8..d390d3c 100644 --- a/frontend/src/containers/AdminPage/AdminPage.tsx +++ b/frontend/src/containers/AdminPage/AdminPage.tsx @@ -1,7 +1,7 @@ import styled from "styled-components"; import React, { useState, useEffect } from "react"; import { UseFormReturn, useForm } from "react-hook-form"; -import { useNavigate } from "react-router-dom"; // useNavigate 훅 임포트 +import { useNavigate } from "react-router-dom"; interface AdminData { checkbox: boolean; @@ -17,6 +17,7 @@ const AdminPage = () => { const [filteredData, setFilteredData] = useState([]); const [showLogoutModal, setShowLogoutModal] = useState(false); const [showRegistrationModal, setShowRegistrationModal] = useState(false); + const [showDeleteModal, setShowDeleteModal] = useState(false); const navigate = useNavigate(); const TestData: AdminData[] = [ @@ -88,26 +89,21 @@ const AdminPage = () => { }; const handleDelete = () => { + setShowDeleteModal(true); + }; + + const handleConfirmDelete = () => { const newData = adminData.filter((item) => !item.checkbox); setAdminData(newData); setFilteredData(newData); + setShowDeleteModal(false); + }; + + const handleCancelDelete = () => { + setShowDeleteModal(false); }; - const { register, handleSubmit, reset } = useForm(); - // const newStudent: AdminData = { - // checkbox: false, - // name: data.name, - // studentid: parseInt(data.studentid), - // studentclass: data.studentclass, - // chapel: parseInt(data.chapel), - // chapelseat: data.chapelseat, - // }; - // const newData = [...adminData, newStudent]; - // setAdminData(newData); - // setFilteredData(newData); - // reset(); // 입력 폼 초기화 - // setShowRegistrationModal(false); // 등록 모달 닫기 - // // + const { register, handleSubmit } = useForm(); const onSubmit = (data: any) => { const searchQuery = data.search.toLowerCase(); @@ -124,6 +120,38 @@ const AdminPage = () => { }); setFilteredData(filtered); }; + const handleRegistration = (data: any) => { + const existingStudent = adminData.some( + (student) => + student.name === data.name || + student.studentid === parseInt(data.studentid) + ); + + if (existingStudent) { + alert("이미 등록된 데이터입니다."); + } else { + const newAdminData = [ + ...adminData, + { + checkbox: false, + name: data.name, + studentid: parseInt(data.studentid), + studentclass: data.studentclass, + chapel: parseInt(data.chapel), + chapelseat: data.chapelseat, + }, + ]; + setAdminData(newAdminData); + setFilteredData(newAdminData); + setShowRegistrationModal(false); + } + }; + + const handleCheckboxChange = (index: number) => { + const newData = [...adminData]; + newData[index].checkbox = !newData[index].checkbox; + setAdminData(newData); + }; return (
@@ -172,11 +200,7 @@ const AdminPage = () => { { - const newData = [...adminData]; - newData[index].checkbox = !newData[index].checkbox; - setAdminData(newData); - }} + onChange={() => handleCheckboxChange(index)} /> {data.name} {data.studentid} @@ -188,6 +212,57 @@ const AdminPage = () => { + + {showRegistrationModal && ( + + + 학생 등록 + + 이름: + + + + 학번: + + + + 학과: + + + + 채플: + + + + 좌석: + + + + + 등록 + + setShowRegistrationModal(false)} + > + 취소 + + + + + )} + + {showDeleteModal && ( + + + 정말로 삭제할까요? + + Yes + No + + + + )} + {showLogoutModal && ( @@ -199,46 +274,27 @@ const AdminPage = () => { )} - {showRegistrationModal && ( - - - 학생 등록 -
- - 이름: - - - - 학번: - - - - 학과: - - - - 채플: - - - - 좌석: - - - - 등록 - setShowRegistrationModal(false)}> - 취소 - - -
-
-
- )}
); }; export default AdminPage; + +const DeleteModal = styled.div` + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + width: 30%; + padding: 20px; + background-color: white; + border: 1px solid #375cde; + border-radius: 10px; + display: flex; + flex-direction: column; + align-items: center; +`; + const RegistrationModal = styled.div` position: fixed; top: 50%; @@ -324,6 +380,15 @@ const ModalButton = styled.button` color: white; cursor: pointer; `; +const ModalButtonCancel = styled.button` + padding: 10px 20px; + margin: 0 10px; + border-radius: 5px; + border: none; + background-color: #375cde; + color: white; + cursor: pointer; +`; const AdminManagementBox = styled.div` display: flex; From 33c2d9c62bebf15d054d7dbbdc6d483124b20b2e Mon Sep 17 00:00:00 2001 From: jiho0419 <127321491+jiho0419@users.noreply.github.com> Date: Thu, 13 Jun 2024 10:51:45 +0900 Subject: [PATCH 3/3] =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8=20=ED=8E=98?= =?UTF-8?q?=EC=9D=B4=EC=A7=80=20=EB=B2=84=ED=8A=BC=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20api=20=EC=97=B0=EB=8F=99=20=20#12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/containers/LoginPage/LoginPage.tsx | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/frontend/src/containers/LoginPage/LoginPage.tsx b/frontend/src/containers/LoginPage/LoginPage.tsx index cf46aab..1750695 100644 --- a/frontend/src/containers/LoginPage/LoginPage.tsx +++ b/frontend/src/containers/LoginPage/LoginPage.tsx @@ -6,7 +6,7 @@ import { useState } from "react"; import axios from "axios"; const LoginPage = () => { - const [error, setError] = useState(""); + // const [error, setError] = useState(""); const signup = useNavigate(); // useNavigate 훅 사용 const { register, @@ -24,17 +24,41 @@ const LoginPage = () => { if (data.studentId === "admin" && data.password === "admin") { signup("/admin"); - } else { - try { - const response = await axios.post( - "http://isaacnas.duckdns.org:8083/user/login", - loginData - ); - if (response.status === 200) { - signup("/main"); + // if (data.studentId === "admin") { + // signup("/admin"); + } + try { + const response = await axios.post( + "http://isaacnas.duckdns.org:8083/user/login", + loginData, + { + headers: { + "Content-Type": "application/json", + }, } - } catch (error) { - setError("로그인에 실패했습니다. 다시 시도해주세요."); + ); + + console.log("서버 응답:", response); // 디버깅을 위해 콘솔에 출력 + + if (response.status === 200 || response.data.success) { + alert("로그인 되었습니다!"); + signup("/main"); + } else { + alert("로그인에 실패했습니다. 다시 시도해주세요."); + } + } catch (error: any) { + if (error.response) { + // 요청이 이루어졌고 서버가 2xx 범위 외의 상태 코드로 응답함 + console.error("Error response:", error.response.data); + alert(`로그인에 실패했습니다: ${error.response.data.message}`); + } else if (error.request) { + // 요청이 이루어졌지만 응답을 받지 못함 + console.error("Error request:", error.request); + alert("로그인 서버로부터 응답이 없습니다. 나중에 다시 시도해주세요."); + } else { + // 요청 설정 중 오류가 발생함 + console.error("Error message:", error.message); + alert("로그인 중 오류가 발생했습니다. 다시 시도해주세요."); } } }; @@ -78,7 +102,8 @@ const LoginPage = () => { value === "admin" || value === watch("studentId") || /^(?=.*[a-zA-Z])(?=.*[0-9]).{8,}$/.test(value) || - "영문+숫자 조합 8자 이상 입력해주세요.", + "비밀번호를 제대로 입력해주세요.", + // "영문+숫자 조합 8자 이상 입력해주세요.", })} /> {errors.password && ( @@ -153,6 +178,11 @@ const LoginBtn = styled.div` width: 100vw; min-width: 200px; max-width: 580px; + position: fixed; + bottom: 3%; + left: 50%; + transform: translateX(-50%); + z-index: 1; `; const SubmitButton = styled.button`