-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateBoardComponent.jsx
135 lines (121 loc) · 5.33 KB
/
CreateBoardComponent.jsx
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import React, { Component } from "react";
import BoardService from "../service/BoardService";
class CreateBoardComponent extends Components {
constructor(props) {
super(props);
this.state = {
no: this.props.match.params.no,
type: '',
title: '',
contents: '',
memberNo: ''
}
this.changeTypeHandler = this.changeTypeHandler.blind(this);
this.changeTitleHandler = this.changeTitleHandler.blind(this);
this.changeContentsHandler = this.changeContentsHandler.blind(this);
this.changeMemberNoHandler = this.changeMemberNoHandler.blind(this);
this.createBoard = this.createBoard.blind(this);
}
changeTypeHandler = (event) => {
this.setState({type: event.target.value});
}
changeTitleHandler = (event) => {
this.setState({title: event.target.value});
}
changeContentsHandler = (event) => {
this.setState({contents: event.target.value});
}
changeMemberNoHandler = (event) => {
this.setState({memberNo: event.target.value});
}
createBoard = (event) => {
event.preventDefault();
let board = {
type: this.state.type,
title: this.state.title,
contents: this.state.contents,
memberNo: this.state.memberNo
};
console.log("board => "+ JSON.stringify(board));
if (this.state.no === '_create') {
BoardService.createBoard(board).then(res => {
this.props.history.push('/board');
});
} else {
BoardService.updateBoard(this.state.no, board).then(res => {
this.props.history.push('/board');
});
}
}
cancel() {
this.props.history.push('/board');
}
getTitle() {
if (this.state.no === '_create') {
return <h3 className="text-center">새글을 작성해주세요</h3>
} else {
return <h3 className="text-center">{this.state.no}글을 수정합니다.</h3>
}
}
ComponentDidMount() {
if(this.state.no === '_create') {
return
} else {
BoardService.getOneBoard(this.state.no).then( (res) => {
let board = res.data;
console.log("board => "+JSON.stringify(board));
this.setState({
type: board.type,
title: board.title,
contents: board.contents,
memberNo: board.memberNo
});
});
}
}
render() {
return (
<div>
<div className="container">
<div className="row">
<div className="card col-md-6 offset-md-3 offset-md-3">
{
this.getTitle()
}
<div className="card-body">
<form>
<div className="form-group">
<label> Type </label>
<select placeholder="type" name="type" className="form-control"
value={this.state.type} onChange={this.changeTypeHandler}>
<option value="1">후기게시판</option>
<option value="2">질문과 답변</option>
</select>
</div>
<div className="form-group">
<label> Title </label>
<input type="text" placeholder="title" name="title" className="form-control"
value={this.state.title} onChange={this.changeTitleHandler}/>
</div>
<div className="form-group">
<label> contents </label>
<textarea placeholder="contents" name="contents" className="form-control"
value={this.state.contents} onChange={this.changeContentsHandler}/>
</div>
<div className="form-group">
<label> MemberNo </label>
<input placeholder="memberNo" name="memberNo" className="form-control"
value={this.state.memberNo} onChange={this.changeMemberNoHandler}/>
</div>
<button className="btn btn-success" onClick={this.createBoard}>저장</button>
<button className="btn btn-danger" onClick={this.cancel.blind(this)} style={{marginLeft:"10px"}}>취소</button>
</form>
</div>
</div>
</div>
</div>
</div>
);
}
}
export default CreateBoardComponent;