Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import * as actionType from './action_types/userActionTypes';
- import { BidiiBuild as bidii } from './../api/BidiiBuildConfig';
- // Common JS Style
- let Auth = require('j-toker');
- let AuthConfig = require('./../api/JtokerConfig');
- /**
- * PLAIN JAVASCRIPT ACTIONS
- * @param bool
- * @returns {{type, payload: *}}
- */
- export function accountSignInLoading(bool) {
- return {
- type: actionType.ACCOUNT_SIGN_IN_LOADING,
- payload: bool
- }
- }
- export function accountSignInSuccess(bool) {
- return {
- type: actionType.ACCOUNT_SIGN_IN_SUCCESS,
- payload: bool
- }
- }
- export function accountSetUserProfile(user) {
- return {
- type: actionType.ACCOUNT_SET_USER_PROFILE,
- payload: user
- }
- }
- export function accountSignInFail(bool) {
- return {
- type: actionType.ACCOUNT_SIGN_IN_FAIL,
- payload: bool
- }
- }
- export function accountSignInErrors(error) {
- return {
- type: actionType.ACCOUNT_SIGN_IN_ERRORS,
- payload: error
- }
- }
- /**
- * ACTION CREATORS WITH REDUX THUNK
- * @param values
- * @returns {function(*)}
- */
- export function userSignOut() {
- return (dispatch) => {
- const response = Auth.signOut();
- response
- .then(() => {
- dispatch(accountSignInSuccess(false));
- window.location.href = bidii.loginPath;
- })
- .fail((error) => {
- alert('Please try again later...')
- })
- }
- }
- export function emailSignIn(values) {
- return (dispatch) => {
- const response = Auth.emailSignIn(values);
- dispatch(accountSignInLoading(true));
- response.then((data) => {
- dispatch(accountSignInLoading(false));
- dispatch(accountSignInSuccess(true));
- dispatch(accountSetUserProfile(data));
- }).fail((error) => {
- dispatch(accountSignInLoading(false));
- dispatch(accountSignInFail(true));
- dispatch(accountSignInErrors(error));
- })
- }
- }
- export function accountValidateToken() {
- return (dispatch) => {
- const response = Auth.validateToken();
- response.then((user) => {
- dispatch(accountSignInSuccess(true));
- dispatch(accountSetUserProfile(user));
- }).fail(() => {
- dispatch(accountSignInSuccess(false));
- })
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement