Files
frontend-app-profile/src/data/reducers/PreferencesReducer.js
Adam Butterworth 5deff373ed Pull data down to UI
2019-02-21 13:55:03 -05:00

67 lines
1.3 KiB
JavaScript

import {
FETCH_PREFERENCES,
SAVE_PREFERENCES,
} from '../../actions/preferences';
const initialState = {
fetchPreferencesState: null,
savePreferencesState: null,
};
const profile = (state = initialState, action) => {
switch (action.type) {
case FETCH_PREFERENCES.BEGIN:
return {
...state,
fetchPreferencesState: 'pending',
};
case FETCH_PREFERENCES.SUCCESS:
return {
...state,
fetchPreferencesState: 'complete',
...action.preferences,
};
case FETCH_PREFERENCES.FAILURE:
return {
...state,
fetchPreferencesState: 'error',
};
case FETCH_PREFERENCES.RESET:
return {
...state,
fetchPreferencesState: null,
error: null,
};
case SAVE_PREFERENCES.BEGIN:
return {
...state,
savePreferencesState: 'pending',
};
case SAVE_PREFERENCES.SUCCESS:
return {
...state,
savePreferencesState: 'complete',
...action.preferences,
};
case SAVE_PREFERENCES.FAILURE:
return {
...state,
savePreferencesState: 'error',
};
case SAVE_PREFERENCES.RESET:
return {
...state,
savePreferencesState: null,
error: null,
};
default:
return state;
}
};
export default profile;