@@ -7,16 +9,108 @@ class CreatePost extends Component {
...
@@ -7,16 +9,108 @@ class CreatePost extends Component {
super(pros)
super(pros)
this.state={
this.state={
title:'',
content:'',
image:'',
courses:[],
course:'',
}
}
}
}
changeHandler=(e)=>{
conststate=this.state
state[e.target.name]=e.target.value;
this.setState(state)
}
userTypeHandler=(e)=>{
conststate=this.state
state[e.target.name]=e.target.value;
this.setState(state)
}
componentDidMount(){
axios.get(constant()+'/courses').then(
data=>{
this.setState({
courses:data.data,
course:data.data[0].id//get first object id from courses list and set status to defult course
})
}
).catch(error=>{
console.log(error)
})
}
submitHandler=(e)=>{
e.preventDefault()
console.log(this.state)
axios.post(constant()+'/save/post',this.state)
.then(response=>{
console.log(response)
if(response.data!==''){
alert(`Post added successfully`);
this.props.history.push("/createpost")
}
})
.catch(error=>{
console.log(error)
})
}
SubmitButtonHandler=()=>{
this.props.history.push("/createpost")
}
render(){
render(){
return(
const{title,image,content,course}=this.state;
return(
<divclassName="container">
<divclassName="container">
<h2>NewPostPage</h2>
<divclassName="panel panel-default">
<divclassName="panel-heading">
<h3className="panel-title">
CreateNewPost
</h3>
</div>
<divclassName="panel-body">
<formonSubmit={this.submitHandler}>
<divclassName="form-group">
<label>Title:</label>
<inputtype='text'id="title"className="form-control"name="title"value={title}onChange={this.changeHandler}placeholder="Title"pattern="^[a-zA-Z0-9_]+$"title="Title is required"/>