Signup.js 8.92 KB
Newer Older
Kim, Subin's avatar
Kim, Subin committed
1
import React, { useState, useEffect, useRef } from 'react';
이재연's avatar
..    
이재연 committed
2
import { Redirect } from 'react-router-dom';
Kim, Subin's avatar
Kim, Subin committed
3
4
import Nav1 from '../Components/MainNav';
import Nav2 from '../Components/SubNav';
이재연's avatar
이재연 committed
5
import { Form, Col, Container, Button, Row, Alert } from 'react-bootstrap'
이재연's avatar
이재연 committed
6
import FormCheckInput from 'react-bootstrap/esm/FormCheckInput';
이재연's avatar
이재연 committed
7
8
import DaumPostcode from "react-daum-postcode";

이재연's avatar
이재연 committed
9
10
11
12
13
14
15
16
const INIT_USER = {
    name: '',
    number: '',
    id: '',
    password: '',
    password2: '',
    tel: ''
}
Kim, Subin's avatar
Kim, Subin committed
17
18

function Signup() {
이재연's avatar
이재연 committed
19
20
21
22
23
24
25
26
27
28
29
30
    const [user, setUser] = useState(true)
    //const [disabled, setDisabled] = useState(true)
    const [error, setError] = useState('')

    //useEffect(() => {
    //    const isUser = Object.values(user).every(el => Boolean(el))
    //    isUser ? setDisabled(false) : setDisabled(true)
    //}, user)

    function handleChange(event) {
        const { name, value } = event.target
        setUser({ ...user, [name]: value })
이재연's avatar
이재연 committed
31
    }
이재연's avatar
이재연 committed
32
33
34

    const [validated, setValidated] = useState(false);

이재연's avatar
이재연 committed
35
36
37
    async function handleSubmit(event) {
        event.preventDefault()
        const form = event.currentTarget;
이재연's avatar
이재연 committed
38
39
        console.log(form)
        if (form.checkValidity() === false) {
이재연's avatar
이재연 committed
40
41
            event.preventDefault();
            event.stopPropagation();
이재연's avatar
이재연 committed
42
43
        }
        setValidated(true);
이재연's avatar
이재연 committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
        console.log(user)
        
        try {
            setError('')
            const response = await fetch('/api/users/signup', {
                method: 'POST',
                headers: {
                    'Content-Type': 'application/json'
                },
                body: JSON.stringify(user)
            })
            const data = await response.json()
            console.log(data)
        } catch (error) {
            console.log(error)
            setError('다시 시도하세요.')
        }
이재연's avatar
이재연 committed
61
    }
이재연's avatar
..    
이재연 committed
62

Kim, Subin's avatar
Kim, Subin committed
63
    return (
이재연's avatar
logsign    
이재연 committed
64
        <div>
이재연's avatar
이재연 committed
65

Kim, Subin's avatar
Kim, Subin committed
66
67
            <Nav1 />
            <Nav2 />
이재연's avatar
logsign    
이재연 committed
68
            <Container className="my-5">
이재연's avatar
이재연 committed
69
70
71
                {error && <Alert variant='danger'>
                    {error}
                </Alert>}
이재연's avatar
logsign    
이재연 committed
72
                <Row className="justify-content-center">
이재연's avatar
이재연 committed
73
                    <Col md={6} xs={10} className="border" style={{ background: '#F7F3F3' }}>
이재연's avatar
logsign    
이재연 committed
74
75
                        <h2 className="text-center mt-5">Sign Up</h2>

이재연's avatar
이재연 committed
76
77
78
79
                        <Form
                            noValidate validated={validated}
                            onSubmit={handleSubmit}
                            className="p-5">
이재연's avatar
logsign    
이재연 committed
80
81
82
83
84



                            <Form.Group controlId="formBasicName">
                                <Form.Row>
이재연's avatar
이재연 committed
85
                                    <Col sm={4} xs={6} as={Form.Label} for="id"> </Col>
이재연's avatar
logsign    
이재연 committed
86

이재연's avatar
이재연 committed
87
88
89
90
91
92
93
94
95
                                    <Col sm={8} xs={12} as={Form.Control}
                                        required type="text"
                                        name="name"
                                        placeholder="Name"
                                        style={{ width: '160px' }}
                                        value={user.name}
                                        onChange={handleChange} />

                                    <Form.Control.Feedback type="invalid">이름을 입력하세요. </Form.Control.Feedback>
이재연's avatar
logsign    
이재연 committed
96
97
98
99
100
                                </Form.Row>
                            </Form.Group>

                            <Form.Group controlId="formBasicNumber">
                                <Form.Row>
이재연's avatar
이재연 committed
101
                                    <Col sm={4} xs={6} as={Form.Label} for="number">주민등록번호</Col>
이재연's avatar
logsign    
이재연 committed
102

이재연's avatar
이재연 committed
103
104
105
106
107
108
109
110
111
                                    <Col as={Row} sm={8} xs={12} >
                                        <Form.Control
                                            required type="text"
                                            name="number1"
                                            maxlength="6"
                                            className="mx-2" style={{ width: '170px' }}
                                            value={user.number1}
                                            onChange={handleChange}>
                                        </Form.Control>
이재연's avatar
logsign    
이재연 committed
112
                                    -
이재연's avatar
이재연 committed
113
114
115
116
117
118
119
120
                                    <Form.Control
                                            required type="text"
                                            name="number2"
                                            maxlength="1" className="mx-3"
                                            style={{ width: '25px' }}
                                            value={user.number2}
                                            onChange={handleChange}>
                                        </Form.Control>
이재연's avatar
logsign    
이재연 committed
121
                                    ******
이재연's avatar
이재연 committed
122
                                    <Form.Control.Feedback type="invalid">주민등록번호를 입력하세요.</Form.Control.Feedback>
이재연's avatar
logsign    
이재연 committed
123
124
125
126
                                    </Col>

                                </Form.Row>
                            </Form.Group>
이재연's avatar
이재연 committed
127
128
                            <Form.Group controlId="formBasicId">
                                <Form.Row>
이재연's avatar
이재연 committed
129
130
131
132
133
134
135
136
137
138
139
                                    <Col sm={4} xs={6} as={Form.Label} for="id">아이디</Col>

                                    <Col sm={8} xs={12} as={Form.Control}
                                        required
                                        type="text"
                                        name="id"
                                        placeholder="ID"
                                        style={{ width: '160px' }}
                                        value={user.id}
                                        onChange={handleChange} />
                                    <Form.Control.Feedback type="invalid"> 아이디를 입력하세요.</Form.Control.Feedback>
이재연's avatar
이재연 committed
140
141
                                </Form.Row>
                            </Form.Group>
이재연's avatar
logsign    
이재연 committed
142
143
144

                            <Form.Group controlId="formBasicPassword">
                                <Form.Row>
이재연's avatar
이재연 committed
145
146
147
148
149
150
151
152
153
154
155
                                    <Col sm={4} xs={6} as={Form.Label} for="password">비밀번호</Col>
                                    <Col sm={8} xs={12} as={Form.Control}
                                        type="password"
                                        name="password"
                                        placeholder="Password"
                                        style={{ width: '160px' }}
                                        value={user.password}
                                        required
                                        onChange={handleChange} />
                                    <Form.Control.Feedback className="text-center" type="invalid">
                                        비밀번호를 입력하세요.
이재연's avatar
이재연 committed
156
                                    </Form.Control.Feedback>
이재연's avatar
logsign    
이재연 committed
157
158
159
160
161
                                </Form.Row>
                            </Form.Group>

                            <Form.Group controlId="formBasicPassword2">
                                <Form.Row>
이재연's avatar
이재연 committed
162
163
164
165
166
167
168
169
170
171
                                    <Col sm={4} xs={6} as={Form.Label} for="password">비밀번호 확인</Col>
                                    <Col sm={8} xs={12} as={Form.Control}
                                        type="password"
                                        name="password2"
                                        placeholder="Password"
                                        style={{ width: '160px' }}
                                        value={user.password2}
                                        required
                                        onChange={handleChange} />
                                    <Form.Control.Feedback type="invalid"> 비밀번호를 한번  입력하세요.
이재연's avatar
이재연 committed
172
                                    </Form.Control.Feedback>
이재연's avatar
logsign    
이재연 committed
173
174
175
176
177
                                </Form.Row>
                            </Form.Group>

                            <Form.Group controlId="formBasicTel">
                                <Form.Row>
이재연's avatar
이재연 committed
178
179
180
181
182
183
184
185
186
187
                                    <Col sm={4} xs={6} as={Form.Label} for="tel">휴대전화</Col>

                                    <Col sm={8} xs={12} as={Form.Control}
                                        required
                                        type="text"
                                        name="tel"
                                        size="sm" style={{ width: '160px' }}
                                        value={user.tel}
                                        onChange={handleChange} />
                                    <Form.Control.Feedback type="invalid"> 휴대전화를 입력하세요. </Form.Control.Feedback>
이재연's avatar
logsign    
이재연 committed
188
189
190
                                </Form.Row>
                            </Form.Group>

이재연's avatar
이재연 committed
191
192
193
194
195
196
                            <Button
                                style={{ background: '#91877F', borderColor: '#91877F' }} type="submit" block>
                                Sign Up
                            </Button>


이재연's avatar
logsign    
이재연 committed
197
198
199
200
201
202
203
204

                        </Form>

                    </Col>
                </Row>

            </Container>
        </div>
이재연's avatar
..    
이재연 committed
205

Kim, Subin's avatar
Kim, Subin committed
206
207
208
209
    )
}

export default Signup