- Registration screens stubbing and partial buildouts
This commit is contained in:
@@ -1,38 +1,39 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
import { getEndpointUrl } from '../api/index.js';
|
||||
|
||||
import { fetchItems } 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 { blockUI, unblockUI } from './index.js';
|
||||
import { API_ENDPOINTS } from '../constants/constants.js';
|
||||
|
||||
import Item from '../domain/Item.js';
|
||||
|
||||
const itemsLoaded = (payload) => ({ type: ITEMS_LOADED, payload });
|
||||
|
||||
const itemsLoadSuccess = (items, dispatch) => {
|
||||
const itemsLoadError = (payload) => ({ type: ITEMS_LOAD_FAILED, payload });
|
||||
|
||||
const itemsFetchSuccess = (items) => (dispatch) => {
|
||||
const payload = List(items).map((i) => Item.fromJS(i));
|
||||
dispatch({ type: ITEMS_LOADED, payload });
|
||||
|
||||
dispatch(itemsLoaded(payload));
|
||||
dispatch(unblockUI);
|
||||
};
|
||||
|
||||
const itemsFetchFailure = (error) => (dispatch) => {
|
||||
console.error('[actions::getItems]', error));
|
||||
dispatch(itemsLoadFailure(error));
|
||||
dispatch(unblockUI);
|
||||
};
|
||||
|
||||
export const fetchItems = () => (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const activeEvent = state.get('activeEvent');
|
||||
const eventId = getActiveEventId(getState());
|
||||
const authToken = getLoginToken(getState());
|
||||
|
||||
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_ITEMS);
|
||||
apiUrl = apiUrl.replace(/:event_id$/, '');
|
||||
if (activeEvent) {
|
||||
apiUrl = `${apiUrl}${activeEvent}`;
|
||||
}
|
||||
|
||||
dispatch(blockUI());
|
||||
|
||||
fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(payload => itemsLoadSuccess(payload, dispatch))
|
||||
.catch(err => console.error('[actions::getItems]', err));
|
||||
fetchItems(activeEvent, authToken)
|
||||
.then(payload => dispatch(itemsFetchSuccess(payload)))
|
||||
.catch(err => dispatch(itemsFetchFailure(err));
|
||||
};
|
||||
|
||||
89
app/actions/profile.js
Normal file
89
app/actions/profile.js
Normal file
@@ -0,0 +1,89 @@
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
|
||||
import {
|
||||
getEmailAvailability,
|
||||
getNomAvailaibility,
|
||||
registerNewUser,
|
||||
} from '../api/profile.js';
|
||||
|
||||
import {
|
||||
DO_LOGOUT,
|
||||
PROFILE_EMAIL_AVAILABLE,
|
||||
PROFILE_NOM_AVAILABLE,
|
||||
UPDATE_PROFILE,
|
||||
} from '../constants/actionTypes.js';
|
||||
|
||||
const isValidEmail = (payload) => ({
|
||||
type: PROFILE_EMAIL_AVAILABLE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const isValidNom = (payload) => ({
|
||||
type: PROFILE_NOM_AVAILABLE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const logoutUser = () => ({
|
||||
type: DO_LOGOUT,
|
||||
});
|
||||
|
||||
const registrationFailure = (payload) => ({
|
||||
type: REGISTRATION_FAILURE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const registrationSuccess = (payload) => ({
|
||||
type: REGISTRATION_SUCCESS,
|
||||
payload,
|
||||
});
|
||||
|
||||
const updateProfile = (profile) => ({
|
||||
type: UPDATE_PROFILE,
|
||||
payload: profile,
|
||||
});
|
||||
|
||||
export const checkEmailAvailability = (email) => (dispatch) => {
|
||||
|
||||
};
|
||||
|
||||
export const checkNomAvailability = (nomDeBid) => (dispatch) => {
|
||||
|
||||
};
|
||||
|
||||
|
||||
export const logout = () => (dispatch) => dispatch(logoutUser());
|
||||
|
||||
// USER REGISTRATION
|
||||
const handleRegistrationSuccess = (user) => (dispatch) => {
|
||||
dispatch(unblockUI());
|
||||
dispatch(registrationSuccess());
|
||||
dispatch(loginSuccess(user));
|
||||
};
|
||||
|
||||
const handleRegistrationFailure = (error) => (dispatch) => {
|
||||
dispatch(unblockUI());
|
||||
dispatch(registrationFailure(error));
|
||||
};
|
||||
|
||||
export const registerUser = (user) => (dispatch) => {
|
||||
dispatch(blockUI());
|
||||
registerNewUser(user)
|
||||
.then(user => dispatch(handleRegistrationSuccess(user)))
|
||||
.catch(err => dispatch(handleRegistrationFailure(err)));
|
||||
};
|
||||
|
||||
// FACEBOOK
|
||||
export const facebookLoginSuccess = (result) => (dispatch) => {
|
||||
console.log('facebookLoginSuccess', result);
|
||||
dispatch(facebookLoginSuccess(result));
|
||||
};
|
||||
|
||||
|
||||
// LOGIN SERVICES COMMON ACTIONS
|
||||
export const serviceRegistrationError = (error) => (dispatch) => {
|
||||
|
||||
};
|
||||
|
||||
export const serviceRegistrationCanceled = () => (dispatch) => {
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user