-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyStudy.js
More file actions
110 lines (102 loc) · 3.91 KB
/
MyStudy.js
File metadata and controls
110 lines (102 loc) · 3.91 KB
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
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
import React from 'react';
import { withRouter } from 'react-router';
import {createBrowserHistory} from 'history';
import axios from 'axios';
import {Card,Button} from 'react-bootstrap';
const MyStudy = (props) => {
const mystudy = props.mystudy;
const mystudy_id = mystudy.id;
const URL_room = 'https://nudo-study.cf/api/studies/do/'+mystudy_id;
const URL_recruit = 'https://nudo-study.cf/api/studies/completed/'+mystudy_id;
const URL_delete = 'https://nudo-study.cf/api/studies/setting/'+mystudy_id;
const fetchRoom = async () => {
try{
const response = await axios.get(URL_room,{ withCredentials: true });
console.log(response.data);
if(response.data.code==="200"){
window.location.assign('/room/'+response.data.addr); //새로고침
}
}catch(e){
console.log(e);
}
}
const enterManage = () =>{
props.history.push({ //import {useHistory} from "react-router";
pathname: '/manage/'+ mystudy_id,
state: {studyTitle: mystudy.title, startDate: mystudy.date_start}
});
}
const recruited = async () => {
console.log('모집완료');
try{
const response = await axios.get(URL_recruit,{ withCredentials: true });
console.log(response.data);
if(response.data.code==="200"){
console.log('모집완료 확인');
window.location.replace('/studies/my');
}
}catch(e){
console.log(e);
}
}
const deleteStudy = async () => {
console.log('스터디 삭제');
try{
const response = await axios.delete(URL_delete,{ withCredentials: true });
console.log(response.data);
if(response.data.code === 200 ){
console.log('삭제 확인');
window.location.replace('/studies/my');
}
}catch(e){
console.log(e);
}
}
return (
<div>
<Card>
<Card.Header>{mystudy.topic}</Card.Header>
<Card.Body>
<Card.Title>{mystudy.title}</Card.Title>
<Card.Text>
목표 시간: {mystudy.target_time} <br/>
멤버 수: {mystudy.member_number} <br/>
하루 벌금: {mystudy.penalty} <br/>
스터디 정보: {mystudy.info} <br/>
방장이름: {mystudy.leader} <br/>
스터디 아이디: {mystudy.id} <br/>
</Card.Text>
{
(mystudy.is_recruit===false)?
<>
<Button size="sm" onClick={() => {fetchRoom()}}>공부 시작</Button>
<Button size="sm" onClick={() => {enterManage()}}>관리</Button>
</>
:
null
}
{
(mystudy.is_recruit===true && localStorage.getItem('user')===mystudy.leader)?
<>
<Button size="sm" variant="warning" onClick={() => {recruited()}}>모집 완료</Button>
</>
:
null
}
{
(localStorage.getItem('user')===mystudy.leader)?
<>
<Button size="sm" variant="warning" onClick={() => {deleteStudy()}}>삭제</Button>
</>
:
null
}
</Card.Body>
</Card>
<br/>
</div>
);
};
export default withRouter(MyStudy);