김건희

[Add] LoginPage View

1 import './App.css'; 1 import './App.css';
2 import RegisterPage from './component/views/RegisterPage/RegisterPage'; 2 import RegisterPage from './component/views/RegisterPage/RegisterPage';
3 +import LoginPage from './component/views/LoginPage/LoginPage';
3 4
4 function App() { 5 function App() {
5 return ( 6 return (
6 <div> 7 <div>
7 - <RegisterPage /> 8 + <LoginPage />
8 </div> 9 </div>
9 ); 10 );
10 } 11 }
......
1 +import React, { useCallback, useState } from "react";
2 +import "../style/LoginPage.scss"
3 +
4 +function LoginPage(props) {
5 +
6 + const [Id, setId] = useState("");
7 + const [Password, setPassword] = useState("");
8 +
9 + const [checkIdError, setCheckIdError] = useState(false);
10 + const [checkPasswordError, setCheckPasswordError] = useState(false);
11 + const [checkLoginError, setCheckLoginError] = useState(false);
12 +
13 + const idRegex = /^(?=.*[a-zA-Z])(?=.*[0-9]).{6,14}$/;
14 + const passwordRegex = /^(?=.*[a-zA-Z])(?=.*[!@#$%^*+=-?])(?=.*[0-9]).{8,25}$/;
15 +
16 + const onIdHandler = useCallback((event) => {
17 + setId(event.currentTarget.value);
18 +
19 + // 아이디 유효성 검사
20 + if (!idRegex.test(event.currentTarget.value)) {
21 + setCheckIdError(true);
22 + }
23 + else {
24 + setCheckIdError(false);
25 + }
26 +
27 + }, [checkIdError]);
28 +
29 + const onPasswordHandler = useCallback((event) => {
30 + setPassword(event.currentTarget.value);
31 +
32 + // 비밀번호 유효성 검사
33 + if (!passwordRegex.test(event.currentTarget.value)) {
34 + setCheckPasswordError(true);
35 + }
36 + else {
37 + setCheckPasswordError(false);
38 + }
39 + }, [checkPasswordError]);
40 +
41 + const onSubmitHandler = useCallback((event) => {
42 + event.preventDefault();
43 +
44 + if (checkIdError || Id === "") {
45 + setCheckLoginError(true);
46 + }
47 + else if (checkPasswordError || Password === "") {
48 + setCheckLoginError(true);
49 + }
50 + else {
51 + setCheckLoginError(false);
52 + }
53 +
54 + if (!checkLoginError) {
55 + const UserData = {
56 + id: Id,
57 + password: Password,
58 + };
59 + }
60 +
61 + }, [checkIdError, checkPasswordError, Password]);
62 +
63 + return (
64 + <div id = "body">
65 + <div className="login-box">
66 + <h2>로그인</h2>
67 + <div className="input-area">
68 + <input
69 + placeholder="아이디"
70 + type="text"
71 + value={Id}
72 + onChange={onIdHandler}
73 + />
74 + </div>
75 + <div className="check-variable">
76 + {checkIdError && <div style={{color : 'red'}}>아이디는 6자리 이상 14자리 이하 소문자와 숫자로 입력해주세요.</div>}
77 + </div>
78 + <div className="input-area">
79 + <input
80 + placeholder="비밀번호"
81 + type="text"
82 + value={Password}
83 + onChange={onPasswordHandler}
84 + />
85 + </div>
86 + <div className="check-variable">
87 + {checkPasswordError && <div style={{color : 'red'}}>알파벳과 숫자, 특수문자를 포함하여 8자리 이상 입력해주세요.</div>}
88 + </div>
89 + <div className="btn-area" onClick={onSubmitHandler}>
90 + <button
91 + className="login-btn"
92 + >
93 + 로그인
94 + </button>
95 + </div>
96 + <div className="check-variable">
97 + {checkLoginError && <div style={{color : 'red'}}>정보를 제대로 입력해주세요.</div>}
98 + </div>
99 + </div>
100 + </div>
101 + );
102 +
103 +}
104 +
105 +export default LoginPage;
...\ No newline at end of file ...\ No newline at end of file
......
1 +* {
2 + margin: 0;
3 + padding: 0;
4 + box-sizing: border-box;
5 + background-color: rgb(245, 235, 223);
6 +}
7 +#body {
8 + display: flex;
9 + justify-content: center;
10 + align-items: center;
11 + border-top: 2px solid;
12 + border-bottom: 2px solid;
13 +
14 + .login-box {
15 + border: 2px solid;
16 + width: 35%;
17 + height: 60%;
18 + margin-top: 30px;
19 + margin-bottom: 30px;
20 + h2 {
21 + text-align: center;
22 + margin-top: 20px;
23 + margin-bottom: 20px;
24 + }
25 + }
26 + .input-area {
27 + display: flex;
28 + justify-content: center;
29 + align-items: center;
30 + margin-bottom: 5px;
31 +
32 + input {
33 + padding: 10px 0.1rem;
34 + background-color: rgb(255, 255, 255);
35 + }
36 + }
37 + .check-variable {
38 + display: flex;
39 + justify-content: center;
40 + align-items: center;
41 + margin-bottom: 5px;
42 + }
43 + .btn-area {
44 + display: flex;
45 + justify-content: center;
46 + margin-top: 30px;
47 + margin-bottom: 35px;
48 +
49 + button {
50 + width: 120px;
51 + height: 40px;
52 + font-size: large;
53 + font-weight: bold;
54 + background-color:rgb(255, 253, 238);
55 + cursor: pointer;
56 + }
57 + }
58 +}
......