SignupComp.js 4.07 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import React, { useState } from "react";
import "../App.css";
import {
  Form,
  Button,
  Row,
  Col,
  Card,
  Alert,
  FloatingLabel,
} from "react-bootstrap";
import { AuthWithKakao } from "../utils/Oauth";
import axios from "axios";
import { routesClient } from "./../routesClient";
Spark's avatar
Spark committed
15
16

function SignupComp() {
17
18
19
20
21
22
23
24
25
26
27
  const cardstyled = {
    margin: "auto",
    padding: "1em",
    display: "flex",
    justifyContent: "center",
    width: "100%",
    borderWidth: "3px",
    borderRadius: "20px",
    borderColor: "rgb(110, 189, 142)",
    color: "#04AB70",
  };
Spark's avatar
Spark committed
28

29
30
31
32
33
34
35
36
37
  const inboxstyled = {
    display: "flex",
    flexDirection: "column",
    maxWidth: "80%",
    justifyContent: "center",
    margin: "auto",
    padding: "0.5em",
    color: "black",
  };
Spark's avatar
Spark committed
38

39
40
41
42
43
  const initValues = {
    nick_name: "",
    email: "",
    isOAuth: false,
  };
Spark's avatar
Spark committed
44

45
  const [formValues, setFormValues] = useState(initValues);
Spark's avatar
Spark committed
46

47
48
  const [userExist, setUserExist] = useState(false);
  const [alertShow, setAlertShow] = useState(false);
Spark's avatar
Spark committed
49

50
51
52
53
  function handleChange(event) {
    const { name, value } = event.target;
    setFormValues({ ...formValues, [name]: value });
  }
Spark's avatar
Spark committed
54

55
56
57
58
59
60
61
  async function handleSubmit(event) {
    event.preventDefault();
    const res = await axios.post(routesClient.signup, formValues);
    console.log("existing_user : ", res.data.contents.existing_user);
    setUserExist(res.data.contents.existing_user);
    setAlertShow(true);
  }
Spark's avatar
Spark committed
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
  return (
    <Row className="text-center w-100 my-2">
      <Card style={cardstyled}>
        <Card.Title id="impactTitle">계정 생성하기</Card.Title>
        <Card.Subtitle style={{ fontWeight: "lighter" }}>
          이메일 또는 소셜미디어로 계정을 생성하세요
        </Card.Subtitle>
        <hr />
        <Card.Text>
          <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>
92

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

113
114
115
116
            <Button variant="light" className="mt-3" id="formbtn" type="submit">
              회원가입
            </Button>
          </Form>
Spark's avatar
Spark committed
117

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

128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
          <Row
            style={{
              margin: "auto",
              marginBottom: "5px",
              display: "flex",
              justifyContent: "center",
            }}
          >
            <a href="#;" onClick={() => AuthWithKakao(false)} id="socialLink">
              <img
                src="http://image.kmib.co.kr/online_image/2020/0626/611514110014734788_1.jpg"
                id="logpng"
                alt="KAKAO"
              />
            </a>
          </Row>
        </Card.Text>
      </Card>
    </Row>
  );
Spark's avatar
Spark committed
148
149
}

150
export default SignupComp;