SignupComp.js 6.52 KB
Newer Older
Spark's avatar
Spark committed
1
import React, { useState } from 'react'
Spark's avatar
Spark committed
2
import '../App.css'
Spark's avatar
Spark committed
3
import { Form, Button, Row, Col, Card, Alert } from 'react-bootstrap';
Spark's avatar
Spark committed
4
import { LoginWithKakao } from '../utils/Oauth';
Spark's avatar
Spark committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

function SignupComp() {

    const cardstyled = {
        margin: 'auto',
        padding: '1em',
        display: 'flex',
        justifyContent: 'center',
        width: '100%',
        borderWidth: '3px',
        borderRadius: '20px',
        borderColor: 'rgb(110, 189, 142)',
        color: '#04AB70'
    }

    const inboxstyled = {
        display: 'flex',
        flexDirection: 'column',
Spark's avatar
Spark committed
23
        maxWidth: '80%',
Spark's avatar
Spark committed
24
25
26
27
28
29
        justifyContent: 'center',
        margin: 'auto',
        padding: '1rem'
    }

    const initValues = {
Spark's avatar
Spark committed
30
31
        name: '',
        email: ''
Spark's avatar
Spark committed
32
33
34
35
36
    }

    const [formValues, setFormValues] = useState(initValues)
    const [validated, setValidated] = useState(false)

Spark's avatar
Spark committed
37
38
39
40
41
    const [emailSubm, setEmailSubm] = useState(false)

    const [userExist, setUserExist] = useState(false)
    const [alertShow, setAlertShow] = useState(false)

Spark's avatar
Spark committed
42
43
44
    function handleChange(event) {
        const { name, value } = event.target
        setFormValues({ ...formValues, [name]: value })
Spark's avatar
Spark committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
        console.log('???', formValues)
    }

    function CheckUserExist() {
        localStorage.setItem('signup_username', formValues.name)
        localStorage.setItem('signup_email_Address', formValues.email)

        const signUser = localStorage.getItem('signup_username')
        const signEmail = localStorage.getItem('signup_email_Address').split('@')[1]

        if (signEmail && signUser) {
            setAlertShow(true)
            setUserExist(!userExist)
        }
        else
            if (!signEmail) {
                setAlertShow(false)
                // setUserExist(true)
            }
Spark's avatar
Spark committed
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    }

    function handleSubmit(event) {
        const form = event.currentTarget;
        console.log('formValues', formValues);
        console.log('formValues.values', Object.values(formValues)[0].length);

        // console.log(form)
        // if (Object.values(formValues)[0].length !== 0) { //form.checkValidity() === false
        //     event.preventDefault();
        //     event.stopPropagation();
        // }
        console.log(validated)
        setValidated(true);
        // const form = event.current
        // setFormError(validate(formValues))
        // setIsSubmit(true)
    }
Spark's avatar
Spark committed
82

Spark's avatar
Spark committed
83
84
85
86
    function handleClickSubm() {
        // setEmailSubm(true);
        const subm = document.getElementById("subm-mailSent");
        subm.style.visibility = 'visible'
Spark's avatar
Spark committed
87
88
        // const aftermail = document.getElementById('AftermailSent');
        // aftermail.style.display = ''
Spark's avatar
Spark committed
89
    }
Spark's avatar
Spark committed
90
91


Spark's avatar
Spark committed
92
93
94


    return (
Spark's avatar
Spark committed
95

Spark's avatar
Spark committed
96
97
        <Row className='text-center w-100 my-2'>
            <Card style={cardstyled}>
Spark's avatar
Spark committed
98
                <Card.Title id='impactTitle'>
Spark's avatar
Spark committed
99
100
101
102
103
104
105
                    Create an Account
                </Card.Title>
                <Card.Subtitle style={{ fontWeight: 'lighter' }}>
                    Sign up with your social media account or email address
                </Card.Subtitle>
                <hr />
                <Card.Text>
Spark's avatar
Spark committed
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
                    <Row className='m-auto d-flex justify-content-center' style={{ width: '80%' }}>
                        {!userExist ?
                            <Alert show={alertShow} variant={'success'}>
                                <Col>
                                    😊 계정 생성이 완료 되었습니다.
                                </Col>
                                <Alert.Link href='/login' style={{ fontSize: '0.8em' }}>
                                    로그인 하러가기 
                                </Alert.Link>
                            </Alert>
                            :
                            <Alert show={alertShow} variant={'danger'}>
                                <Col>
                                    🤔 이미 존재하는 계정입니다.
                                </Col>
                                <Alert.Link href='/login' style={{ fontSize: '0.8em' }}>
                                    로그인 하러가기 
                                </Alert.Link>
                            </Alert>
                        }
                    </Row>
Spark's avatar
Spark committed
127

Spark's avatar
Spark committed
128
129
                    <Form style={inboxstyled}
                        onSubmit={handleSubmit}>
Spark's avatar
Spark committed
130
                        <Form.Group controlId="username">
Spark's avatar
Spark committed
131
132
133
134
135
136
137
138
139
140
141
142
143
                            <Row className='m-auto mb-1 d-flex justify-content-center'>
                                <Form.Control
                                    type="text"
                                    name="name"
                                    placeholder="Name"
                                    value={formValues.name}
                                    onChange={handleChange}
                                    required
                                />
                            </Row>
                            <Row>
                                <p></p>
                            </Row>
Spark's avatar
Spark committed
144
145
146
147
148
149
150
151
152
                            <Row className='m-auto d-flex justify-content-center'>
                                <Form.Control
                                    type="email"
                                    name="email"
                                    placeholder="Email Address"
                                    value={formValues.email}
                                    onChange={handleChange}
                                    required
                                />
Spark's avatar
Spark committed
153
                            </Row>
Spark's avatar
Spark committed
154
                        </Form.Group>
Spark's avatar
Spark committed
155

Spark's avatar
Spark committed
156
157
                        <Button variant='light' className='mt-3' id='formbtn' onClick={CheckUserExist}>
                            {/* type="submit" */}
Spark's avatar
Spark committed
158
159
160
161
                            Sign Up
                        </Button>
                    </Form>

Spark's avatar
Spark committed
162
163
164
165
166
167
168
169
170
                    <Row className='d-flex align-items-center m-2'>
                        <Col>
                            <hr />
                        </Col>
                        OR
                        <Col>
                            <hr />
                        </Col>
                    </Row>
Spark's avatar
Spark committed
171
172

                    <Row style={{ margin: 'auto', marginBottom: '5px', display: 'flex', justifyContent: 'center' }}>
Spark's avatar
Spark committed
173
174
                        <a href="#;" onClick={LoginWithKakao} id='socialLink' >
                            <img src='http://image.kmib.co.kr/online_image/2020/0626/611514110014734788_1.jpg' id='logpng' alt='KAKAO' />
Spark's avatar
Spark committed
175
176
177
178
179
180
181
182
183
                        </a>
                    </Row>
                </Card.Text>
            </Card>
        </Row>
    )
}

export default SignupComp;