SignupComp.js 6.5 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, FloatingLabel } 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
        justifyContent: 'center',
        margin: 'auto',
Spark's avatar
Spark committed
26
27
        padding: '0.5em',
        color: 'black'
Spark's avatar
Spark committed
28
29
30
    }

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

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

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

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

Spark's avatar
Spark committed
43
44
45
    function handleChange(event) {
        const { name, value } = event.target
        setFormValues({ ...formValues, [name]: value })
Spark's avatar
Spark committed
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
        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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
    }

    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
83

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


Spark's avatar
Spark committed
93
94
95


    return (
Spark's avatar
Spark committed
96

Spark's avatar
Spark committed
97
98
        <Row className='text-center w-100 my-2'>
            <Card style={cardstyled}>
Spark's avatar
Spark committed
99
                <Card.Title id='impactTitle'>
Spark's avatar
Spark committed
100
101
102
103
104
105
106
                    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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
                    <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
128

Spark's avatar
Spark committed
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
                        <FloatingLabel
                            controlId="floatingInput"
                            label="Name"
                            className='mb-3'
                        >
                            <Form.Control
                                type="text"
                                name="name"
                                placeholder="Name"
                                value={formValues.name}
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>
                        <FloatingLabel
                            controlId="floatingInput"
                            label="Email Address"
                        >
                            <Form.Control
                                type="email"
                                name="email"
                                placeholder="Email Address"
                                value={formValues.email}
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>

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

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

                    <Row style={{ margin: 'auto', marginBottom: '5px', display: 'flex', justifyContent: 'center' }}>
Spark's avatar
Spark committed
175
176
                        <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
177
178
179
180
181
182
183
184
185
                        </a>
                    </Row>
                </Card.Text>
            </Card>
        </Row>
    )
}

export default SignupComp;