SignupComp.js 5.06 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';
Spark's avatar
Spark committed
6
import { routesClient } from './../routesClient';
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
35
        email: '',
        isOauth: false
Spark's avatar
Spark committed
36
37
38
    }

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

    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
    }
Spark's avatar
Spark committed
47
48
49

    async function handleSubmit(event) {
        event.preventDefault();
Spark's avatar
Spark committed
50
        const res = await axios.post(routesClient.signup, formValues)
51
52
        console.log('existing_user : ', res.data.contents.existing_user)
        setUserExist(res.data.contents.existing_user)
53
        setAlertShow(true)
54
    }
55

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

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

Spark's avatar
Spark committed
90
91
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
                        <FloatingLabel
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
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>
                        <FloatingLabel
                            label="Email Address"
                        >
                            <Form.Control
                                type="email"
                                name="email"
                                placeholder="Email Address"
                                onChange={handleChange}
                                required
                            />
                        </FloatingLabel>

115
                        <Button variant='light' className='mt-3' id='formbtn' type='submit'>
Spark's avatar
Spark committed
116
117
118
119
                            Sign Up
                        </Button>
                    </Form>

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

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

export default SignupComp;