- Linting... Prettier...
This commit is contained in:
6
app/actions/activeEvent.js
Normal file
6
app/actions/activeEvent.js
Normal file
@@ -0,0 +1,6 @@
|
||||
import { SET_ACTIVE_EVENT } from '../constants/actionTypes.js';
|
||||
|
||||
export const setActiveEvent = (eventId) => ({
|
||||
type: SET_ACTIVE_EVENT,
|
||||
payload: eventId,
|
||||
});
|
||||
@@ -1,52 +1,54 @@
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
|
||||
import { placeBid as placeBidApi } from '../api/bid.js';
|
||||
import {
|
||||
BID_FAILURE,
|
||||
BID_SUCCESS,
|
||||
PLACE_BID,
|
||||
SET_AUCTION_FILTER,
|
||||
SET_AUCTION_VIEW_MODE,
|
||||
BID_FAILURE,
|
||||
BID_SUCCESS,
|
||||
PLACE_BID,
|
||||
SET_AUCTION_FILTER,
|
||||
SET_AUCTION_VIEW_MODE,
|
||||
} from '../constants/actionTypes.js';
|
||||
import { getActiveEventId } from '../selectors/activeEvent.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
const placeBidFailure = (bid, dispatch) => {
|
||||
dispatch({ type: BID_FAILURE, bid });
|
||||
dispatch(unblockUI);
|
||||
const placeBidFailure = (payload) => ({
|
||||
type: BID_FAILURE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const placeBidSuccess = (payload) => ({
|
||||
type: BID_SUCCESS,
|
||||
payload,
|
||||
});
|
||||
|
||||
const handleBidFailure = (error) => (dispatch) => {
|
||||
console.error('[postBid]', error);
|
||||
dispatch(placeBidFailure(error));
|
||||
};
|
||||
|
||||
const placeBidSuccess = (bid, dispatch) => {
|
||||
dispatch({ type: BID_SUCCESS, bid });
|
||||
dispatch(unblockUI);
|
||||
const handleBidSuccess = (result) => (dispatch) => {
|
||||
dispatch(placeBidSuccess(result));
|
||||
};
|
||||
|
||||
const startPlacingBid = (itemId) => ({
|
||||
type: PLACE_BID,
|
||||
payload: itemId,
|
||||
});
|
||||
|
||||
export const changeFilterMode = (payload) => ({
|
||||
type: SET_AUCTION_FILTER,
|
||||
payload,
|
||||
type: SET_AUCTION_FILTER,
|
||||
payload,
|
||||
});
|
||||
|
||||
export const changeViewMode = (payload) => ({
|
||||
type: SET_AUCTION_VIEW_MODE,
|
||||
payload,
|
||||
type: SET_AUCTION_VIEW_MODE,
|
||||
payload,
|
||||
});
|
||||
|
||||
export const placeBid = (payload) => ({
|
||||
type: PLACE_BID,
|
||||
payload,
|
||||
});
|
||||
export const placeBid = ({ bidAmount, itemId, maxAmount }) => (dispatch, getState) => {
|
||||
const authToken = getAuthToken(getState());
|
||||
const eventId = getActiveEventId(getState());
|
||||
|
||||
export const postBid = () => (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const activeEvent = state.get('activeEvent');
|
||||
|
||||
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));
|
||||
dispatch(startPlacingBid(itemId));
|
||||
placeBidApi({ bidAmount, eventId, itemId, maxAmount }, authToken)
|
||||
.then((payload) => dispatch(handleBidSuccess(payload)))
|
||||
.catch((err) => dispatch(handleBidFailure(err)));
|
||||
};
|
||||
|
||||
@@ -1,39 +1,27 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
import { getEndpointUrl } from '../api/index.js';
|
||||
|
||||
import {
|
||||
AUCTIONS_UPDATED,
|
||||
ITEMS_LOADED,
|
||||
} from '../constants/actionTypes.js';
|
||||
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
import { API_ENDPOINTS } from '../constants/constants.js';
|
||||
import { fetchAuctionStatus as fetchActionStatusApi } from '../api/actionStatus.js';
|
||||
import { AUCTIONS_UPDATED } from '../constants/actionTypes.js';
|
||||
import { getActiveEventId } from '../selectors/activeEvent.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
import Auction from '../domain/Auction.js';
|
||||
|
||||
const auctionsUpdated = (payload) => ({
|
||||
type: AUCTIONS_UPDATED,
|
||||
payload,
|
||||
});
|
||||
|
||||
const autionStatusLoadSuccess = (auctions, dispatch) => {
|
||||
const payload = List(auctions).map((i) => Auction.fromJS(i));
|
||||
dispatch({ type: AUCTIONS_UPDATED, payload });
|
||||
dispatch(unblockUI);
|
||||
const autionStatusLoadSuccess = (auctions) => (dispatch) => {
|
||||
const payload = List(auctions).map((i) => Auction.fromJS(i));
|
||||
dispatch(auctionsUpdated(payload));
|
||||
};
|
||||
|
||||
export const fetchAuctionStatus = () => (dispatch, getState) => {
|
||||
const state = getState();
|
||||
const activeEvent = state.get('activeEvent');
|
||||
const authToken = getAuthToken(getState());
|
||||
const eventId = getActiveEventId(getState());
|
||||
|
||||
let apiUrl = getEndpointUrl(API_ENDPOINTS.GET_STATUS);
|
||||
apiUrl = apiUrl.replace(/:event_id$/, '');
|
||||
if (activeEvent) {
|
||||
apiUrl = `${apiUrl}${activeEvent}`;
|
||||
}
|
||||
|
||||
dispatch(blockUI());
|
||||
|
||||
return fetch(apiUrl)
|
||||
.then(response => response.json())
|
||||
.then(payload => autionStatusLoadSuccess(payload, dispatch))
|
||||
.catch(err => console.error('[actions::getStatus]', err));
|
||||
return fetchActionStatusApi(eventId, authToken)
|
||||
.then((payload) => dispatch(autionStatusLoadSuccess(payload)))
|
||||
.catch((err) => console.error('[actions::getStatus]', err));
|
||||
};
|
||||
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
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 { EVENTS_LOAD_FAILED, EVENTS_LOADED, GET_EVENTS } from '../constants/actionTypes.js';
|
||||
import Event from '../domain/Event.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
const beginFetchEvents = () => ({ type: GET_EVENTS });
|
||||
|
||||
const eventsLoaded = (payload) => ({ 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);
|
||||
const payload = List(items).map((i) => Event.fromJS(i));
|
||||
dispatch(eventsLoaded(payload));
|
||||
};
|
||||
|
||||
const eventsFetchFailure = (error) => (dispatch) => {
|
||||
console.error('[actions::events::eventsFetchFailure]', error);
|
||||
dispatch(eventsLoadError(error));
|
||||
dispatch(unblockUI);
|
||||
console.error('[actions::events::eventsFetchFailure]', error);
|
||||
dispatch(eventsLoadError(error));
|
||||
};
|
||||
|
||||
export const fetchEvents = () => (dispatch, getState) => {
|
||||
const authToken = getAuthToken(getState());
|
||||
const authToken = getAuthToken(getState());
|
||||
|
||||
fetchEventsApi(authToken)
|
||||
.then(payload => dispatch(eventsFetchSuccess(payload)))
|
||||
.catch(err => dispatch(eventsFetchFailure(err)));
|
||||
dispatch(beginFetchEvents());
|
||||
fetchEventsApi(authToken)
|
||||
.then((payload) => dispatch(eventsFetchSuccess(payload)))
|
||||
.catch((err) => dispatch(eventsFetchFailure(err)));
|
||||
};
|
||||
|
||||
@@ -1,12 +1,9 @@
|
||||
import {
|
||||
BLOCK_UI,
|
||||
UNBLOCK_UI,
|
||||
} from '../constants/actionTypes.js';
|
||||
import { BLOCK_UI, UNBLOCK_UI } from '../constants/actionTypes.js';
|
||||
|
||||
export const blockUI = () => ({
|
||||
type: BLOCK_UI,
|
||||
type: BLOCK_UI,
|
||||
});
|
||||
|
||||
export const unblockUI = () => ({
|
||||
type: UNBLOCK_UI,
|
||||
type: UNBLOCK_UI,
|
||||
});
|
||||
|
||||
@@ -1,39 +1,34 @@
|
||||
import { List } from 'immutable';
|
||||
|
||||
import { fetchItems as fetchItemsApi } from '../api/items.js';
|
||||
import {
|
||||
GET_ITEMS,
|
||||
ITEMS_LOADED,
|
||||
} from '../constants/actionTypes.js';
|
||||
import { GET_ITEMS, ITEMS_LOAD_FAILED, ITEMS_LOADED } from '../constants/actionTypes.js';
|
||||
import { getActiveEventId } from '../selectors/activeEvent.js';
|
||||
import { getAuthToken } from '../selectors/auth.js';
|
||||
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
|
||||
import Item from '../domain/Item.js';
|
||||
|
||||
const beginItemLoad = () => ({ type: GET_ITEMS });
|
||||
|
||||
const itemsLoaded = (payload) => ({ type: ITEMS_LOADED, payload });
|
||||
|
||||
const itemsLoadError = (payload) => ({ type: ITEMS_LOAD_FAILED, payload });
|
||||
const itemsLoadFailure = (payload) => ({ type: ITEMS_LOAD_FAILED, payload });
|
||||
|
||||
const itemsFetchSuccess = (items) => (dispatch) => {
|
||||
const payload = List(items).map((i) => Item.fromJS(i));
|
||||
|
||||
dispatch(itemsLoaded(payload));
|
||||
dispatch(unblockUI);
|
||||
const payload = List(items).map((i) => Item.fromJS(i));
|
||||
dispatch(itemsLoaded(payload));
|
||||
};
|
||||
|
||||
const itemsFetchFailure = (error) => (dispatch) => {
|
||||
console.error('[actions::items::itemsFetchFailure]', error);
|
||||
dispatch(itemsLoadFailure(error));
|
||||
dispatch(unblockUI);
|
||||
console.error('[actions::items::itemsFetchFailure]', error);
|
||||
dispatch(itemsLoadFailure(error));
|
||||
};
|
||||
|
||||
export const fetchItems = () => (dispatch, getState) => {
|
||||
const eventId = getActiveEventId(getState());
|
||||
const authToken = getAuthToken(getState());
|
||||
const authToken = getAuthToken(getState());
|
||||
const eventId = getActiveEventId(getState());
|
||||
|
||||
fetchItemsApi(activeEvent, authToken)
|
||||
.then(payload => dispatch(itemsFetchSuccess(payload)))
|
||||
.catch(err => dispatch(itemsFetchFailure(err)));
|
||||
dispatch(beginItemLoad());
|
||||
fetchItemsApi(eventId, authToken)
|
||||
.then((payload) => dispatch(itemsFetchSuccess(payload)))
|
||||
.catch((err) => dispatch(itemsFetchFailure(err)));
|
||||
};
|
||||
|
||||
@@ -1,124 +1,117 @@
|
||||
import { blockUI, unblockUI } from './index.js';
|
||||
|
||||
import {
|
||||
getEmailAvailability,
|
||||
getNomAvailaibility,
|
||||
loginUser,
|
||||
registerNewUser,
|
||||
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,
|
||||
DO_LOGOUT,
|
||||
LOGIN_FAILURE,
|
||||
LOGIN_SUCCESS,
|
||||
PROFILE_EMAIL_AVAILABLE,
|
||||
PROFILE_NOM_AVAILABLE,
|
||||
REGISTRATION_FAILURE,
|
||||
REGISTRATION_SUCCESS,
|
||||
UNSET_AUTH,
|
||||
UNSET_PROFILE,
|
||||
UPDATE_PROFILE,
|
||||
} from '../constants/actionTypes.js';
|
||||
|
||||
const isValidEmail = (payload) => ({
|
||||
type: PROFILE_EMAIL_AVAILABLE,
|
||||
payload,
|
||||
type: PROFILE_EMAIL_AVAILABLE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const isValidNom = (payload) => ({
|
||||
type: PROFILE_NOM_AVAILABLE,
|
||||
payload,
|
||||
type: PROFILE_NOM_AVAILABLE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const loginFailure = (payload) => ({
|
||||
type: LOGIN_FAILURE,
|
||||
payload,
|
||||
type: LOGIN_FAILURE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const loginSuccess = (payload) => ({
|
||||
type: LOGIN_SUCCESS,
|
||||
payload,
|
||||
type: LOGIN_SUCCESS,
|
||||
payload,
|
||||
});
|
||||
|
||||
const logoutUser = () => ({
|
||||
type: DO_LOGOUT,
|
||||
type: DO_LOGOUT,
|
||||
});
|
||||
|
||||
const registrationFailure = (payload) => ({
|
||||
type: REGISTRATION_FAILURE,
|
||||
payload,
|
||||
type: REGISTRATION_FAILURE,
|
||||
payload,
|
||||
});
|
||||
|
||||
const registrationSuccess = (payload) => ({
|
||||
type: REGISTRATION_SUCCESS,
|
||||
payload,
|
||||
type: REGISTRATION_SUCCESS,
|
||||
payload,
|
||||
});
|
||||
|
||||
const unsetAuth = () => ({
|
||||
type: UNSET_AUTH,
|
||||
type: UNSET_AUTH,
|
||||
});
|
||||
|
||||
const unsetProfile = () => ({
|
||||
type: UNSET_PROFILE,
|
||||
type: UNSET_PROFILE,
|
||||
});
|
||||
|
||||
const updateProfile = (profile) => ({
|
||||
type: UPDATE_PROFILE,
|
||||
payload: profile,
|
||||
type: UPDATE_PROFILE,
|
||||
payload: profile,
|
||||
});
|
||||
|
||||
export const checkEmailAvailability = (email) => (dispatch) => {
|
||||
export const checkEmailAvailability = (email) => (dispatch) => {};
|
||||
|
||||
};
|
||||
|
||||
export const checkNomAvailability = (nomDeBid) => (dispatch) => {
|
||||
|
||||
};
|
||||
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)));
|
||||
dispatch(blockUI());
|
||||
loginUser(username, password)
|
||||
.then((result) => {
|
||||
dispatch(loginSuccess(result));
|
||||
})
|
||||
.catch((err) => dispatch(loginFailure(err)));
|
||||
};
|
||||
|
||||
export const logout = () => (dispatch) => {
|
||||
dispatch(unsetProfile());
|
||||
dispatch(unsetAuth());
|
||||
dispatch(logoutUser());
|
||||
dispatch(unsetProfile());
|
||||
dispatch(unsetAuth());
|
||||
dispatch(logoutUser());
|
||||
};
|
||||
|
||||
// USER REGISTRATION
|
||||
const handleRegistrationSuccess = (user) => (dispatch) => {
|
||||
dispatch(unblockUI());
|
||||
dispatch(registrationSuccess());
|
||||
dispatch(loginSuccess(user));
|
||||
dispatch(unblockUI());
|
||||
dispatch(registrationSuccess());
|
||||
dispatch(loginSuccess(user));
|
||||
};
|
||||
|
||||
const handleRegistrationFailure = (error) => (dispatch) => {
|
||||
dispatch(unblockUI());
|
||||
dispatch(registrationFailure(error));
|
||||
dispatch(unblockUI());
|
||||
dispatch(registrationFailure(error));
|
||||
};
|
||||
|
||||
export const registerUser = (user) => (dispatch) => {
|
||||
dispatch(blockUI());
|
||||
registerNewUser(user)
|
||||
.then(user => dispatch(handleRegistrationSuccess(user)))
|
||||
.catch(err => dispatch(handleRegistrationFailure(err)));
|
||||
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));
|
||||
console.log('facebookLoginSuccess', result);
|
||||
dispatch(facebookLoginSuccess(result));
|
||||
};
|
||||
|
||||
|
||||
// LOGIN SERVICES COMMON ACTIONS
|
||||
export const serviceRegistrationError = (error) => (dispatch) => {
|
||||
export const serviceRegistrationError = (error) => (dispatch) => {};
|
||||
|
||||
};
|
||||
|
||||
export const serviceRegistrationCanceled = () => (dispatch) => {
|
||||
|
||||
};
|
||||
export const serviceRegistrationCanceled = () => (dispatch) => {};
|
||||
|
||||
Reference in New Issue
Block a user