diff --git a/.eslintrc b/.eslintrc index 445e9e6..70bb7f9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,14 +1,40 @@ { - "extends": ["airbnb", "prettier"], - "plugins": ["prettier"], + "env": { + "browser": true, + "es6": true, + "commonjs": true, + "node": true + }, + "extends": ["airbnb", "prettier", "prettier/react"], + "plugins": ["prettier", "react", "jsx-a11y"], "rules": { "prettier/prettier": ["error"], "comma-spacing": ["error", { "before": false, "after": true }], - "indent": ["error", 2], - "linebreak-style": ["error", "unix"], "func-names": "off", "prefer-arrow-callback":"off", "no-use-before-define": "off", - "max-len": [2, 80, 4, {"ignoreUrls": true}] - } + "max-len": [2, 80, 4, {"ignoreUrls": true, "ignoreComments": true, "ignorePattern": "^import\\s.+\\sfrom\\s.+;$", "ignoreStrings": true, "ignoreTemplateLiterals" : true}], + "quotes": [2, "double"], + "import/no-named-as-default": 0, + "import/no-named-as-default-member": 0, + "import/prefer-default-export": 0, + "import/no-extraneous-dependencies": 0, + "consistent-return": "off", + "no-nested-ternary":"off", + "no-param-reassign":"off" , + "no-shadow":"off", + "no-restricted-syntax":"off", + "no-prototype-builtins": "off", + "no-underscore-dangle":"off", + "react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }], + "react/require-default-props": 0, + "react/forbid-prop-types": 0, + "react/prefer-stateless-function": 0, + "react/jsx-one-expression-per-line": 0, + "react/destructuring-assignment" : 0, + "jsx-a11y/label-has-for": "off", + "jsx-a11y/label-has-associated-control": "off", + "prefer-template":"off" + }, + "parser": "babel-eslint" } \ No newline at end of file diff --git a/package.json b/package.json index 02e9c34..4173d10 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "babel-preset-react-app": "^7.0.0", "case-sensitive-paths-webpack-plugin": "2.1.1", "chalk": "1.1.3", + "cross-fetch": "^3.0.1", "css-loader": "0.28.7", "dotenv": "4.0.0", "extract-text-webpack-plugin": "3.0.2", diff --git a/src/modules/app/components/App.js b/src/modules/app/components/App.js index d5d528f..f283cd1 100644 --- a/src/modules/app/components/App.js +++ b/src/modules/app/components/App.js @@ -1,10 +1,10 @@ import React, { Component } from "react"; import PropTypes from "prop-types"; import { connect } from "react-redux"; -import userContext from "../../userContext"; import { Route, Link } from "react-router-dom"; import { ConnectedRouter } from "react-router-redux"; import { OnUpdate } from "rrc"; +import userContext from "../../userContext"; import home from "../../../screens/home"; import signin from "../../../screens/sign-in"; import protectedRoute from "../../../screens/protected"; diff --git a/src/modules/busyIndicator/components/BusyIndicator.js b/src/modules/busyIndicator/components/BusyIndicator.js index d852f5c..a54acc9 100644 --- a/src/modules/busyIndicator/components/BusyIndicator.js +++ b/src/modules/busyIndicator/components/BusyIndicator.js @@ -2,8 +2,8 @@ import React from "react"; import Indicator from "./indicator.svg"; import "./busyIndicator.css"; -const BusyIndicator = () => { - return Busy indicator; -}; +const BusyIndicator = () => ( + Busy indicator +); export default BusyIndicator; diff --git a/src/modules/doAsync/doAsyncLogic.js b/src/modules/doAsync/doAsyncLogic.js index a2f5fcb..023deb0 100644 --- a/src/modules/doAsync/doAsyncLogic.js +++ b/src/modules/doAsync/doAsyncLogic.js @@ -42,7 +42,7 @@ export function handleError( logError(dispatch, actionType, httpMethod, url, httpConfig, { exception, errorMessage: `${errorMessage}. - An error occurred when trying to dispatch results of ajax call to Redux.` + An error occurred when trying to dispatch results of ajax call to Redux.` }); } diff --git a/src/modules/http/http.js b/src/modules/http/http.js index b350ebf..e1c2c16 100644 --- a/src/modules/http/http.js +++ b/src/modules/http/http.js @@ -3,12 +3,14 @@ import localStorage from "localStorage"; import { API_URL } from "./http.constants"; // import { getJwtToken } from "../../modules/userContext/userContext.selectors"; // import { getState } from "../store"; -import * as actionTypes from "../userContext/userContext.actionTypes"; +// import * as actionTypes from "../userContext/userContext.actionTypes"; export default { get, post, - put + put, + patch, + delete: callDelete }; const ASYNC_DELAY = 1000; @@ -87,7 +89,7 @@ function doFetch(url, config, { stubSuccess, stubError } = {}) { const authHeader = response.headers.get("Authorization"); setJwtTokenFromHeaderResponse(authHeader); - updateSessionToken(parseJwtTokenFromHeader(authHeader)); + // updateSessionToken(parseJwtTokenFromHeader(authHeader)); } if (response.ok) { @@ -150,10 +152,10 @@ function parseJwtTokenFromHeader(authorizationHeader) { return tokens.length > 1 ? tokens[1] : null; } -const updateSessionToken = token => dispatch => { - // TODO: Do we need this? - // dispatch({ - // type: actionTypes.JWT_TOKEN_ASYNC.RECEIVED, - // payload: token - // }); -}; +// const updateSessionToken = token => dispatch => { +// TODO: Do we need this? +// dispatch({ +// type: actionTypes.JWT_TOKEN_ASYNC.RECEIVED, +// payload: token +// }); +// }; diff --git a/src/modules/notificationPopup/notificationPopup.actions.js b/src/modules/notificationPopup/notificationPopup.actions.js index ce5220c..89cdf3d 100644 --- a/src/modules/notificationPopup/notificationPopup.actions.js +++ b/src/modules/notificationPopup/notificationPopup.actions.js @@ -1,43 +1,41 @@ -import { NOTIFY_SUCCESS, RESET } from "./notificationPopup.actionTypes"; - -// We are using let so that we can assign fakes in tests. Might be a better way to do this :P -export let handleError = ( - type, - { errorMessage, message, stack, componentStack } -) => { - if (!type) { - throw new Error( - "You must specify a type argument which is a redux action type to be used with your error" - ); - } - - console.log(`${errorMessage}:${message}:${stack} - ${componentStack ? `componentStack: ` + componentStack : ""} - `); - - return { - type, - payload: { - errorMessage, - message, - stack - } - }; -}; - -export const notifySuccess = (successMessage, { title, config } = {}) => { - return { - type: NOTIFY_SUCCESS, - payload: { - successMessage, - config: { - ...config, - title - } - } - }; -}; - -export const resetError = () => ({ - type: RESET -}); +import { NOTIFY_SUCCESS, RESET } from "./notificationPopup.actionTypes"; + +// We are using let so that we can assign fakes in tests. Might be a better way to do this :P +export const handleError = ( + type, + { errorMessage, message, stack, componentStack } +) => { + if (!type) { + throw new Error( + "You must specify a type argument which is a redux action type to be used with your error" + ); + } + + console.log(`${errorMessage}:${message}:${stack} + ${componentStack ? "componentStack: " + componentStack : ""} + `); + + return { + type, + payload: { + errorMessage, + message, + stack + } + }; +}; + +export const notifySuccess = (successMessage, { title, config } = {}) => ({ + type: NOTIFY_SUCCESS, + payload: { + successMessage, + config: { + ...config, + title + } + } +}); + +export const resetError = () => ({ + type: RESET +}); diff --git a/src/modules/pendingRequest/index.js b/src/modules/pendingRequest/index.js index 36fb874..f0c7bef 100644 --- a/src/modules/pendingRequest/index.js +++ b/src/modules/pendingRequest/index.js @@ -1,11 +1,11 @@ -import * as constants from "./pendingRequest.constants"; -import reducer from "./pendingRequest.reducer"; -import * as selectors from "./pendingRequest.selectors"; -import * as actions from "./pendingRequest.actions"; - -export default { - actions, - constants, - reducer, - selectors -}; +import * as constants from "./pendingRequest.constants"; +import reducer from "./pendingRequest.reducer"; +import * as selectors from "./pendingRequest.selectors"; +import * as actions from "./pendingRequest.actions"; + +export default { + actions, + constants, + reducer, + selectors +}; diff --git a/src/modules/pendingRequest/pendingRequest.actionTypes.js b/src/modules/pendingRequest/pendingRequest.actionTypes.js index adb7f41..a1168eb 100644 --- a/src/modules/pendingRequest/pendingRequest.actionTypes.js +++ b/src/modules/pendingRequest/pendingRequest.actionTypes.js @@ -1,12 +1,12 @@ -import { buildActionType } from "../utilities/reduxUtilities"; - -export const CANCEL = buildActionType("pendingRequest", "CANCEL"); - -export const ADD = buildActionType("pendingRequest", "ADD"); - -export const DELETE = buildActionType("pendingRequest", "DELETE"); - -export const SET_BUSY_SPINNER = buildActionType( - "pendingRequest", - "SET_BUSY_SPINNER" -); +import { buildActionType } from "../utilities/reduxUtilities"; + +export const CANCEL = buildActionType("pendingRequest", "CANCEL"); + +export const ADD = buildActionType("pendingRequest", "ADD"); + +export const DELETE = buildActionType("pendingRequest", "DELETE"); + +export const SET_BUSY_SPINNER = buildActionType( + "pendingRequest", + "SET_BUSY_SPINNER" +); diff --git a/src/modules/pendingRequest/pendingRequest.actions.js b/src/modules/pendingRequest/pendingRequest.actions.js index 4a27b80..85e6ec8 100644 --- a/src/modules/pendingRequest/pendingRequest.actions.js +++ b/src/modules/pendingRequest/pendingRequest.actions.js @@ -1,31 +1,31 @@ -import { - CANCEL, - ADD, - DELETE, - SET_BUSY_SPINNER -} from "./pendingRequest.actionTypes"; - -export const cancelPendingRequest = () => ({ - type: CANCEL -}); - -export const addPendingRequest = requestedActionType => ({ - type: ADD, - payload: { - requestedActionType - } -}); - -export const setBusySpinner = (requestedActionType, turnSpinnerOff) => ({ - type: SET_BUSY_SPINNER, - payload: { - requestedActionType, - turnSpinnerOff - } -}); -export const deletePendingRequest = requestedActionType => ({ - type: DELETE, - payload: { - requestedActionType - } -}); +import { + CANCEL, + ADD, + DELETE, + SET_BUSY_SPINNER +} from "./pendingRequest.actionTypes"; + +export const cancelPendingRequest = () => ({ + type: CANCEL +}); + +export const addPendingRequest = requestedActionType => ({ + type: ADD, + payload: { + requestedActionType + } +}); + +export const setBusySpinner = (requestedActionType, turnSpinnerOff) => ({ + type: SET_BUSY_SPINNER, + payload: { + requestedActionType, + turnSpinnerOff + } +}); +export const deletePendingRequest = requestedActionType => ({ + type: DELETE, + payload: { + requestedActionType + } +}); diff --git a/src/modules/pendingRequest/pendingRequest.reducer.js b/src/modules/pendingRequest/pendingRequest.reducer.js index a60e9cf..fa8e544 100644 --- a/src/modules/pendingRequest/pendingRequest.reducer.js +++ b/src/modules/pendingRequest/pendingRequest.reducer.js @@ -1,64 +1,64 @@ -import * as types from "./pendingRequest.actionTypes"; - -const intialState = {}; - -export default function reducer(state = intialState, action) { - switch (action.type) { - case types.ADD: { - const newState = { - ...state - }; - - newState[action.payload.requestedActionType] = { - turnSpinnerOff: false - }; - - return newState; - } - - case types.CANCEL: { - const newState = { - ...state - }; - - for (const name in newState) { - if (newState.hasOwnProperty(name)) { - newState[name] = { - ...newState[name], - cancelled: true - }; - } - } - - return newState; - } - - case types.DELETE: { - const newState = { - ...state - }; - - delete newState[action.payload.requestedActionType]; - - return newState; - } - - case types.SET_BUSY_SPINNER: { - const { turnSpinnerOff } = action.payload; - const newState = { - ...state - }; - - newState[action.payload.requestedActionType] = { - ...newState[action.payload.requestedActionType], - turnSpinnerOff - }; - - return newState; - } - - default: { - return state; - } - } -} +import * as types from "./pendingRequest.actionTypes"; + +const intialState = {}; + +export default function reducer(state = intialState, action) { + switch (action.type) { + case types.ADD: { + const newState = { + ...state + }; + + newState[action.payload.requestedActionType] = { + turnSpinnerOff: false + }; + + return newState; + } + + case types.CANCEL: { + const newState = { + ...state + }; + + for (const name in newState) { + if (newState.hasOwnProperty(name)) { + newState[name] = { + ...newState[name], + cancelled: true + }; + } + } + + return newState; + } + + case types.DELETE: { + const newState = { + ...state + }; + + delete newState[action.payload.requestedActionType]; + + return newState; + } + + case types.SET_BUSY_SPINNER: { + const { turnSpinnerOff } = action.payload; + const newState = { + ...state + }; + + newState[action.payload.requestedActionType] = { + ...newState[action.payload.requestedActionType], + turnSpinnerOff + }; + + return newState; + } + + default: { + return state; + } + } +} diff --git a/src/modules/pendingRequest/pendingRequest.selectors.js b/src/modules/pendingRequest/pendingRequest.selectors.js index d94bebd..f44074b 100644 --- a/src/modules/pendingRequest/pendingRequest.selectors.js +++ b/src/modules/pendingRequest/pendingRequest.selectors.js @@ -1,4 +1,4 @@ -import { STATE_NAME } from "./pendingRequest.constants"; - -export const getPendingRequest = (state, requestedActionType) => - state[STATE_NAME][requestedActionType]; +import { STATE_NAME } from "./pendingRequest.constants"; + +export const getPendingRequest = (state, requestedActionType) => + state[STATE_NAME][requestedActionType]; diff --git a/src/modules/rootReducer.js b/src/modules/rootReducer.js index 8536006..2e91d1c 100644 --- a/src/modules/rootReducer.js +++ b/src/modules/rootReducer.js @@ -1,9 +1,9 @@ import { combineReducers } from "redux"; import { reducer as formReducer } from "redux-form"; +import { routerReducer } from "react-router-redux"; import userContext from "./userContext"; import error from "./error"; import busyIndicator from "./busyIndicator"; -import { routerReducer } from "react-router-redux"; export default combineReducers({ [userContext.constants.STATE_NAME]: userContext.reducer, diff --git a/src/modules/store.js b/src/modules/store.js index 98e80f0..6732cab 100644 --- a/src/modules/store.js +++ b/src/modules/store.js @@ -6,6 +6,8 @@ import { import { routerMiddleware } from "react-router-redux"; import thunk from "redux-thunk"; +const reduxImmutableStateInvariant = require("redux-immutable-state-invariant").default(); + let store; export const createStore = (rootReducer, history, initialState) => { @@ -20,7 +22,7 @@ export const createStore = (rootReducer, history, initialState) => { const middleware = [routerMiddlewareWithHistory, thunk]; if (process.env.NODE_ENV !== "production") { - middleware.push(require("redux-immutable-state-invariant").default()); + middleware.push(reduxImmutableStateInvariant); } const enhancer = composeEnhancers( @@ -33,12 +35,12 @@ export const createStore = (rootReducer, history, initialState) => { return store; }; -// Allows access to store.dispatch outside of connected components (e.g. action creators) -export const dispatch = () => { - store.dispatch(arguments); +// Allows access to store.dispatch outside of connected components (e.g. action creators) +export const dispatch = args => { + store.dispatch(args); }; // Allows access to store.dispatch outside of connected components (e.g. action creators) -export const getState = () => { - store.getState(arguments); +export const getState = args => { + store.getState(args); }; diff --git a/src/modules/userContext/components/WithRestrictedAccess.js b/src/modules/userContext/components/WithRestrictedAccess.js index 00cfd97..dbfaf1a 100644 --- a/src/modules/userContext/components/WithRestrictedAccess.js +++ b/src/modules/userContext/components/WithRestrictedAccess.js @@ -31,7 +31,7 @@ const WithRestrictedAccess = (WrappedComponent, requiredPermissions = []) => { }} /> ) : ( -
You don't have the required permissions for this page.
+
You {"don't"} have the required permissions for this page.
)} ); diff --git a/src/modules/userContext/userContext.actions.js b/src/modules/userContext/userContext.actions.js index 36941c2..10ba851 100644 --- a/src/modules/userContext/userContext.actions.js +++ b/src/modules/userContext/userContext.actions.js @@ -1,4 +1,4 @@ -import http, { constants } from "../http"; +import { constants } from "../http"; import * as actionTypes from "./userContext.actionTypes"; import doAsync from "../doAsync"; diff --git a/src/screens/home/components/HomeContainer.js b/src/screens/home/components/HomeContainer.js index dcd238f..1fabf86 100644 --- a/src/screens/home/components/HomeContainer.js +++ b/src/screens/home/components/HomeContainer.js @@ -15,8 +15,8 @@ class HomeContainer extends Component {

Welcome Guest

- You can login as ryan@vicesoftware.com with 'password' for your - password. + You can login as ryan@vicesoftware.com with {"'password'"} for + your password.

) : ( diff --git a/src/screens/sign-in/components/SignInContainer.js b/src/screens/sign-in/components/SignInContainer.js index f550d12..44141fa 100644 --- a/src/screens/sign-in/components/SignInContainer.js +++ b/src/screens/sign-in/components/SignInContainer.js @@ -33,7 +33,7 @@ class LoginContainer extends React.Component { } LoginContainer.propTypes = { - signInFormValues: PropTypes.object.isRequired, + // signInFormValues: PropTypes.object.isRequired, isAuthenticated: PropTypes.bool.isRequired, location: PropTypes.object.isRequired, signIn: PropTypes.func.isRequired