90 lines
1.8 KiB
JavaScript
90 lines
1.8 KiB
JavaScript
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) => {
|
|
|
|
};
|