%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/emergentqj/actioncivile/pre-auth/.8352c036a19b0051d0217d27d25e3f4a/static/js/sagas/
Upload File :
Create Path :
Current File : /home/emergentqj/actioncivile/pre-auth/.8352c036a19b0051d0217d27d25e3f4a/static/js/sagas/sendOtpToken.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 { serialize, trackMixpanelActions } from "utils";

import { getDataAction } from "../common/actions";

const config = configFunc();

const callMixpanelWrongPINAction = () => (
  trackMixpanelActions(MIXPANEL_ACTIONS.FORGOT_PASSWORD_WRONG_PIN, {
    category: "Selfservice",
    channel: "DesktopWeb",
    eventType: "forgotPassword",
    label: MIXPANEL_ACTIONS.FORGOT_PASSWORD_WRONG_PIN,
  })
);

function* runSendOtpToken(action) {
  const sendOtpTokenUrl = `${config.apiUrl}login/isValidPasswordResetPincode`;

  try {
    const { data } = action;
    const payload = yield call(
      getDataAction(`${sendOtpTokenUrl}?${serialize(data)}`, null, false, {
        "Content-Type": "application/json",
      }),
    );

    if (!payload.data.valid) {
      callMixpanelWrongPINAction();

      yield put({
        type: LIST_ACTIONS.SEND_OTP_TOKEN_ERROR,
        data: "accountLocked",
        profileLocked: payload.data.profileLocked,
        lockExpireDate: payload.data.profileLockExpireDate,
        remainingAttempts: payload.data.remainingAttempts,
      });
    } else {
      trackMixpanelActions(MIXPANEL_ACTIONS.FORGOT_PASSWORD_CORRECT_PIN, {
        category: "Selfservice",
        channel: "DesktopWeb",
        eventType: "forgotPassword",
        label: MIXPANEL_ACTIONS.FORGOT_PASSWORD_CORRECT_PIN,
      });

      yield put({
        type: LIST_ACTIONS.SEND_OTP_TOKEN_SUCCESS,
        payload,
      });
    }
  } catch (e) {
    callMixpanelWrongPINAction();

    const { data } = e.response || {};

    yield put({
      type: LIST_ACTIONS.SEND_OTP_TOKEN_ERROR,
      payload: data,
    });
  }
}

export default function* sendOtpToken() {
  yield takeEvery(LIST_ACTIONS.SEND_OTP_TOKEN_REQUEST, runSendOtpToken);
}

Zerion Mini Shell 1.0