%PDF- %PDF-
Direktori : /home/emergentqj/actioncivile/pre-auth/.632e77b3fb93bc8da5b589b869bc0037/static/js/sagas/ |
Current File : /home/emergentqj/actioncivile/pre-auth/.632e77b3fb93bc8da5b589b869bc0037/static/js/sagas/getOtpToken.js |
import { put, call, takeEvery } from "redux-saga/effects"; import configFunc from "config/config"; import MIXPANEL_ACTIONS from "constants/mixpanel_actions"; import LIST_ACTIONS from "constants/action_types"; import { trackMixpanelActions } from "utils"; import { postDataAction } from "common/actions"; const config = configFunc(); function* runGetOtpToken(action) { const sendOtpUrl = `${config.apiUrl}login/forgotPassword`; const dataSend = { username: action.data.phoneNumber, sendBySms: action.data.sendBySms, sendByEmail: action.data.sendByEmail, }; try { const payload = yield call( postDataAction(sendOtpUrl, dataSend, false, { "Content-Type": "application/json", }), ); const { data } = action; const { resent } = action; if (payload.data?.status === "VALIDATION_EXCEPTION") { trackMixpanelActions(MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN_ERROR, { category: "Selfservice", channel: "DesktopWeb", eventType: "click", error: payload.data, pinChannel: dataSend.sendBySms ? "sms" : "email", userName: dataSend.username, resetMethod: action.data.resetMethod, label: MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN, }); let error; if (payload.data.userErrorKey === "password.reset.token.emailorsmsmissing") { error = "emailorsmsmissing"; } else if (payload.data.userErrorKey === "password.reset.token.usernotfound") { error = "usernotfound"; } yield put({ type: LIST_ACTIONS.GET_OTP_TOKEN_ERROR_USERNAME, data: error, }); } else if (payload.data?.locked) { trackMixpanelActions(MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN_ERROR, { category: "Selfservice", channel: "DesktopWeb", eventType: "click", error: payload.data, pinChannel: dataSend.sendBySms ? "sms" : "email", userName: dataSend.username, resetMethod: action.data.resetMethod, label: MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN, }); yield put({ type: LIST_ACTIONS.GET_OTP_TOKEN_ERROR, data: "accountLocked", lockExpireDate: payload.data.lockExpireDate, }); } else { yield put({ type: LIST_ACTIONS.GET_OTP_TOKEN_SUCCESS, payload, data, resent, }); trackMixpanelActions(MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN, { category: "Selfservice", channel: "DesktopWeb", eventType: "click", pinChannel: dataSend.sendBySms ? "sms" : "email", userName: dataSend.username, resetMethod: action.data.resetMethod, label: MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN, }); } } catch (e) { const data = e.data?.message || "try-again"; yield put({ type: LIST_ACTIONS.GET_OTP_TOKEN_ERROR, data, }); trackMixpanelActions(MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN_ERROR, { category: "Selfservice", channel: "DesktopWeb", eventType: "click", error: data, pinChannel: dataSend.sendBySms ? "sms" : "email", userName: dataSend.username, resetMethod: action.data.resetMethod, label: MIXPANEL_ACTIONS.FORGOT_PASSWORD_SEND_PIN, }); } } export default function* getOtpToken() { yield takeEvery(LIST_ACTIONS.GET_OTP_TOKEN_REQUEST, runGetOtpToken); }