([]);
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 && (
-
-
- 학생 등록
-
-
-
- )}
);
};
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`