InitRoom.js 2.01 KB
Newer Older
Kim, Chaerin's avatar
Kim, Chaerin committed
1
2
3
4
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
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
import { useEffect, useState } from "react";
import catchErrors from "../../context/catchError";
import { useParams } from "react-router-dom";
import roomApi from "../../apis/room.api";

const INIT_ROOM = {
    id: "",
    name: "",
    profileimg: "",
};

const InitRoom = () => {
    const { roomId } = useParams();
    const [room, setRoom] = useState(INIT_ROOM);
    const [error, setError] = useState("");

    async function getRoom(roomId) {
        console.log(roomId)
        try {
            const data = await roomApi.getRoom([roomId]);
            setRoom(data[0]);
        } catch (error) {
            catchErrors(error, setError);
        }
    }
    console.log(room)

    useEffect(() => {
        console.log('roomId확인', roomId)
        getRoom(roomId);
    }, [roomId]);

    return (
        <div>
            <div style={{ backgroundColor: "#262626", width: "auto", height: "2px" }} />
            <form className="flex-row align-items-center justify-content-center m-5">
                <div className="d-flex justify-content-center">
                    <img
                        src={`/roomUploads/${room.profileimg}`}
                        className="rounded-circle"
                        style={{
                            width: "250px",
                            height: "250px",
                        }}
                    />
                </div>
                <div className="d-flex justify-content-center mt-3">
                    <div>
                        <div className="row">
                            <h6 className="col" style={{ text: 'center' }}> 방이름 </h6>
                            <h4 className="col"> {room.name} </h4>
                        </div>
                        <div className="row">
                            <h6 className="col"> 방코드 </h6>
                            <h4 className="col"> {room.id} </h4>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    );
};

export default InitRoom;