Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. import * as actionType from './action_types/userActionTypes';
  2. import { BidiiBuild as bidii } from './../api/BidiiBuildConfig';
  3.  
  4. // Common JS Style
  5. let Auth = require('j-toker');
  6. let AuthConfig = require('./../api/JtokerConfig');
  7.  
  8.  
  9. /**
  10. * PLAIN JAVASCRIPT ACTIONS
  11. * @param bool
  12. * @returns {{type, payload: *}}
  13. */
  14.  
  15. export function accountSignInLoading(bool) {
  16. return {
  17. type: actionType.ACCOUNT_SIGN_IN_LOADING,
  18. payload: bool
  19. }
  20. }
  21.  
  22. export function accountSignInSuccess(bool) {
  23. return {
  24. type: actionType.ACCOUNT_SIGN_IN_SUCCESS,
  25. payload: bool
  26. }
  27. }
  28.  
  29. export function accountSetUserProfile(user) {
  30. return {
  31. type: actionType.ACCOUNT_SET_USER_PROFILE,
  32. payload: user
  33. }
  34. }
  35.  
  36. export function accountSignInFail(bool) {
  37. return {
  38. type: actionType.ACCOUNT_SIGN_IN_FAIL,
  39. payload: bool
  40. }
  41. }
  42.  
  43. export function accountSignInErrors(error) {
  44. return {
  45. type: actionType.ACCOUNT_SIGN_IN_ERRORS,
  46. payload: error
  47. }
  48. }
  49.  
  50.  
  51. /**
  52. * ACTION CREATORS WITH REDUX THUNK
  53. * @param values
  54. * @returns {function(*)}
  55. */
  56.  
  57. export function userSignOut() {
  58. return (dispatch) => {
  59. const response = Auth.signOut();
  60. response
  61. .then(() => {
  62. dispatch(accountSignInSuccess(false));
  63. window.location.href = bidii.loginPath;
  64. })
  65. .fail((error) => {
  66. alert('Please try again later...')
  67. })
  68. }
  69.  
  70. }
  71.  
  72. export function emailSignIn(values) {
  73. return (dispatch) => {
  74. const response = Auth.emailSignIn(values);
  75. dispatch(accountSignInLoading(true));
  76. response.then((data) => {
  77. dispatch(accountSignInLoading(false));
  78. dispatch(accountSignInSuccess(true));
  79. dispatch(accountSetUserProfile(data));
  80. }).fail((error) => {
  81. dispatch(accountSignInLoading(false));
  82. dispatch(accountSignInFail(true));
  83. dispatch(accountSignInErrors(error));
  84. })
  85. }
  86. }
  87.  
  88.  
  89.  
  90. export function accountValidateToken() {
  91. return (dispatch) => {
  92. const response = Auth.validateToken();
  93. response.then((user) => {
  94. dispatch(accountSignInSuccess(true));
  95. dispatch(accountSetUserProfile(user));
  96. }).fail(() => {
  97. dispatch(accountSignInSuccess(false));
  98. })
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement