|
1 | | -import {getAuthLogin, activateUser} from '../../services/authService'; |
| 1 | +import {getAuthLogin} from '../../services/authService'; |
2 | 2 | import {Cookies} from 'react-cookie'; |
3 | 3 | import * as authActionTypes from './authActionTypes'; |
4 | 4 |
|
@@ -49,47 +49,5 @@ export const logoutIfNeeded = () => { |
49 | 49 | export const setToken = payload => ({type: authActionTypes.SET_TOKEN, payload}); |
50 | 50 | export const setIsLoggedIn = payload => ({type: authActionTypes.SET_IS_LOGGED_IN, payload}); |
51 | 51 |
|
52 | | -export const activateIfNeeded = (userId, bearerToken) => { |
53 | | - return (dispatch, getState) => { |
54 | | - if (shouldActivate(getState())) { |
55 | | - return dispatch(activation(userId, bearerToken)); |
56 | | - } |
57 | | - return Promise.resolve(); |
58 | | - }; |
59 | | -}; |
60 | | -const shouldActivate = ({auth: {isLoggingIn, isLoggedIn, isActivating}}) => !isLoggingIn && !isLoggedIn && !isActivating; |
61 | | -const activation = (userId, bearerToken) => { |
62 | | - return (dispatch) => { |
63 | | - dispatch(activationRequest()); |
64 | | - |
65 | | - return activateUser(userId, bearerToken) |
66 | | - .then((response) => { |
67 | | - if (response.status === 204) { |
68 | | - dispatch(activationSuccess('Account activated. You can now log in.')); |
69 | | - |
70 | | - return {success: true}; |
71 | | - } else { |
72 | | - return response.json(); |
73 | | - } |
74 | | - }) |
75 | | - .then((json) => { |
76 | | - if (!json.success) { |
77 | | - throw Error(json.message || 'Something went wrong'); |
78 | | - } |
79 | | - }) |
80 | | - .catch(e => dispatch(activationFailure(e.message))); |
81 | | - }; |
82 | | -}; |
83 | | -const activationRequest = () => ({type: authActionTypes.ACTIVATION_REQUEST}); |
84 | | -const activationSuccess = payload => ({type: authActionTypes.ACTIVATION_SUCCESS, payload}); |
85 | | -const activationFailure = payload => ({type: authActionTypes.ACTIVATION_FAILURE, payload}); |
86 | | - |
87 | | -export const setActivationData = () => { |
88 | | - const {host, hostname, protocol} = location; |
89 | | - return {type: authActionTypes.SET_ACTIVATION_DATA, payload: {host, hostname, protocol}}; |
90 | | -}; |
91 | | - |
92 | 52 | export const setLoginErrorMessage = payload => ({type: authActionTypes.SET_LOGIN_ERROR_MESSAGE, payload}); |
93 | | -export const setActivationErrorMessage = payload => ({type: authActionTypes.SET_ACTIVATION_ERROR_MESSAGE, payload}); |
94 | | -export const setActivationSuccessMessage = payload => ({type: authActionTypes.SET_ACTIVATION_SUCCESS_MESSAGE, payload}); |
95 | 53 | export const toggleLoginPasswordVisibility = () => ({type: authActionTypes.TOGGLE_LOGIN_PASSWORD_VISIBILITY}); |
0 commit comments