%PDF- %PDF-
Direktori : /home/emergentqj/actioncivile/pre-auth/.4cc3a2e1590a4463a5f392ddcc26929e/static/js/sagas/ |
Current File : /home/emergentqj/actioncivile/pre-auth/.4cc3a2e1590a4463a5f392ddcc26929e/static/js/sagas/signUp.js |
import { put, call, takeEvery } from "redux-saga/effects"; import i18n from "i18next"; import configFunc from "config/config"; import { getBusinessPaymentMethods, userLogin } from "actions/api_actions"; import { showAlert } from "actions/list_actions"; import LIST_ACTIONS from "constants/action_types"; import MIXPANEL_ACTIONS from "constants/mixpanel_actions"; import { postDataAction } from "common/actions"; import history from "utils/history"; import { trackMixpanelActions } from "utils/mixpanel"; import { formDataForMixPanel } from "utils"; const config = configFunc(); /** * Private User Signup * @param {*} dispatch * @param {*} actionParam */ function* runSignUp(dispatch, actionParam) { const { data } = actionParam; try { const signUpUrl = `${config.apiUrl}signup/private`; yield call(postDataAction(signUpUrl, data)); const userData = { countryConstant: data.countryCode, password: data.password, phoneNumber: data.phoneNumber, user: data.phoneNumber, }; trackMixpanelActions(MIXPANEL_ACTIONS.SIGN_UP_WEB_AUTH, { accountType: "CUSTOMER", customerType: "PRIVATE", email: data.email, phone: data.phoneNumber, username: data.phoneNumber, primaryPhoneNumber: data.phoneNumber, }); dispatch(userLogin(userData)); } catch (e) { yield put({ type: LIST_ACTIONS.SIGNUP_PRIVATE_ERROR, error: e.response.data, }); yield put( showAlert({ icon: "error", show: true, title: i18n.t("sweet-alert.sorry"), text: e.response.data.status === "DUPLICATE_USER" ? i18n.t("sweet-alert.user-exist") : i18n.t("sweet-alert.try-again"), }), ); } } /** * Corporate User Sugnup * @param {*} dispatch * @param {*} actionParam */ function* runSignUpCorporate(dispatch, actionParam) { try { const signUpUrl = `${config.apiUrl}signup/corporate`; const { data } = actionParam; const payload = yield call(postDataAction(signUpUrl, data, true)); trackMixpanelActions(MIXPANEL_ACTIONS.SIGN_UP_WEB_AUTH, { accountType: "CUSTOMER", customerType: "CORPORATE", firstName: data.firstName, lastName: data.lastName, City: data.city, email: data.email, phone: data.phone, username: data.phone, primaryPhoneNumber: data.phone, }); if (payload.data.redirect) { window.location.href = payload.data.redirect; } else { history.push("/"); } } catch (e) { yield put({ type: LIST_ACTIONS.SIGNUP_BUSINESS_ERROR, error: e.response.data, }); yield put( showAlert({ icon: "error", show: true, title: i18n.t("sweet-alert.sorry"), text: e.response.data && e.response.data.status === "DUPLICATE_USER" ? i18n.t("sweet-alert.user-exist") : i18n.t("sweet-alert.try-again"), }), ); } } function* runSignUpCorporateLogin(dispatch, actionParam) { const signUpUrl = `${config.apiUrl}signup/corporate`; const action = actionParam; const mpData = action.data; try { const payload = yield call(postDataAction(signUpUrl, action.data, true)); trackMixpanelActions( MIXPANEL_ACTIONS.BUSINESS_REGISTRATION_V2_CREATE_CUSTOMER, { category: "Selfservice", channel: "DesktopWeb", eventType: "click", label: MIXPANEL_ACTIONS.BUSINESS_REGISTRATION_V2_CREATE_CUSTOMER, formData: formDataForMixPanel(mpData), }, ); yield put({ type: LIST_ACTIONS.SIGNUP_CORPORATE_LOGIN_SUCCESS, payload }); if (payload && payload.data) { // yield put(getUser(false, true)); yield put(getBusinessPaymentMethods(payload.data.customer.id)); } else { yield put({ type: LIST_ACTIONS.SIGNUP_CORPORATE_LOGIN_ERROR, error: i18n.t("sweet-alert.sorry"), }); } } catch (e) { trackMixpanelActions( MIXPANEL_ACTIONS.BUSINESS_REGISTRATION_V2_CREATE_CUSTOMER_ERROR, { category: "Selfservice", channel: "DesktopWeb", eventType: "click", formData: formDataForMixPanel(mpData), error: e.response.data, }, ); yield put({ type: LIST_ACTIONS.SIGNUP_CORPORATE_LOGIN_ERROR, error: e.response.data, }); let errorMsg = i18n.t("sweet-alert.try-again"); if (e.response.data && e.response.data.status === "DUPLICATE_USER") { errorMsg = i18n.t("sweet-alert.user-exist"); } if ( e.response.data && e.response.data.message && e.response.data.message.includes("organization.number.in.use") ) { errorMsg = i18n.t("form-validator.organization-number-in-use"); } yield put( showAlert({ icon: "error", show: true, title: i18n.t("sweet-alert.sorry"), text: errorMsg, }), ); } } export function* signUp(dispatch) { yield takeEvery(LIST_ACTIONS.SIGNUP_REQUEST, runSignUp, dispatch); } export function* signUpCorporate(dispatch) { yield takeEvery( LIST_ACTIONS.SIGNUP_CORPORATE_REQUEST, runSignUpCorporate, dispatch, ); } export function* signUpCorporateLogin(dispatch) { yield takeEvery( LIST_ACTIONS.SIGNUP_CORPORATE_LOGIN_REQUEST, runSignUpCorporateLogin, dispatch, ); }