signup.tsx 3.22 KB
Newer Older
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
1
2
import React, { useState } from "react";
import { Link } from "react-router-dom";
Lee Soobeom's avatar
Lee Soobeom committed
3

Kim, MinGyu's avatar
Kim, MinGyu committed
4

Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
5
6
7
function PasswordUpdate() {
  const [password, setPassword] = useState("");
  const [confirm, setConfirm] = useState("");
Kim, MinGyu's avatar
Kim, MinGyu committed
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  const [result, setResult] = useState("");
  const [email, setEmail] = useState("");
  const [alert, setAlert] = useState("");

  function isEmail() {
    var regExp = /^[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*@[0-9a-zA-Z]([-_\.]?[0-9a-zA-Z])*\.[a-zA-Z]{2,3}$/i;
    
      if(regExp.test(email)){
        setAlert("이메일 형식이 맞습니다.")
      }else{
        setAlert("이메일 형식이 틀립니다.")
      }
     return
  }
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
22

Kim, MinGyu's avatar
Kim, MinGyu committed
23
  const reform = () => {
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
24
25
26
27

    if (password && confirm){
    
      if (password==confirm) {
Kim, MinGyu's avatar
Kim, MinGyu committed
28
        setResult("비밀번호가 일치합니다.");
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
29
      } else {
Kim, MinGyu's avatar
Kim, MinGyu committed
30
        setResult("비밀번호가 다릅니다.");
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
31
32
      }
    }else {
Kim, MinGyu's avatar
Kim, MinGyu committed
33
      setResult("비밀번호가 입력되지 않았습니다.")
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
34
35
36
37
38
    }

  };

  return (
Kim, MinGyu's avatar
Kim, MinGyu committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
    <div>
      <div className="place-self-center py-3 border-b border-white ">
        <input
          className="placeholder:text-slate-300
          bg-white border border-slate-500 rounded-2xl
          py-2 pl-9 pr-3 
          focus:border-black"placeholder="비밀번호" type="text"
          name="password"
          value={password}
          onChange={(e) => setPassword(e.target.value )}
        />
      </div>
      <div className="place-self-center py-3 border-b border-white ">
        
        <input
          className="placeholder:text-slate-300
          bg-white border border-slate-500 rounded-2xl
          py-2 pl-9 pr-3 
          focus:border-black"placeholder="비밀번호 확인" type="text"
          name="confirm"
          value={confirm}
          onKeyUp={reform} onChange={(e) => setConfirm(e.target.value )}
          >
          
        </input>
      </div>
      <p>{result}</p>

      <input className="placeholder:text-slate-300
            bg-white border border-slate-500 rounded-2xl
            py-2 pl-9 pr-3 
            focus:border-black
            " placeholder="email" type="text" name="Id" 
      onChange={(e) => setEmail(e.target.value )}
      onKeyUp={isEmail}
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
74
      />
Kim, MinGyu's avatar
Kim, MinGyu committed
75
76
      <p>{alert}</p>
    </div>
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
77
78
79
80
81
82
83
84
  );
}



export default function Signup () {
  return(

Kim, MinGyu's avatar
Kim, MinGyu committed
85
86
  <div className="gap-5 flex flex-col ">
    <div className="p-12 w-1/2 h-1/2 md:w-40 md:h-1/6 bg-red-400 place-self-center rounded-2xl">
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
87
88
          <Link to="/">Travel Report</Link>
        </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
89
90
      <div className="flex flex-col w-auto h-80 md:w-1/2 bg-white border-2 border-black grid place-items-center rounded-xl place-self-center">
        
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
91
92
93
94
95
96
97
          
        <div className="place-self-center py-3 border-b border-white ">
          <input className="placeholder:text-slate-300
            bg-white border border-slate-500 rounded-2xl
            py-2 pl-9 pr-3 
            focus:border-black" placeholder="ID " type="text"/>
        </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
98
          
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
99
        <div className="showText place-self-center">
Kim, MinGyu's avatar
Kim, MinGyu committed
100
          <PasswordUpdate />
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
101
        </div>
Kim, MinGyu's avatar
Kim, MinGyu committed
102
        
Kim, MinGyu's avatar
signup    
Kim, MinGyu committed
103
104
105
106
107
108
109
110
111
112
113
114
        <button className="place-self-center py-3 border-b border-white 
            ">
              회원가입 버튼
        </button>
            
      </div> 
    
    
  </div>
  )
}
//출처 : //https://www.daleseo.com/react-forms/