Skip to content

Commit

Permalink
bug(Error message reporting): Fix bug on displaying error on reportin…
Browse files Browse the repository at this point in the history
…g an article without message

- Users should not be able to report an article without a message
- Load username on loading view an article container

[Finishes #165786018]
  • Loading branch information
Etomovich committed May 3, 2019
1 parent 48beae7 commit b52f4e7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/containers/GetAnArticle.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';
import { ToastContainer } from 'react-toastify';
import AnArticle from '../components/AnArticle';
import Comments from '../components/Comments';
import { fetchAnArticle, fetchArticleComments } from '../store/actions/commentsActions';
Expand All @@ -14,7 +15,12 @@ export class GetAnArticle extends Component {
}

render() {
const { isFetchingArticle, isFetchingComments, errors } = this.props;
const { isFetchingArticle, isFetchingComments, errors, isLoggedIn } = this.props;
let username = false;

if (isLoggedIn && username === false) {
username = localStorage.getItem('username');
}
if (isFetchingArticle) {
return (<div className="article-loading">Loading...</div>);
}
Expand All @@ -29,6 +35,7 @@ export class GetAnArticle extends Component {
return (
<div className="container an-article">
<div className="auth">
<ToastContainer />
<AnArticle data={article} />
<br />
<hr />
Expand All @@ -43,6 +50,7 @@ export class GetAnArticle extends Component {
GetAnArticle.propTypes = {
isFetchingArticle: PropTypes.bool.isRequired,
isFetchingComments: PropTypes.bool.isRequired,
isLoggedIn: PropTypes.func.isRequired,
article: PropTypes.shape({}),
match: PropTypes.shape({}).isRequired,
errors: PropTypes.string,
Expand All @@ -62,6 +70,7 @@ GetAnArticle.defaultProps = {
export const mapStateToProps = state => ({
article: state.getCommentsReducer,
comments: state.getCommentsReducer,
isLoggedIn: state.loginUser.loggedIn,
errors: state.getCommentsReducer.errors,
author: state.getCommentsReducer.author,
isFetchingArticle: state.getCommentsReducer.isFetchingArticle,
Expand Down
1 change: 1 addition & 0 deletions src/store/reducers/alertModalReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function alertModalReducer(state = initialState, action) {
...state,
message: 'The article has been reported succesfully.',
colorClass: 'alert-success',
isDeleteComment: false,
showAlert: true,
});
default:
Expand Down

0 comments on commit b52f4e7

Please sign in to comment.