Skip to content

Commit

Permalink
feat: add toastr and logger middlewares
Browse files Browse the repository at this point in the history
  • Loading branch information
pyphilia committed Mar 30, 2021
1 parent 1f25242 commit e979494
Show file tree
Hide file tree
Showing 25 changed files with 1,620 additions and 1,042 deletions.
2 changes: 1 addition & 1 deletion .huskyrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"pre-commit": "pretty-quick --staged && yarn lint",
"post-commit": "git status",
"post-merge": "yarn install",
"pre-push": "yarn lint && yarn build"
"pre-push": "yarn lint && yarn build && yarn test:once"
}
}
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"react-dom": "^17.0.1",
"react-i18next": "11.8.5",
"react-redux": "7.2.2",
"react-redux-toastr": "7.6.5",
"react-router": "5.2.0",
"react-router-dom": "5.2.0",
"react-scripts": "4.0.1",
Expand All @@ -40,17 +41,19 @@
},
"scripts": {
"start": "env-cmd -f ./.env.local react-scripts start",
"start:test": "env-cmd -f ./.env.test react-scripts start",
"start:ci": "react-scripts -r @cypress/instrument-cra start",
"build": "react-scripts build",
"test": "env-cmd -f ./.env.test react-scripts test",
"test:once": "env-cmd -f ./.env.test react-scripts test --watchAll=false",
"eject": "react-scripts eject",
"lint": "eslint .",
"prettier:check": "prettier --check src/**/*.js",
"prettier:write": "prettier --write src/**/*.js",
"hooks:uninstall": "node node_modules/husky/husky.js uninstall",
"hooks:install": "node node_modules/husky/husky.js install",
"cypress:open": "cypress open",
"cypress": "env-cmd -f ./.env.test npm-run-all --parallel start cypress:open",
"cypress": "concurrently \"yarn start:test\" \"wait-on http://localhost:3111 && yarn cypress:run\"",
"cypress:run": "env-cmd -f ./.env.test cypress run --headless --browser chrome"
},
"eslintConfig": {
Expand All @@ -76,6 +79,7 @@
"@testing-library/jest-dom": "^5.11.6",
"@testing-library/react": "^11.2.2",
"@testing-library/user-event": "^12.6.0",
"concurrently": "6.0.0",
"cypress": "6.2.1",
"cypress-file-upload": "5.0.2",
"env-cmd": "10.1.0",
Expand All @@ -91,7 +95,8 @@
"prettier": "2.2.1",
"pretty-quick": "3.1.0",
"standard-version": "9.1.0",
"typescript": "4.1.3"
"typescript": "4.1.3",
"wait-on": "5.3.0"
},
"nyc": {
"exclude": [
Expand Down
3 changes: 3 additions & 0 deletions src/actions/file.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// eslint-disable-next-line import/prefer-default-export
export const uploadFileNotification = (payload) => (dispatch) =>
dispatch(payload);
104 changes: 78 additions & 26 deletions src/actions/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@ import {
GET_SHARED_ITEMS_SUCCESS,
FLAG_DELETING_ITEMS,
DELETE_ITEMS_SUCCESS,
GET_OWN_ITEMS_ERROR,
CREATE_ITEM_ERROR,
DELETE_ITEM_ERROR,
DELETE_ITEMS_ERROR,
CLEAR_ITEM_ERROR,
MOVE_ITEM_ERROR,
COPY_ITEM_ERROR,
GET_CHILDREN_ERROR,
EDIT_ITEM_ERROR,
GET_SHARED_ITEMS_ERROR,
SET_ITEM_ERROR,
GET_ITEM_ERROR,
GET_ITEMS_ERROR,
} from '../types/item';
import { getParentsIdsFromPath } from '../utils/item';
import { createFlag } from './utils';
Expand Down Expand Up @@ -58,8 +71,11 @@ export const setItem = (id) => async (dispatch) => {
type: SET_ITEM_SUCCESS,
payload: { item, children: newChildren, parents: newParents },
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: SET_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_SETTING_ITEM, false));
}
Expand All @@ -74,8 +90,11 @@ export const getItem = (id) => async (dispatch) => {
type: GET_ITEM_SUCCESS,
payload: item,
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: GET_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_GETTING_ITEM, false));
}
Expand All @@ -91,8 +110,11 @@ export const getItems = () => async (dispatch) => {
type: GET_ITEMS_SUCCESS,
payload: items,
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: GET_ITEMS_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_GETTING_ITEMS, false));
}
Expand All @@ -107,8 +129,11 @@ export const getOwnItems = () => async (dispatch) => {
type: GET_OWN_ITEMS_SUCCESS,
payload: ownedItems,
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: GET_OWN_ITEMS_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_GETTING_OWN_ITEMS, false));
}
Expand All @@ -126,8 +151,11 @@ export const createItem = (props) => async (dispatch) => {
type: CREATE_ITEM_SUCCESS,
payload: newItem,
});
} catch (e) {
return console.error(e);
} catch (error) {
return dispatch({
type: CREATE_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_CREATING_ITEM, false));
}
Expand All @@ -141,8 +169,11 @@ export const deleteItem = (itemId) => async (dispatch) => {
type: DELETE_ITEM_SUCCESS,
payload: { id: itemId },
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: DELETE_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_DELETING_ITEM, false));
}
Expand All @@ -166,8 +197,11 @@ export const deleteItems = (itemIds) => async (dispatch) => {
payload: itemIds,
});
}
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: DELETE_ITEMS_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_DELETING_ITEMS, false));
}
Expand All @@ -178,8 +212,11 @@ export const clearItem = () => (dispatch) => {
dispatch({
type: CLEAR_ITEM_SUCCESS,
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: CLEAR_ITEM_ERROR,
error,
});
}
};

Expand All @@ -195,8 +232,11 @@ export const moveItem = (payload) => async (dispatch, getState) => {
type: MOVE_ITEM_SUCCESS,
payload,
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: MOVE_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_MOVING_ITEM, false));
}
Expand All @@ -211,8 +251,11 @@ export const copyItem = (payload) => async (dispatch) => {
type: COPY_ITEM_SUCCESS,
payload: { ...payload, item: newItem },
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: COPY_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_COPYING_ITEM, false));
}
Expand All @@ -230,8 +273,11 @@ export const getChildren = (id) => async (dispatch) => {
type: GET_CHILDREN_SUCCESS,
payload: { id, children },
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: GET_CHILDREN_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_GETTING_CHILDREN, false));
}
Expand All @@ -245,8 +291,11 @@ export const editItem = (item) => async (dispatch) => {
type: EDIT_ITEM_SUCCESS,
payload: editedItem,
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: EDIT_ITEM_ERROR,
error,
});
} finally {
dispatch(createFlag(FLAG_EDITING_ITEM, false));
}
Expand Down Expand Up @@ -277,7 +326,10 @@ export const getSharedItems = () => async (dispatch) => {
type: GET_SHARED_ITEMS_SUCCESS,
payload: [...sharedItems, ...childrenItems],
});
} catch (e) {
console.error(e);
} catch (error) {
dispatch({
type: GET_SHARED_ITEMS_ERROR,
error,
});
}
};
15 changes: 12 additions & 3 deletions src/actions/membership.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
import * as Api from '../api/membership';
import { SHARE_ITEM_ERROR, SHARE_ITEM_SUCCESS } from '../types/membership';

// eslint-disable-next-line import/prefer-default-export
export const shareItemWith = async ({ id, email, permission }) => {
export const shareItemWith = ({ id, email, permission }) => async (
dispatch,
) => {
try {
await Api.shareItemWith({ id, email, permission });
} catch (e) {
console.error(e);
dispatch({
type: SHARE_ITEM_SUCCESS,
});
} catch (error) {
dispatch({
type: SHARE_ITEM_ERROR,
error,
});
}
};
Loading

0 comments on commit e979494

Please sign in to comment.