Skip to content

State (Actions)

Shawn DelPercio edited this page May 28, 2020 · 4 revisions

Actions

Index.js

A file to import all action creators from authActions.js, reviewActions.js, companyActions.js, and userActions.js and export them so that you dont need to look through all four files to find correct action creator.

AuthActions.js

Actions for authenticating a user, includes the 'login' and 'signup' action creators.

The 'login' action creator dispatches the 'LOGIN_START' action, then makes a POST request to '/auth/login'. If successful, stores some information in local storage, and sends 'LOGIN_SUCCESS' action to store user info into state. If the request fails, sends 'LOGIN_FAIL' action to store status and description of error.

The 'signup' action creator dispatches the 'SIGNUP_START' action, then makes a POST request to '/auth/register'. If successful, stores some information in local storage, and sends 'SIGNUP_SUCCESS' action to store user info into state. If the request fails, sends 'SIGNUP_FAIL' action to store status and description of error.

reviewActions.js

Actions for CRUD operations with reviews, includes the 'getReview', 'getReviewById', 'postReview', 'editReview', and 'deleteReview' action creators.

The 'getReview' action creator dispatches the 'FETCH_REVIEWS_START', 'FETCH_REVIEWS_SUCCESS', and 'FETCH_REVIEWS_FAILURE' actions on start, success, and failure. Makes a GET request to the '/reviews' endpoint to get an array of all reviews.

The 'getReviewById' action creator dispatches the 'FETCH_REVIEW_BY_ID_START', 'FETCH_REVIEW_BY_ID_SUCCESS', and 'FETCH_REVIEW_BY_ID_FAILURE' actions on start, success, and failure. Makes a GET request to the '/reviews/:id' endpoint to get a single review.

The 'postReview' action creator dispatches 'POST_REVIEW_START', 'POST_REVIEWS_SUCCESS', and 'POST_REVIEWS_FAILURE' actions on start, success, and failure. Makes a POST request to the '/users/:id/add-review' endpoint to create a new review.

The 'editReview' action creator dispatches 'EDIT_REVIEW_START', 'EDIT_REVIEWS_SUCCESS', and 'EDIT_REVIEWS_FAILURE' actions on start, success, and failure. Makes a PUT request to the '/users/:userID/reviews/:reviewID' endpoint to update a single review.

The 'deleteReview' action creator dispatches 'DELETE_REVIEW_START', 'DELETE_REVIEWS_SUCCESS', and 'DELETE_REVIEWS_FAILURE' actions on start, success, and failure. Makes a DELETE request to the '/users/:userID/reviews/:reviewID' endpoint to delete a single review.

reviewActions.js

Actions for CRUD operations with companies, includes the 'getCompanies', 'postCompany' action creators.

The 'getCompanies' action creator dispatches 'FETCH_COMPANIES_START', 'FETCH_COMPANIES_SUCCESS', and 'FETCH_COMPANIES_FAILURE' actions on start, success, and failure. Makes a GET request to the '/companies' endpoint to get an array of all companies.

The 'postCompany' action creator dispatches 'POST_COMPANY_START', 'POST_COMPANY_SUCCESS', and 'POST_COMPANY_FAILURE' actions on start, success, and failure. Makes a POST request to the '/companies' endpoint to create a new company.

userActions.js

Actions for CRUD operations with users, includes the 'getUser', 'updateUser', 'blockUser' action creators.

The 'getUser' action creator dispatches 'FETCH_USER_START', 'FETCH_USER_SUCCESS', and 'FETCH_USER_FAILURE' actions on start, success, and failure. Makes a GET request to the '/users/:id' endpoint to get information for a single user.

The 'updateUser' action creator dispatches 'EDIT_USER_START', 'EDIT_USER_SUCCESS', and 'EDIT_USER_FAILURE' actions on start, success, and failure. Makes a PUT request to the '/users/:id' endpoint to update information for a single user.

The 'blockUser' action creator dispatches 'BLOCK_USER_START', 'BLOCK_USER_SUCCESS', and 'BLOCK_USER_FAILURE' actions on start, success, and failure. Makes a PUT request to the '/users/:id' endpoint to toggle the 'blocked' status for a user.