%PDF- %PDF-
Direktori : /home/emergentqj/actioncivile/pre-auth/def/static/js/sagas/ |
Current File : /home/emergentqj/actioncivile/pre-auth/def/static/js/sagas/migration.js |
import { put, call, takeEvery, } from "redux-saga/effects"; import configFunc from "config/config"; import LIST_ACTIONS from "constants/action_types"; import { getUniversalCookies } from "utils/cookies"; import { getDataAction } from "common/actions"; import { postDataAction2 } from "../common/actions"; const config = configFunc(); function* runMigration(dispatch, action) { const newPasswordUrl = `${config.apiUrl}migration/newpassword`; try { yield call(postDataAction2({ url: newPasswordUrl, params: { newPassword: action.newPassword, referenceId: action.referenceId, }, auth: true, })); } catch (e) { return yield put({ type: LIST_ACTIONS.MIGRATION_ERROR, }); } yield put({ type: LIST_ACTIONS.MIGRATION_DONE, }); return null; } function* runGetSepaDetails(dispatch, action) { const epSsAuthToken = getUniversalCookies().get("epSsAuthToken"); const getSepaDetailsUrl = `${config.b2bApiUrl}billinggroup/${action.id}/sepa`; try { const payload = yield call(postDataAction2({ url: getSepaDetailsUrl, params: { authToken: epSsAuthToken, }, auth: true, })); if (payload) { yield put({ type: LIST_ACTIONS.GET_SEPA_DETAILS_SUCCESS, payload, }); } } catch (e) { console.error(`Error with fetching migrated user's Sepa data ${e}`); } } function* runGetMigratedUserData(dispatch, action) { const { migrationReferenceId } = action; const getMigratedUserUrl = `${config.apiUrl}migration/migrateduser/${migrationReferenceId}`; try { const payload = yield call(getDataAction(getMigratedUserUrl, null, false)); if (payload) { yield put({ type: LIST_ACTIONS.GET_MIGRATED_USER_DATA_SUCCESS, payload, }); } if (payload.data.data.originalMoP === "DIRECT_DEBIT") { const id = payload.data.data.billingAccountId; yield put({ type: LIST_ACTIONS.GET_SEPA_DETAILS, id, }); } else { yield put({ type: LIST_ACTIONS.GET_BUSINESS_PAYMENT_METHODS_REQUEST, customerId: payload.data.data.customerId, }); } } catch (e) { console.error(`Error with fetching migrated user data ${e}`); } } export function* migration(dispatch) { yield takeEvery(LIST_ACTIONS.SET_NEW_MIGRATION_PASSWORD, runMigration, dispatch); } export function* getMigratedUserData(dispatch) { yield takeEvery(LIST_ACTIONS.GET_MIGRATED_USER_DATA, runGetMigratedUserData, dispatch); } export function* getSepaDetails(dispatch) { yield takeEvery(LIST_ACTIONS.GET_SEPA_DETAILS, runGetSepaDetails, dispatch); }