SignupComp.js 5.34 KB
Newer Older
1
import React, { useEffect, 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
import axios from 'axios';
6
import { callUserInfo } from '../utils/CheckDB';
Spark's avatar
Spark committed
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24

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
25
        maxWidth: '80%',
Spark's avatar
Spark committed
26
27
        justifyContent: 'center',
        margin: 'auto',
Spark's avatar
Spark committed
28
29
        padding: '0.5em',
        color: 'black'
Spark's avatar
Spark committed
30
31
32
    }

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

    const [formValues, setFormValues] = useState(initValues)
Spark's avatar
Spark committed
38
39
40
41

    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
    // console.log('???', formValues)
Spark's avatar
Spark committed
47
48
49
50

    async function handleSubmit(event) {
        event.preventDefault();
        await axios.post("/api/signup", formValues)
Spark's avatar
Spark committed
51
    }
Spark's avatar
Spark committed
52

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
    const [userInfo, setUserInfo] = useState([])

    function CheckUserExist() {
        setUserInfo(callUserInfo())
        setAlertShow(true)
        if (userInfo) {
            setUserExist(true)
            // 기존회원
        }
        if (callUserInfo() === undefined) {

            setUserExist(false)
            // 신규회원
        }
    }
    console.log(callUserInfo())
    console.log(userExist)


Spark's avatar
Spark committed
72
    return (
Spark's avatar
Spark committed
73

Spark's avatar
Spark committed
74
75
        <Row className='text-center w-100 my-2'>
            <Card style={cardstyled}>
Spark's avatar
Spark committed
76
                <Card.Title id='impactTitle'>
Spark's avatar
Spark committed
77
78
79
80
81
82
83
                    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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
                    <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
105

Spark's avatar
Spark committed
106
107
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
                        <FloatingLabel
Spark's avatar
Spark committed
108
                            label="Nickname"
Spark's avatar
Spark committed
109
110
111
112
                            className='mb-3'
                        >
                            <Form.Control
                                type="text"
Spark's avatar
Spark committed
113
114
                                name="nick_name"
                                placeholder="Nickname"
Spark's avatar
Spark committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>
                        <FloatingLabel
                            label="Email Address"
                        >
                            <Form.Control
                                type="email"
                                name="email"
                                placeholder="Email Address"
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>

131
                        <Button variant='light' className='mt-3' id='formbtn' type='submit' onClick={CheckUserExist}>
Spark's avatar
Spark committed
132
133
134
135
                            Sign Up
                        </Button>
                    </Form>

Spark's avatar
Spark committed
136
137
138
139
140
141
142
143
144
                    <Row className='d-flex align-items-center m-2'>
                        <Col>
                            <hr />
                        </Col>
                        OR
                        <Col>
                            <hr />
                        </Col>
                    </Row>
Spark's avatar
Spark committed
145
146

                    <Row style={{ margin: 'auto', marginBottom: '5px', display: 'flex', justifyContent: 'center' }}>
Spark's avatar
Spark committed
147
148
                        <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
149
150
151
152
153
154
155
156
157
                        </a>
                    </Row>
                </Card.Text>
            </Card>
        </Row>
    )
}

export default SignupComp;