-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(articlePage): serve comment on article functionality
- ensure only logged in users can enter and post comments - ensure users can post comments on an article [Finishes #161290969]
- Loading branch information
1 parent
a0e41e2
commit 70d4b3d
Showing
11 changed files
with
316 additions
and
109 deletions.
There are no files selected for viewing
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
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,36 @@ | ||
import { toastr } from 'react-redux-toastr'; | ||
import { globalLoading, globalFailure } from './globalActions'; | ||
import fetchArticle from './singleArticleActions'; | ||
import requestOptions from '../utils/requestOptions'; | ||
import getToken from '../utils/getToken'; | ||
|
||
export const postComment = (articleId, body) => (dispatch) => { | ||
dispatch(globalLoading(true)); | ||
const commentBody = { | ||
body | ||
}; | ||
return fetch(`${process.env.API_BASE_URL}/articles/${articleId}/comments`, | ||
requestOptions(commentBody, 'POST', getToken())) | ||
.then( | ||
res => res.json(), | ||
error => dispatch(globalFailure(error)) | ||
) | ||
.then((commentResponse) => { | ||
if (commentResponse.status === 'success') { | ||
// successfully posted article | ||
toastr.success(commentResponse.message); | ||
dispatch(fetchArticle(articleId)); | ||
} | ||
if (commentResponse.status === 'unauthorized') { | ||
// no token provided or invalid token | ||
toastr.error(commentResponse.message); | ||
} | ||
if (commentResponse.errors) { | ||
// invalid body | ||
toastr.error('Failed to post comment...', commentResponse.errors.body[0]); | ||
} | ||
dispatch(globalLoading(false)); | ||
}); | ||
}; | ||
|
||
export const dummyExport = null; |
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
Empty file.
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
Oops, something went wrong.