NicknameChange.js 2.91 KB
Newer Older
1
import axios from 'axios';
2
3
import React, { useState } from 'react'
import { Row, Card, Form, Button, FloatingLabel } from 'react-bootstrap';
4
import Swal from 'sweetalert2';
Spark's avatar
Spark committed
5
import { routesClient } from './../routesClient';
Spark's avatar
Spark committed
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30

function NicknameChange() {

    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',
        maxWidth: '80%',
        justifyContent: 'center',
        margin: 'auto',
        padding: '0.5em',
        color: 'black'
    }

31
    const [inputname, setInputname] = useState('')
Spark's avatar
Spark committed
32

33
34
    function handleChange({ target: { value } }) {
        setInputname(value)
Spark's avatar
Spark committed
35
36
    }

37
    async function handleSubmit(event) {
Spark's avatar
Spark committed
38
        event.preventDefault();
39
        if (inputname !== '') {
Spark's avatar
Spark committed
40
            await axios.post(routesClient.edit, { nick_name: inputname })
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
                .then(function (response) {
                    console.log(response.data.msg);
                    if (response.data.msg === 'OK!') {
                        Swal.fire({
                            title: '변경되었습니다.',
                            text: '축하드립니다!👏',
                            icon: 'success',
                            customClass: 'swal-wide',
                            confirmButtonText: '확인',
                        }).then(function (response) {
                            if (response.isConfirmed) {
                                window.location.reload()
                            }
                        })
                    }
                    else {
57
                        console.log(response.data.msg);
58
59
60
                    }
                })
        }
61
    };
Spark's avatar
Spark committed
62
63
64
65
66
67
68
69
70
71

    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>
72

Spark's avatar
Spark committed
73
74
                <hr />

75
                <Card.Text className='m-0'>
Spark's avatar
Spark committed
76
                    <Form style={inboxstyled} onSubmit={handleSubmit}>
77
                        <FloatingLabel label="Nickname">
78
                            <Form.Control type="text" placeholder="닉네임 변경" id='nickname' onChange={handleChange} required />
Spark's avatar
Spark committed
79
80
81
82
83
84
85
86
87
88
89
90
                        </FloatingLabel>
                        <Button variant='light' className='mt-3' id='formbtn' type='submit'>
                             
                        </Button>
                    </Form>
                </Card.Text>
            </Card>
        </Row>
    )
}

export default NicknameChange;