InvitePage.js 3.88 KB
Newer Older
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
1
import Header from "../components/Header";
권병윤's avatar
0807    
권병윤 committed
2
3
4
5
6
import { useState, useEffect } from "react";
import { useParams } from "react-router";
import roomApi from "../apis/room.api";
import userApi from "../apis/user.api";
import catchErrors from "../context/catchError";
권병윤's avatar
0806    
권병윤 committed
7

권병윤's avatar
0807    
권병윤 committed
8
9
10
11
12
13
const INIT_PROFILE = {
  id: "",
  roomNumber: ""
};

// userapi로 유저정보 불러다가, 참여방 목록에 그 방아이디 추가하고, 방에도 그 유저 아이디 추가한 다음에 참가시키기.
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
14
const InvitePage = () => {
권병윤's avatar
0807    
권병윤 committed
15
16
17
  const [profile, setProfile] = useState([INIT_PROFILE]);
  const [success, setSuccess] = useState(false);
  const [error,setError]=useState("");
권병윤's avatar
0806    
권병윤 committed
18
  const usercheck = localStorage.getItem("user");
권병윤's avatar
0807    
권병윤 committed
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
  const {roomId} = useParams();

  async function getProfile(userID) {
    try {
      const data = await userApi.getUser(userID);
      setProfile(data);
    } catch (error) {
      catchErrors(error, setError);
    }
  }

  async function joinroom(userId,roomId) {
    try {
        // setLoading(true);
        setError("");
        const data = await roomApi.join({ userId: userId, roomId: roomId });
        console.log('서버연결됬나요', data)
        setSuccess(true);
    } catch (error) {
        catchErrors(error, setError);
    } finally {
        // setLoading(false);
    }
}
  useEffect(() => {
    getProfile(usercheck);
  }, []);
권병윤's avatar
0806    
권병윤 committed
46
47
48
49

  function goInvitedroom() {
    let check1= null;
    let check2= null;
권병윤's avatar
0807    
권병윤 committed
50
    console.log(usercheck);
권병윤's avatar
0806    
권병윤 committed
51
    if (usercheck)
권병윤's avatar
0807    
권병윤 committed
52
53
54
55
56
      joinroom(usercheck,roomId);
      if(success)
        check1 = window.confirm("방 참여가 완료되었습니다.")
        if(check1)
        window.location.href=`/user/${usercheck}`
권병윤's avatar
0806    
권병윤 committed
57
58
59
60
    else 
      check2 = window.confirm("로그인이 필요합니다.")
      if(check2)
        window.location.href="/"
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
61
62
  }

권병윤's avatar
0806    
권병윤 committed
63
64
65
66
67
  function invitereject() {
    if(usercheck)
    window.location.href=`/user/${usercheck}`
    else
    window.location.href="/"
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
68
69
70
71
72
73
74
75
76
  }

  return (
    <div>
      {/*페이지 전체*/}
      <Header />
      <div className="d-flex justify-content-evenly">
        {/* 위 사진,이름 */}
        <div
권병윤's avatar
0806    
권병윤 committed
77
78
79
80
81
82
83
84
85
          // style={{
          //   width: "100%",
          //   height: "140px",
          //   textAlign: "center",
          //   border: "3px",
          //   borderStyle: "none solid solid",
          //   borderColor: "red",
          //   fontSize: "12px",
          // }}
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
86
        >
권병윤's avatar
0806    
권병윤 committed
87
          {/* 방 부분
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
88
89
90
          <p style={{ marginBottom: "0px", fontSize: "16px" }}>초대받은 방</p>
          <img style={{ width: "90px", height: "90px" }}></img>
          <p style={{ marginBottom: "0px", fontSize: "16px" }}>
권병윤's avatar
0806    
권병윤 committed
91
92
            방 id: ${roomid}
          </p> */}
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
93
94
95
96
        </div>
      </div>

      <div
권병윤's avatar
0806    
권병윤 committed
97
98
99
100
101
102
103
104
        // style={{
        //   width: "80%",
        //   height: "200px",
        //   textAlign: "center",
        //   fontSize: "18px",
        //   marginLeft: "10%",
        //   marginRight: "10%",
        // }}
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
105
106
      >
        {/* 아래 텍스트 */}
권병윤's avatar
0806    
권병윤 committed
107
108
109
110
111
112
113
114
115
116
117
        <p align= "center" style={{
          fontSize: "30px",
          marginTop: "120px",
          marginBottom: "80px"
        }}>
          축하합니다! 친구가 당신을
          <br/>
          화상회의에 초대했습니다.
          <br/>
          <br/>
          <b>초대를 수락하시겠습니까?</b>
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
118
119
120
121
122
123
124
125
126
127
        </p>
      </div>

      <div className="d-flex justify-content-evenly">
        {/* 수락, 거절 버튼 */}
        <button
          type="submit"
          className="col-2 p-1 btn btn-primary"
          data-bs-dismiss="modal"
          style={{ width: "120px" }}
권병윤's avatar
0806    
권병윤 committed
128
129
          onClick={goInvitedroom}
          
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
130
131
132
133
134
135
136
137
        >
          수락
        </button>
        <button
          type="submit"
          className="col-2 p-1 btn btn-primary"
          data-bs-dismiss="modal"
          style={{ width: "120px" }}
권병윤's avatar
0806    
권병윤 committed
138
          onClick={invitereject}
Kim, Chaerin's avatar
merge19    
Kim, Chaerin committed
139
140
141
142
143
144
145
146
147
        >
          거절
        </button>
      </div>
    </div>
  );
};

export default InvitePage;