-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature(create articles): users can post articles
- Enable users to post an article [Delivers #160609518]
- Loading branch information
1 parent
6ce122c
commit 80dc0a5
Showing
29 changed files
with
486 additions
and
13,642 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.ql-container.ql-snow { | ||
border: none!important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { toast } from 'react-toastify'; | ||
import { axiosInstance } from '../config/axiosInstance'; | ||
import { createArticle } from './actionCreators'; | ||
|
||
export const postArticle = (postData) => dispatch => { | ||
toast.dismiss(); | ||
axiosInstance | ||
.post('/api/articles/', postData) | ||
.then(response => { | ||
dispatch(createArticle(true)); | ||
toast.success( | ||
response.statusText, | ||
{ autoClose: 3500, hideProgressBar: true }, | ||
{ | ||
position: toast.POSITION.TOP_CENTER, | ||
}, | ||
); | ||
}); | ||
}; | ||
export default postArticle; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
import React, { Component } from 'react'; | ||
import { connect } from 'react-redux'; | ||
import PropTypes from 'prop-types'; | ||
import ReactQuill from 'react-quill'; | ||
import 'react-quill/dist/quill.snow.css'; | ||
import { postArticle } from '../../actions/articleActions'; | ||
|
||
export class NewArticle extends Component { | ||
editorModules = { | ||
toolbar: [ | ||
[{ header: [1, 2, 3, 4, false] }], | ||
['bold', 'italic', 'underline', 'strike', 'blockquote'], | ||
[{ size: ['14px', '16px', '18px'] }], | ||
[{ list: 'ordered' }, { list: 'bullet' }, { indent: '-1' }, { indent: '+1' }], | ||
['link', 'image'], | ||
['clean'], | ||
], | ||
}; | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
title: '', | ||
description: '', | ||
body: '', | ||
}; | ||
} | ||
|
||
componentWillReceiveProps(nextProps) { | ||
if (nextProps.createArticleSuccess === true) { | ||
const { history } = this.props; | ||
history.push('/'); | ||
} | ||
} | ||
|
||
handleSubmit = event => { | ||
event.preventDefault(); | ||
const { title, description, body } = this.state; | ||
const payload = { | ||
article: { | ||
title, | ||
description, | ||
body, | ||
}, | ||
}; | ||
const { addArticle } = this.props; | ||
addArticle(payload); | ||
} | ||
|
||
resetForm = () => { | ||
this.setState({ | ||
title: '', | ||
description: '', | ||
body: '', | ||
}); | ||
}; | ||
|
||
handleChange = event => { | ||
const { name, value } = event.target; | ||
this.setState({ [name]: value }); | ||
} | ||
|
||
handleEditorChange = (value) => { | ||
this.setState({ body: value }); | ||
} | ||
|
||
render() { | ||
const { title, description, body } = this.state; | ||
return ( | ||
<div className="container" style={{ paddingTop: '50px' }}> | ||
<div className="row"> | ||
<div className="col-12"> | ||
<form id="add-article-form" onSubmit={this.handleSubmit}> | ||
<div className="container col-sm-12 col-md-8"> | ||
<div className="form-group mt-2"> | ||
<div className="input-group mb-2"> | ||
<input type="text" name="title" className="clear-box very-big-font" placeholder="Title" id="title" value={title} onChange={this.handleChange} required /> | ||
</div> | ||
</div> | ||
<div className="form-group"> | ||
<div className="input-group mb-2"> | ||
<input type="text" name="description" className="clear-box bigger-font" placeholder="Description" id="description" value={description} onChange={this.handleChange} required /> | ||
</div> | ||
</div> | ||
<div className="form-group"> | ||
<div className="text-editor"> | ||
<div> | ||
<ReactQuill | ||
id="text-editor" | ||
modules={this.editorModules} | ||
theme="snow" | ||
className="quill-height" | ||
value={body} | ||
onChange={this.handleEditorChange} | ||
required | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="mt-5"> | ||
<button type="submit" className="btn btn-primary m-r-10">Save</button> | ||
<button type="button" id="clear-button" className="btn btn-outline-warning m-r-10" onClick={this.resetForm}>Clear</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
NewArticle.propTypes = { | ||
addArticle: PropTypes.func.isRequired, | ||
history: PropTypes.object.isRequired, | ||
createArticleSuccess: PropTypes.bool.isRequired, | ||
}; | ||
|
||
|
||
const mapStateToProps = (state) => ({ | ||
articlesPayload: state.article.articlesPayload, | ||
createArticleSuccess: state.article.createArticleSuccess, | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
{ addArticle: postArticle }, | ||
)(NewArticle); |
Empty file.
Empty file.
Oops, something went wrong.