Skip to content

Commit

Permalink
feat(signup): add user signup functionality (#10)
Browse files Browse the repository at this point in the history
- consume signup endpoint to add register new customers
- write tests for implementation

[Finishes #163051295]
  • Loading branch information
akhilome committed Jan 15, 2019
1 parent a7a6d2c commit a82de7c
Show file tree
Hide file tree
Showing 28 changed files with 906 additions and 95 deletions.
5 changes: 4 additions & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"presets": ["@babel/preset-env", "@babel/preset-react"],
"plugins": ["@babel/plugin-proposal-class-properties"]
"plugins": [
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-runtime"
]
}
194 changes: 149 additions & 45 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"heroku-postbuild": "npm run build",
"dev": "webpack-dev-server --open --config webpack.config.dev.js",
"dev:hot": "npm run dev -- --hot",
"test": "jest --config=jest.config.json",
"test": "jest --config=jest.config.json --env=jsdom",
"test:watch": "npm test -- --watch",
"coverage": "npm run test -- --coverage",
"coveralls": "npm run coverage && cat ./coverage/lcov.info | coveralls"
Expand All @@ -27,7 +27,9 @@
},
"homepage": "https://github.com/akhilome/kiakiafood#readme",
"dependencies": {
"axios": "^0.18.0",
"express": "^4.16.4",
"jwt-decode": "^2.2.0",
"prop-types": "^15.6.2",
"react": "^16.7.0",
"react-dom": "^16.7.0",
Expand All @@ -41,6 +43,7 @@
"@babel/cli": "^7.2.3",
"@babel/core": "^7.2.2",
"@babel/plugin-proposal-class-properties": "^7.2.3",
"@babel/plugin-transform-runtime": "^7.2.0",
"@babel/preset-env": "^7.2.3",
"@babel/preset-react": "^7.0.0",
"babel-core": "^7.0.0-bridge.0",
Expand All @@ -59,6 +62,7 @@
"eslint-plugin-react": "^7.12.3",
"html-webpack-plugin": "^3.2.0",
"jest": "^23.6.0",
"jsdom": "^13.1.0",
"style-loader": "^0.23.1",
"webpack": "^4.28.1",
"webpack-cli": "^3.2.1",
Expand Down
46 changes: 46 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import axios from '../services/axios';
import actionTypes from './types';
import { saveToken, getToken } from '../utils/localStorage';
import jwt from '../utils/jwt';

export const startFetching = () => ({ type: actionTypes.START_FETCHING });
export const stopFetching = (fetchSuccess = true, message = '') => ({
type: actionTypes.STOP_FETCHING,
payload: {
error: !fetchSuccess,
message,
},
});

export const signUpUser = userData => async (dispatch) => {
dispatch(startFetching());
try {
const { status, user } = (await axios.post('/auth/signup', userData)).data;
if (status === 'success') saveToken(user.auth_token);
const { userName: name, userStatus: role } = jwt.decode(user.auth_token);
dispatch({
type: actionTypes.SIGN_UP,
payload: {
name,
role,
},
});
return dispatch(stopFetching());
} catch (error) {
return dispatch(
stopFetching(false, error.response ? error.response.data.message : 'something went wrong'),
);
}
};

export const checkAuthStatus = () => {
try {
const { userName: name, userStatus: role } = jwt.decode(getToken());
return {
type: actionTypes.CHECK_AUTH_STATUS,
payload: { name, role },
};
} catch (error) {
return { type: actionTypes.CHECK_AUTH_STATUS_FAIL };
}
};
Loading

0 comments on commit a82de7c

Please sign in to comment.