SignupComp.js 5.12 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
import axios from 'axios';
Spark's avatar
Spark committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23

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

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

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

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

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

Spark's avatar
Spark committed
44
45
46
    function handleChange(event) {
        const { name, value } = event.target
        setFormValues({ ...formValues, [name]: value })
Spark's avatar
Spark committed
47
    }
Spark's avatar
Spark committed
48
49
50
51
52
    console.log('???', formValues)

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

Spark's avatar
Spark committed
55
    return (
Spark's avatar
Spark committed
56

Spark's avatar
Spark committed
57
58
        <Row className='text-center w-100 my-2'>
            <Card style={cardstyled}>
Spark's avatar
Spark committed
59
                <Card.Title id='impactTitle'>
Spark's avatar
Spark committed
60
61
62
63
64
65
66
                    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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
                    <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
88

Spark's avatar
Spark committed
89
90
91
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
                        <FloatingLabel
                            controlId="floatingInput"
Spark's avatar
Spark committed
92
                            label="Nickname"
Spark's avatar
Spark committed
93
94
95
96
                            className='mb-3'
                        >
                            <Form.Control
                                type="text"
Spark's avatar
Spark committed
97
98
                                name="nick_name"
                                placeholder="Nickname"
Spark's avatar
Spark committed
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>
                        <FloatingLabel
                            controlId="floatingInput"
                            label="Email Address"
                        >
                            <Form.Control
                                type="email"
                                name="email"
                                placeholder="Email Address"
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>

Spark's avatar
Spark committed
116
117
                        <Button variant='light' className='mt-3' id='formbtn' type='submit'>
                            {/*  onClick={CheckUserExist} */}
Spark's avatar
Spark committed
118
119
120
121
                            Sign Up
                        </Button>
                    </Form>

Spark's avatar
Spark committed
122
123
124
125
126
127
128
129
130
                    <Row className='d-flex align-items-center m-2'>
                        <Col>
                            <hr />
                        </Col>
                        OR
                        <Col>
                            <hr />
                        </Col>
                    </Row>
Spark's avatar
Spark committed
131
132

                    <Row style={{ margin: 'auto', marginBottom: '5px', display: 'flex', justifyContent: 'center' }}>
Spark's avatar
Spark committed
133
134
                        <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
135
136
137
138
139
140
141
142
143
                        </a>
                    </Row>
                </Card.Text>
            </Card>
        </Row>
    )
}

export default SignupComp;