Roomnamechange.js 3.59 KB
Newer Older
권병윤's avatar
0806    
권병윤 committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { useParams } from "react-router-dom";
import React, { useEffect, useState } from "react";
import RoomApi from "../../apis/room.api";
import catchErrors from "../../context/catchError";

const INIT_Room = {
  id: "",
  name: "",
};

const Roomnamechange = () => {
  const { roomId } = useParams();
  const [Room, setRoom] = useState(INIT_Room);
  const [error, setError] = useState("");

  Room.id = roomId;

  async function getdata(Roomdata) {
    try {
우지원's avatar
우지원 committed
20
      const data = await RoomApi.getRoom([Roomdata]);
권병윤's avatar
0806    
권병윤 committed
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
      setRoom(data);
      console.log(data);
    } catch (error) {
      catchErrors(error, setError);
    }
  }
  useEffect(() => {
    getdata(roomId);
  }, []);

  const updateinfo = (event) => {
    const { name, value } = event.target;
    setRoom({ ...Room, [name]: value });
    console.log(Room);
  };

  const changeinfo = async (event) => {
    const req = await RoomApi.changename(Room);
  };

  return (
    <div className="d-flex flex-row-reverse">
      <button
        type="submit"
        data-bs-toggle="modal"
        data-bs-target="#changeRoomname"
        style={{
          weight: "100px",
          height: "60px",
          backgroundColor: "#f5cfe3",
          borderRadius: "5px",
          color: "black",
          border: "1px #f5cfe3",
        }}
      >
         이름 변경
      </button>

      <div
        className="modal fade"
        id="changeRoomname"
        tabIndex="-1"
        aria-labelledby="changeRoomnameLabel"
        aria-hidden="true"
      >
        <div className="modal-dialog">
          <div className="modal-content">
            <div className="modal-header">
              <button
                type="button"
                className="btn-close"
                data-bs-dismiss="modal"
                aria-label="Close"
              ></button>
            </div>
            <div className="modal-body d-flex justify-content-center"></div>
            <div className="row mb-3">
              <div className="d-flex justify-content-center" style={{ margin:"0px"}}>
                {/* <Link to="/user/:id"> */}
                <p style={{marginTop: "31px", marginBottom: "0px"}}> 이름: </p>
                <input
                  onChange={updateinfo}
                  name="name"
                  value={Room.name}
                  type="text"
                  className="form-control my-4 "
                  placeholder="변경할 방 이름 입력"
                  style={{
                    background: "#fcf4ff",
                    borderTop: "0",
                    borderRight: "0",
                    borderLeft: "0",
                    borderBottom: "1",
                    borderColor: "#d4cafb",
                    height: "38px",
                    width: "130px",
                    marginTop: "0px",
                    marginBottom: "0px"
                  }}
                />
                </div>
                <div className="d-flex justify-content-evenly">
                {/* <Link to={`/room/${roomId}/${Room.channel}`}> */}
                <button
                  onClick={changeinfo}
                  type="button"
                  className="col-2 p-1 btn btn-primary"
                >
                  저장
                </button>
                {/* </Link> */}
                <button
                  type="submit"
                  className="col-2 p-1 btn btn-primary"
                  data-bs-dismiss="modal"
                >
                  취소
                </button>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

export default Roomnamechange;