This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cookies from 'js-cookie'; | |
import * as ActionTypes from '../constants/actionTypes'; | |
const initialState = { | |
user: { | |
isAuthenticated: typeof Cookies.get('auth__flow__spa__loggedUserObj') !== 'undefined', | |
loggedUserObj: Cookies.getJSON('auth__flow__spa__loggedUserObj'), | |
}, | |
error: null, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ActionTypes from '../constants/actionTypes'; | |
export default function toggleModal(state = { login: false }, action) { | |
switch (action.type) { | |
case ActionTypes.TOGGLE_MODAL_SUCCEEDED: | |
return { login: action.newState }; | |
default: | |
return state; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import access from 'state/access.reducers'; | |
import toggleModal from 'state/modals.reducers'; | |
export default { | |
access, | |
toggleModal, | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { put, takeLatest } from 'redux-saga/effects'; | |
import * as ActionTypes from 'constants/actionTypes'; | |
function* toggleModal(action) { | |
const { newState } = action; | |
if (!newState) { | |
// if login modal is closed, reset error | |
yield put({ type: ActionTypes.LOGIN_FAILED, error: null }); | |
} | |
yield put({ type: ActionTypes.TOGGLE_MODAL_SUCCEEDED, newState }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { put, call, takeLatest } from 'redux-saga/effects'; | |
import Cookies from 'js-cookie'; | |
import * as ActionTypes from 'constants/actionTypes'; | |
import { get, post } from 'utils/api'; | |
import lGet from 'lodash/get'; | |
function* login(action) { | |
const { email, password } = action; | |
try { | |
const response = yield call( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { all, fork } from 'redux-saga/effects'; | |
import { watchGetProfile, watchLogout, watchLogin } from './access.sagas'; | |
import watchToggleModal from './modals.sagas'; | |
export default function* rootSaga() { | |
yield all([ | |
fork(watchGetProfile), | |
fork(watchLogin), | |
fork(watchLogout), | |
fork(watchToggleModal), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ActionTypes from 'constants/actionTypes'; | |
const toggleLogin = newState => ({ | |
type: ActionTypes.TOGGLE_MODAL_REQUESTED, | |
newState, | |
}); | |
export default toggleLogin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as ActionTypes from 'constants/actionTypes'; | |
export const login = (email, password) => ({ | |
type: ActionTypes.LOGIN_REQUESTED, | |
email, | |
password, | |
}); | |
export const logout = () => ({ | |
type: ActionTypes.LOGOUT_REQUESTED, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
onFacebookLogin = () => { | |
const inOneHour = new Date(new Date().getTime() + 60 * 60 * 1000); | |
Cookies.set('lastLocation_before_logging', this.props.location.pathname, { expires: inOneHour }); | |
window.location.href = `${window.location.origin}/auth/facebook`; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import PropTypes from 'prop-types'; | |
import { withRouter } from 'react-router'; | |
import { connect } from 'react-redux'; | |
import Cookies from 'js-cookie'; | |
import get from 'lodash/get'; | |
import includes from 'lodash/includes'; | |
import { login } from 'actions/access.actions'; | |
import toggleLogin from 'actions/modals.actions'; | |
import cn from 'classnames'; |