- Cleanup
This commit is contained in:
@@ -1,33 +1,36 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
import { getEndpointUrl } from '../api/index.js';
|
||||
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
import { fetchEvents as fetchEventsApi } from '../api/events.js';
|
||||
import {
|
||||
EVENTS_LOAD_FAILED,
|
||||
EVENTS_LOADED,
|
||||
GET_EVENTS,
|
||||
} from '../constants/actionTypes.js';
|
||||
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
import { API_ENDPOINTS } from '../constants/constants.js';
|
||||
|
||||
import Event from '../domain/Event.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
const eventsLoaded = (payload) => ({ type: EVENTS_LOADED, payload });
|
||||
|
||||
const eventsLoadSuccess = (events, dispatch) => {
|
||||
const payload = List(events).map((i) => Event.fromJS(i));
|
||||
dispatch({ type: EVENTS_LOADED, payload });
|
||||
const eventsLoadError = (payload) => ({ type: EVENTS_LOAD_FAILED, payload });
|
||||
|
||||
const eventsFetchSuccess = (items) => (dispatch) => {
|
||||
const payload = List(items).map((i) => Event.fromJS(i));
|
||||
|
||||
dispatch(eventsLoaded(payload));
|
||||
dispatch(unblockUI);
|
||||
};
|
||||
|
||||
export const setActiveEvent = (eventId) => ({
|
||||
type: SET_ACTIVE_EVENT,
|
||||
payload: eventId,
|
||||
});
|
||||
|
||||
export const fetchEvents = () => (dispatch) => {
|
||||
dispatch(blockUI());
|
||||
fetch(getEndpointUr(API_ENDPOINTS.GET_EVENTS))
|
||||
.then(response => response.json())
|
||||
.then(payload => eventsLoadSuccess(payload, dispatch))
|
||||
.catch(err => console.error('[actions::getEvents]', err));
|
||||
const eventsFetchFailure = (error) => (dispatch) => {
|
||||
console.error('[actions::events::eventsFetchFailure]', error);
|
||||
dispatch(eventsLoadError(error));
|
||||
dispatch(unblockUI);
|
||||
};
|
||||
|
||||
export const fetchEvents = () => (dispatch, getState) => {
|
||||
const authToken = getAuthToken(getState());
|
||||
|
||||
fetchEventsApi(authToken)
|
||||
.then(payload => dispatch(eventsFetchSuccess(payload)))
|
||||
.catch(err => dispatch(eventsFetchFailure(err)));
|
||||
};
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
import { fetchItems } from '../api/items.js';
|
||||
import { fetchItems as fetchItemsApi } from '../api/items.js';
|
||||
import {
|
||||
GET_ITEMS,
|
||||
ITEMS_LOADED,
|
||||
} from '../constants/actionTypes.js';
|
||||
import { getActiveEventId } from '../selectors/activeEvent.js';
|
||||
import { getLoginToken } from '../selectors/profile.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
|
||||
@@ -24,16 +24,16 @@ const itemsFetchSuccess = (items) => (dispatch) => {
|
||||
};
|
||||
|
||||
const itemsFetchFailure = (error) => (dispatch) => {
|
||||
console.error('[actions::getItems]', error));
|
||||
console.error('[actions::items::itemsFetchFailure]', error);
|
||||
dispatch(itemsLoadFailure(error));
|
||||
dispatch(unblockUI);
|
||||
};
|
||||
|
||||
export const fetchItems = () => (dispatch, getState) => {
|
||||
const eventId = getActiveEventId(getState());
|
||||
const authToken = getLoginToken(getState());
|
||||
const authToken = getAuthToken(getState());
|
||||
|
||||
fetchItems(activeEvent, authToken)
|
||||
fetchItemsApi(activeEvent, authToken)
|
||||
.then(payload => dispatch(itemsFetchSuccess(payload)))
|
||||
.catch(err => dispatch(itemsFetchFailure(err));
|
||||
.catch(err => dispatch(itemsFetchFailure(err)));
|
||||
};
|
||||
|
||||
@@ -3,13 +3,18 @@ import { blockUI, unblockUI } from './index.js';
|
||||
import {
|
||||
getEmailAvailability,
|
||||
getNomAvailaibility,
|
||||
loginUser,
|
||||
registerNewUser,
|
||||
} from '../api/profile.js';
|
||||
|
||||
import {
|
||||
DO_LOGOUT,
|
||||
LOGIN_FAILURE,
|
||||
LOGIN_SUCCESS,
|
||||
PROFILE_EMAIL_AVAILABLE,
|
||||
PROFILE_NOM_AVAILABLE,
|
||||
UNSET_AUTH,
|
||||
UNSET_PROFILE,
|
||||
UPDATE_PROFILE,
|
||||
} from '../constants/actionTypes.js';
|
||||
|
||||
@@ -23,6 +28,16 @@ const isValidNom = (payload) => ({
|
||||
payload,
|
||||
});
|
||||
|
||||
const loginFailure = (payload) => ({
|
||||
type: LOGIN_FAILURE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const loginSuccess = (payload) => ({
|
||||
type: LOGIN_SUCCESS,
|
||||
payload,
|
||||
});
|
||||
|
||||
const logoutUser = () => ({
|
||||
type: DO_LOGOUT,
|
||||
});
|
||||
@@ -37,6 +52,14 @@ const registrationSuccess = (payload) => ({
|
||||
payload,
|
||||
});
|
||||
|
||||
const unsetAuth = () => ({
|
||||
type: UNSET_AUTH,
|
||||
});
|
||||
|
||||
const unsetProfile = () => ({
|
||||
type: UNSET_PROFILE,
|
||||
});
|
||||
|
||||
const updateProfile = (profile) => ({
|
||||
type: UPDATE_PROFILE,
|
||||
payload: profile,
|
||||
@@ -50,8 +73,20 @@ export const checkNomAvailability = (nomDeBid) => (dispatch) => {
|
||||
|
||||
};
|
||||
|
||||
export const login = (username, password) => (dispatch) => {
|
||||
dispatch(blockUI());
|
||||
loginUser(username, password)
|
||||
.then(result => {
|
||||
dispatch(loginSuccess(result))
|
||||
})
|
||||
.catch(err => dispatch(loginFailure(err)));
|
||||
};
|
||||
|
||||
export const logout = () => (dispatch) => dispatch(logoutUser());
|
||||
export const logout = () => (dispatch) => {
|
||||
dispatch(unsetProfile());
|
||||
dispatch(unsetAuth());
|
||||
dispatch(logoutUser());
|
||||
};
|
||||
|
||||
// USER REGISTRATION
|
||||
const handleRegistrationSuccess = (user) => (dispatch) => {
|
||||
|
||||
Reference in New Issue
Block a user