|
1 | | -// src/components/SignUp.jsx |
2 | | -import React from 'react'; |
3 | | -import '../login/Login.css'; // 로그인과 같은 스타일 사용 |
| 1 | +import React, { useState } from 'react'; |
| 2 | +import axios from 'axios'; |
| 3 | +import config from '../../config'; |
| 4 | + |
| 5 | +import '../login/Login.css'; |
4 | 6 |
|
5 | 7 | function SignUp() { |
| 8 | + const [formData, setFormData] = useState({ |
| 9 | + username: '', |
| 10 | + email: '', |
| 11 | + password: '', |
| 12 | + confirmPassword: '', |
| 13 | + name: '', |
| 14 | + }); |
| 15 | + |
| 16 | + const handleChange = (e) => { |
| 17 | + setFormData({ |
| 18 | + ...formData, |
| 19 | + [e.target.id]: e.target.value, |
| 20 | + }); |
| 21 | + }; |
| 22 | + |
| 23 | + const handleSubmit = async (e) => { |
| 24 | + e.preventDefault(); |
| 25 | + |
| 26 | + if (formData.password !== formData.confirmPassword) { |
| 27 | + alert('비밀번호가 일치하지 않습니다.'); |
| 28 | + return; |
| 29 | + } |
| 30 | + |
| 31 | + try { |
| 32 | + const response = await axios.post(`${config.API_BASE_URL}/api/users/signup`, { |
| 33 | + userId: formData.username, |
| 34 | + email: formData.email, |
| 35 | + password: formData.password, |
| 36 | + name: formData.name, |
| 37 | + }); |
| 38 | + |
| 39 | + console.log('회원가입 성공:', response.data); |
| 40 | + alert('회원가입이 완료되었습니다!'); |
| 41 | + } catch (error) { |
| 42 | + console.error('회원가입 오류:', error.response?.data || error.message); |
| 43 | + alert(error.response?.data?.message || '회원가입에 실패했습니다.'); |
| 44 | + } |
| 45 | + }; |
| 46 | + |
6 | 47 | return ( |
7 | 48 | <div className="login-container"> |
8 | 49 | <div className="login-box"> |
9 | 50 | <h1 className="login-title">회원가입</h1> |
10 | 51 | <p className="login-subtitle">CodeViz 계정을 만들고 코드 시각화를 시작하세요</p> |
11 | 52 |
|
12 | | - <form className="login-form"> |
| 53 | + <form className="login-form" onSubmit={handleSubmit}> |
13 | 54 | <label htmlFor="username">아이디 *</label> |
14 | | - <input id="username" type="text" placeholder="사용할 아이디 입력" required /> |
| 55 | + <input |
| 56 | + id="username" |
| 57 | + type="text" |
| 58 | + placeholder="사용할 아이디 입력" |
| 59 | + value={formData.username} |
| 60 | + onChange={handleChange} |
| 61 | + required |
| 62 | + /> |
15 | 63 |
|
16 | 64 | <label htmlFor="email">이메일 *</label> |
17 | | - <input id="email" type="email" placeholder="name@example.com" required /> |
| 65 | + <input |
| 66 | + id="email" |
| 67 | + type="email" |
| 68 | + placeholder="name@example.com" |
| 69 | + value={formData.email} |
| 70 | + onChange={handleChange} |
| 71 | + required |
| 72 | + /> |
18 | 73 | <small>인증번호를 받을 이메일 주소를 입력해주세요.</small> |
19 | 74 |
|
20 | 75 | <label htmlFor="password">비밀번호 *</label> |
21 | | - <input id="password" type="password" required /> |
| 76 | + <input |
| 77 | + id="password" |
| 78 | + type="password" |
| 79 | + value={formData.password} |
| 80 | + onChange={handleChange} |
| 81 | + required |
| 82 | + /> |
22 | 83 | <small>비밀번호는 8자 이상이어야 합니다.</small> |
23 | 84 |
|
24 | | - <label htmlFor="confirm-password">비밀번호 확인 *</label> |
25 | | - <input id="confirm-password" type="password" required /> |
| 85 | + <label htmlFor="confirmPassword">비밀번호 확인 *</label> |
| 86 | + <input |
| 87 | + id="confirmPassword" |
| 88 | + type="password" |
| 89 | + value={formData.confirmPassword} |
| 90 | + onChange={handleChange} |
| 91 | + required |
| 92 | + /> |
26 | 93 |
|
27 | 94 | <label htmlFor="name">이름 *</label> |
28 | | - <input id="name" type="text" placeholder="홍길동" required /> |
| 95 | + <input |
| 96 | + id="name" |
| 97 | + type="text" |
| 98 | + placeholder="홍길동" |
| 99 | + value={formData.name} |
| 100 | + onChange={handleChange} |
| 101 | + required |
| 102 | + /> |
29 | 103 |
|
30 | 104 | <div className="remember-me"> |
31 | 105 | <input type="checkbox" id="terms" required /> |
32 | | - <label htmlFor="terms"><strong>이용약관에 동의합니다.</strong><br />이용약관을 읽고 동의합니다.</label> |
| 106 | + <label htmlFor="terms"> |
| 107 | + <strong>이용약관에 동의합니다.</strong><br /> |
| 108 | + 이용약관을 읽고 동의합니다. |
| 109 | + </label> |
33 | 110 | </div> |
34 | 111 |
|
35 | 112 | <div className="remember-me"> |
36 | 113 | <input type="checkbox" id="privacy" required /> |
37 | | - <label htmlFor="privacy"><strong>개인정보 처리방침에 동의합니다.</strong><br />개인정보 처리방침을 확인 후 동의합니다.</label> |
| 114 | + <label htmlFor="privacy"> |
| 115 | + <strong>개인정보 처리방침에 동의합니다.</strong><br /> |
| 116 | + 개인정보 처리방침을 확인 후 동의합니다. |
| 117 | + </label> |
38 | 118 | </div> |
39 | 119 |
|
40 | 120 | <button type="submit">회원가입 완료</button> |
|
0 commit comments