NicknameChange.js 2.86 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
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29

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'
    }

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

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

36
    async function handleSubmit(event) {
Spark's avatar
Spark committed
37
        event.preventDefault();
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        if (inputname !== '') {
            await axios.post('/api/edit-profile', { nick_name: inputname })
                .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 {
56
                        console.log(response.data.msg);
57
58
59
                    }
                })
        }
60
    };
Spark's avatar
Spark committed
61
62
63
64
65
66
67
68
69
70

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

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

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

export default NicknameChange;