Last active
November 2, 2016 16:50
-
-
Save binzailani3136/7dc3e65287163f955968173299be63ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export const changeFilterKind = // eslint-disable-line import/prefer-default-export | |
'CHANGE_FILTER_KIND'; | |
export const createActivity = // eslint-disable-line import/prefer-default-export | |
'CREATE_ACTIVITY'; | |
// Ajax request | |
export const FETCHING_DATA = 'FETCHING_DATA'; | |
// Login | |
export const UPDATE_EMAIL = 'UPDATE_EMAIL'; | |
export const UPDATE_PASSWORD = 'UPDATE_PASSWORD'; | |
export const LOGIN_START = 'LOGIN_START'; | |
export const LOGIN_SUCCESS = 'LOGIN_SUCCESS'; | |
export const LOGIN_ERROR = 'LOGIN_ERROR'; | |
// Create Profile | |
export const UPDATE_PROFILE_IMAGE_URL = 'UPDATE_PROFILE_IMAGE_URL'; | |
export const UPDATE_NAME = 'UPDATE_NAME'; | |
export const UPDATE_PHONE = 'UPDATE_PHONE'; | |
export const UPDATE_COUNTRY = 'UPDATE_COUNTRY'; | |
export const UPDATE_CITY = 'UPDATE_CITY'; | |
export const UPDATE_ZIP = 'UPDATE_ZIP'; | |
export const UPDATE_ADRESS = 'UPDATE_ADRESS'; | |
export const UPDATE_DESCRIPTION = 'UPDATE_DESCRIPTION'; | |
export const UPDATE_LANGUAGES = 'UPDATE_LANGUAGES'; | |
export const UPDATE_SPORTS = 'UPDATE_SPORTS'; | |
export const REMOVE_SPORT = 'REMOVE_SPORT'; | |
export const REMOVE_PAYMENT = 'REMOVE_PAYMENT'; | |
export const REMOVE_PAYOFF = 'REMOVE_PAYOFF'; | |
export const FILTER_SPORTS = 'FILTER_SPORTS'; | |
export const SIGNUP_START = 'SIGNUP_START'; | |
export const SIGNUP_SUCCESS = 'SIGNUP_SUCCESS'; | |
export const SIGNUP_ERROR = 'SIGNUP_ERROR'; |
This file contains hidden or 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 types from './actionNames'; | |
import UserApi from '../dummyData/User'; | |
/** | |
* Triggered when email form text changes | |
*/ | |
export function updateEmail(text) { | |
return { | |
type: types.UPDATE_EMAIL, | |
text | |
}; | |
} | |
/** | |
* Triggered when password form text changes | |
*/ | |
export function updatePassword(text) { | |
return { | |
type: types.UPDATE_PASSWORD, | |
text | |
}; | |
} | |
/** | |
* Triggered when network request is active | |
* Used for activity indicator | |
*/ | |
export function fetchingData() { | |
return { | |
type: types.FETCHING_DATA | |
}; | |
} | |
/** | |
* Triggered when login is succesfull | |
*/ | |
export function loginSuccess(userData) { | |
return { | |
type: types.LOGIN_SUCCESS, | |
userData | |
}; | |
} | |
/** | |
* Triggered when login has failed | |
*/ | |
export function loginError(error) { | |
return { | |
type: types.LOGIN_ERROR, | |
error | |
}; | |
} | |
/** | |
* ASYNC LOGIN | |
* Triggered when login button is pressed | |
*/ | |
export const login = (email, password) => ( | |
(dispatch) => { | |
dispatch(fetchingData(email, password)); | |
// Mocked API request. Needs to be replaced with request to server... | |
return UserApi.authUser().then(userData => { | |
// Handle response here... | |
dispatch(loginSuccess(userData)); | |
}).catch(error => { | |
throw (error); | |
}); | |
} | |
); |
This file contains hidden or 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 { connect } from 'react-redux'; | |
import { bindActionCreators } from 'redux'; | |
import * as authActions from '/src/action/authActions'; | |
import SettingsPage from '/page/SettingsPage'; | |
const stateToProps = (state) => ({ | |
authData: state.Auth, | |
}); | |
const dispatchToProps = (dispatch) => ({ | |
actions: bindActionCreators(authActions, dispatch), | |
}); | |
export default connect( | |
stateToProps, | |
dispatchToProps | |
)(SettingsPage); |
This file contains hidden or 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 types from '../../action/actionNames'; | |
const defaultState = { | |
email: '', | |
password: '', | |
isLoggedIn: false, | |
isFetching: false, | |
userData: {} | |
}; | |
/** | |
* Reducer for handling Auth actions | |
*/ | |
export default function (state = defaultState, action) { | |
switch (action.type) { | |
case types.UPDATE_EMAIL: | |
return { | |
...state, | |
email: action.text | |
}; | |
case types.UPDATE_PASSWORD: | |
return { | |
...state, | |
password: action.text | |
}; | |
case types.FETCHING_DATA: | |
return { | |
...state, | |
isFetching: true | |
}; | |
case types.LOGIN_SUCCESS: | |
return { | |
...state, | |
isLoggedIn: true, | |
isFetching: false, | |
}; | |
default: return state; | |
} | |
} |
This file contains hidden or 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 { createStore, applyMiddleware } from 'redux'; | |
import thunk from 'redux-thunk'; | |
import reducer from '../reducer'; | |
/** | |
* Passing reducers, initial state and middleware to store. | |
*/ | |
function configureStore(initialState) { | |
return createStore( | |
reducer, | |
initialState, | |
applyMiddleware(thunk) | |
); | |
} | |
const store = configureStore(); | |
export default store; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment