How to use checkStatus method in Testcafe

Best JavaScript code snippet using testcafe

user.js

Source:user.js Github

copy

Full Screen

1import { call, put, takeEvery, takeLatest, select } from 'redux-saga/effects';2import { push } from 'connected-react-router/immutable';3import api from '../../network';4import utils from '../../theme/utils';5export const getSigninData = state => state.auth.signinData;6// eslint-disable-next-line camelcase7function* fetch_analysts_for_subscriptions(request) {8 const signinData = yield select(getSigninData); // get the redux object9 console.log('here fetch_analysts_for_subscriptions!!!', request);10 try {11 yield put({ type: 'SET_FILTER_VALUES', payload: request.payload });12 console.log(request.payload.searchParams);13 let payload = {14 searchParams: request.payload.searchParams,15 token: signinData.token.AuthenticationResult.AccessToken16 };17 const response = yield call(api.analystFilterList, payload);18 console.log('response', response);19 if (response.status === 200) {20 if (response.data && response.data.code === 200) {21 yield put({ type: 'SAVE_ANALYSTS_FOR_SUBSCRIPTION', payload: response.data.response });22 } else {23 yield put({ type: 'SAVE_ANALYSTS_FOR_SUBSCRIPTION', payload: [] });24 yield put({ type: 'SET_MESSAGE', payload: 'Something went wrong' });25 }26 } else {27 yield put({ type: 'SET_MESSAGE', payload: 'something went wrong' });28 }29 } catch (error) {30 console.log('error: ', error);31 const checkStatus = utils.checkAPIfailure(error);32 console.log(checkStatus);33 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {34 // change funcName to the current function name so that it gets called back35 const params = {36 funcName: fetch_analysts_for_subscriptions,37 params: request38 };39 yield call(refreshTokenFunc, params);40 } else if (41 checkStatus.Error &&42 checkStatus.Error.Message &&43 checkStatus.Error.Message === 'Access Token has been revoked'44 ) {45 yield put({ type: 'LOGOUT_SUCCESS' });46 // window.localStorage.clear();47 window.localStorage.removeItem('notification');48 window.localStorage.removeItem('notifications');49 yield put(push('/user-analyst'));50 } else {51 console.log('Network Err! or Internal Server Err!');52 yield put({ type: 'SET_MESSAGE', payload: 'something went wrong' });53 }54 }55 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);56 // console.log('response', response);57 // if (response.status === 200) {58 // if (response.data && response.data.code === 200) {59 // const bankDetail = yield call(api.getBankDetails, request.payload.token);60 // console.log(bankDetail);61 // if (bankDetail.status === 200 && bankDetail.data.code === 200) {62 // yield put({ type: 'SAVE_BANK_ACCOUNT', payload: bankDetail.data.response });63 // }64 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });65 // } else {66 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });67 // }68 // } else {69 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });70 // }71}72function* fetch_performance_and_transactions_data(request) {73 const signinData = yield select(getSigninData); // get the redux object74 console.log('here fetch_performance_and_transactions_data!!!', request);75 try {76 const payload = {77 analyst_id: request.payload.analyst_id,78 token: signinData.token.AuthenticationResult.AccessToken79 };80 const response = yield call(api.getAnalystPerformance, payload);81 console.log('response', response);82 if (response.status === 200) {83 if (response.data && response.data.code === 200) {84 yield put({ type: 'SAVE_PERFORMANCE_AND_TRANSACTIONS_DATA', payload: response.data.response });85 } else {86 yield put({ type: 'SET_ANALYST_MESSAGE', payload: response.data.response });87 }88 } else {89 yield put({ type: 'SET_ANALYST_MESSAGE', payload: response.statusText });90 }91 } catch (error) {92 console.log('error: ', error);93 const checkStatus = utils.checkAPIfailure(error);94 console.log(checkStatus);95 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {96 // change funcName to the current function name so that it gets called back97 const params = {98 funcName: fetch_performance_and_transactions_data,99 params: request100 };101 yield call(refreshTokenFunc, params);102 } else if (103 checkStatus.Error &&104 checkStatus.Error.Message &&105 checkStatus.Error.Message === 'Access Token has been revoked'106 ) {107 yield put({ type: 'LOGOUT_SUCCESS' });108 // window.localStorage.clear();109 window.localStorage.removeItem('notification');110 window.localStorage.removeItem('notifications');111 yield put(push('/user-analyst'));112 } else {113 console.log('Network Err! or Internal Server Err!');114 }115 // yield put({ type: 'SET_MESSAGE', payload: error });116 }117}118function* getAnalystSubscriptionPlan(request) {119 const signinData = yield select(getSigninData); // get the redux object120 console.log('Get subscription plan list', request);121 try {122 const payload = {123 analyst_id: request.payload.analyst_id,124 segment: request.payload.segment,125 token: signinData.token.AuthenticationResult.AccessToken126 };127 const response = yield call(api.getFilterSubscriptionPlanList, payload);128 console.log('response', response);129 if (response.status === 200) {130 if (response.data && response.data.code === 200) {131 yield put({ type: 'SET_ANALYST_SUBSCRIPTION_PLAN', payload: response.data.response });132 } else {133 yield put({ type: 'SET_ANALYST_SUBSCRIPTION_PLAN', payload: [] });134 yield put({ type: 'SET_MESSAGE', payload: response.data.response });135 }136 } else {137 yield put({ type: 'SET_ANALYST_SUBSCRIPTION_PLAN', payload: [] });138 yield put({ type: 'SET_MESSAGE', payload: response.statusText });139 }140 } catch (error) {141 console.log('error: ', error);142 const checkStatus = utils.checkAPIfailure(error);143 console.log(checkStatus);144 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {145 // change funcName to the current function name so that it gets called back146 const params = {147 funcName: getAnalystSubscriptionPlan,148 params: request149 };150 yield call(refreshTokenFunc, params);151 } else if (152 checkStatus.Error &&153 checkStatus.Error.Message &&154 checkStatus.Error.Message === 'Access Token has been revoked'155 ) {156 yield put({ type: 'LOGOUT_SUCCESS' });157 // window.localStorage.clear();158 window.localStorage.removeItem('notification');159 window.localStorage.removeItem('notifications');160 yield put(push('/user-analyst'));161 } else {162 console.log('Network Err! or Internal Server Err!');163 }164 // yield put({ type: 'SET_MESSAGE', payload: error });165 }166}167function* getPaymentSubscriptionLink(request) {168 const signinData = yield select(getSigninData); // get the redux object169 console.log('Get payment subscription link', request);170 try {171 const payload = { token: signinData.token.AuthenticationResult.AccessToken };172 const response = yield call(api.paymentSubscriptionLink, request.payload.data, payload.token);173 console.log('response', response);174 if (response.status === 200) {175 if (response.data && response.data.code === 200) {176 yield put({ type: 'SET_PAYMENT_SUBSCRIPTION_LINK', payload: response.data.response });177 } else {178 yield put({ type: 'SET_PAYMENT_SUBSCRIPTION_LINK', payload: null });179 yield put({ type: 'SET_MESSAGE', payload: response.data.response });180 }181 } else {182 yield put({ type: 'SET_PAYMENT_SUBSCRIPTION_LINK', payload: null });183 yield put({ type: 'SET_MESSAGE', payload: response.statusText });184 }185 } catch (error) {186 console.log('error: ', error);187 const checkStatus = utils.checkAPIfailure(error);188 console.log(checkStatus);189 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {190 // change funcName to the current function name so that it gets called back191 const params = {192 funcName: getPaymentSubscriptionLink,193 params: request194 };195 yield call(refreshTokenFunc, params);196 } else if (197 checkStatus.Error &&198 checkStatus.Error.Message &&199 checkStatus.Error.Message === 'Access Token has been revoked'200 ) {201 yield put({ type: 'LOGOUT_SUCCESS' });202 // window.localStorage.clear();203 window.localStorage.removeItem('notification');204 window.localStorage.removeItem('notifications');205 yield put(push('/user-analyst'));206 } else {207 console.log('Network Err! or Internal Server Err!');208 }209 // yield put({ type: 'SET_MESSAGE', payload: error });210 }211}212function* getRecentlyClosedTrades(request) {213 const signinData = yield select(getSigninData); // get the redux object214 console.log('Get recently closed trades', request);215 try {216 const payload = {217 analyst_id: request.payload.analyst_id,218 token: signinData.token.AuthenticationResult.AccessToken219 };220 const response = yield call(api.fetchRecentlyClosedTrades, payload);221 console.log('response', response);222 if (response.status === 200) {223 if (response.data && response.data.code === 200) {224 yield put({ type: 'SET_RECENTLY_CLOSED_TRADES', payload: response.data.response });225 } else {226 yield put({ type: 'SET_RECENTLY_CLOSED_TRADES', payload: [] });227 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });228 }229 } else {230 yield put({ type: 'SET_RECENTLY_CLOSED_TRADES', payload: null });231 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });232 }233 } catch (error) {234 console.log('error: ', error);235 const checkStatus = utils.checkAPIfailure(error);236 console.log(checkStatus);237 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {238 // change funcName to the current function name so that it gets called back239 const params = {240 funcName: getRecentlyClosedTrades,241 params: request242 };243 yield call(refreshTokenFunc, params);244 } else if (245 checkStatus.Error &&246 checkStatus.Error.Message &&247 checkStatus.Error.Message === 'Access Token has been revoked'248 ) {249 yield put({ type: 'LOGOUT_SUCCESS' });250 // window.localStorage.clear();251 window.localStorage.removeItem('notification');252 window.localStorage.removeItem('notifications');253 yield put(push('/user-analyst'));254 } else {255 console.log('Network Err! or Internal Server Err!');256 }257 // yield put({ type: 'SET_MESSAGE', payload: error });258 }259}260function* fetch_user_cards(request) {261 const signinData = yield select(getSigninData); // get the redux object262 console.log('here fetch_user_cards!!!', request);263 try {264 let response = yield fetch('https://api.myjson.com/bins/13ncd2');265 response = yield response.json();266 console.log('response', response);267 yield put({ type: 'SAVE_USER_CARDS', payload: response });268 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);269 // console.log('response', response);270 // if (response.status === 200) {271 // if (response.data && response.data.code === 200) {272 // const bankDetail = yield call(api.getBankDetails, request.payload.token);273 // console.log(bankDetail);274 // if (bankDetail.status === 200 && bankDetail.data.code === 200) {275 // yield put({ type: 'SAVE_BANK_ACCOUNT', payload: bankDetail.data.response });276 // }277 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });278 // } else {279 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });280 // }281 // } else {282 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });283 // }284 } catch (error) {285 console.log('error: ', error);286 const checkStatus = utils.checkAPIfailure(error);287 console.log(checkStatus);288 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {289 // change funcName to the current function name so that it gets called back290 const params = {291 funcName: fetch_user_cards,292 params: request293 };294 yield call(refreshTokenFunc, params);295 } else if (296 checkStatus.Error &&297 checkStatus.Error.Message &&298 checkStatus.Error.Message === 'Access Token has been revoked'299 ) {300 yield put({ type: 'LOGOUT_SUCCESS' });301 // window.localStorage.clear();302 window.localStorage.removeItem('notification');303 window.localStorage.removeItem('notifications');304 yield put(push('/user-analyst'));305 } else {306 console.log('Network Err! or Internal Server Err!');307 }308 // yield put({ type: 'SET_MESSAGE', payload: error });309 }310}311function* fetch_all_webinars(request) {312 const signinData = yield select(getSigninData); // get the redux object313 console.log('here fetch_all_webinars!!!', request);314 try {315 // let response = yield fetch('https://api.myjson.com/bins/13ncd2');316 // response = yield response.json();317 // console.log('response', response);318 // yield put({ type: 'SAVE_USER_CARDS', payload: response });319 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);320 // console.log('response', response);321 // if (response.status === 200) {322 // if (response.data && response.data.code === 200) {323 // const bankDetail = yield call(api.getBankDetails, request.payload.token);324 // console.log(bankDetail);325 // if (bankDetail.status === 200 && bankDetail.data.code === 200) {326 // yield put({ type: 'SAVE_BANK_ACCOUNT', payload: bankDetail.data.response });327 // }328 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });329 // } else {330 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });331 // }332 // } else {333 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });334 // }335 } catch (error) {336 console.log('error: ', error);337 const checkStatus = utils.checkAPIfailure(error);338 console.log(checkStatus);339 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {340 // change funcName to the current function name so that it gets called back341 const params = {342 funcName: fetch_all_webinars,343 params: request344 };345 yield call(refreshTokenFunc, params);346 } else if (347 checkStatus.Error &&348 checkStatus.Error.Message &&349 checkStatus.Error.Message === 'Access Token has been revoked'350 ) {351 yield put({ type: 'LOGOUT_SUCCESS' });352 // window.localStorage.clear();353 window.localStorage.removeItem('notification');354 window.localStorage.removeItem('notifications');355 yield put(push('/user-analyst'));356 } else {357 console.log('Network Err! or Internal Server Err!');358 }359 // yield put({ type: 'SET_MESSAGE', payload: error });360 }361}362function* follow(request) {363 const signinData = yield select(getSigninData); // get the redux object364 console.log('follow!!!', request);365 try {366 const payload = { analyst_id: request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };367 const followRes = yield call(api.follow, payload);368 const checkStatus = utils.checkAPIfailure(followRes);369 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {370 console.log(':::::::SILENTLY UPDATED:::::::::::');371 console.log(followRes);372 console.log('::::::::::::::::::::::::::::::::::');373 } else {374 console.log('failed follow');375 }376 } catch (error) {377 console.log('error: ', error);378 const checkStatus = utils.checkAPIfailure(error);379 console.log(checkStatus);380 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {381 // change funcName to the current function name so that it gets called back382 const params = {383 funcName: follow,384 params: request385 };386 yield call(refreshTokenFunc, params);387 } else if (388 checkStatus.Error &&389 checkStatus.Error.Message &&390 checkStatus.Error.Message === 'Access Token has been revoked'391 ) {392 yield put({ type: 'LOGOUT_SUCCESS' });393 // window.localStorage.clear();394 window.localStorage.removeItem('notification');395 window.localStorage.removeItem('notifications');396 yield put(push('/user-analyst'));397 } else {398 console.log('Network Err! or Internal Server Err!');399 }400 // yield put({ type: 'SET_MESSAGE', payload: error });401 }402}403function* unfollow(request) {404 const signinData = yield select(getSigninData); // get the redux object405 console.log('unfollow', request);406 try {407 const payload = { analyst_id: request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };408 const unfollowRes = yield call(api.unfollow, payload, signinData.token.AuthenticationResult.AccessToken);409 const checkStatus = utils.checkAPIfailure(unfollowRes);410 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {411 console.log(':::::::SILENTLY UPDATED:::::::::::');412 console.log(unfollowRes);413 console.log('::::::::::::::::::::::::::::::::::');414 } else {415 console.log('failed unfollow');416 }417 } catch (error) {418 console.log('error: ', error);419 const checkStatus = utils.checkAPIfailure(error);420 console.log(checkStatus);421 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {422 // change funcName to the current function name so that it gets called back423 const params = {424 funcName: unfollow,425 params: request426 };427 yield call(refreshTokenFunc, params);428 } else if (429 checkStatus.Error &&430 checkStatus.Error.Message &&431 checkStatus.Error.Message === 'Access Token has been revoked'432 ) {433 yield put({ type: 'LOGOUT_SUCCESS' });434 // window.localStorage.clear();435 window.localStorage.removeItem('notification');436 window.localStorage.removeItem('notifications');437 yield put(push('/user-analyst'));438 } else {439 console.log('Network Err! or Internal Server Err!');440 }441 // yield put({ type: 'SET_MESSAGE', payload: error });442 }443}444function* getFeed(request) {445 const signinData = yield select(getSigninData); // get the redux object446 yield put({ type: 'SET_LOADER', payload: true });447 try {448 const response = yield call(api.getFeed, signinData.token.AuthenticationResult.AccessToken);449 console.log('response', response);450 if (response.status === 200) {451 yield put({ type: 'SET_LOADER', payload: false });452 if (response.data && response.data.code === 200) {453 yield put({ type: 'SET_FEED', payload: response.data.response });454 } else if (response.data && response.data.code === 404) {455 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });456 } else {457 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });458 }459 } else {460 yield put({ type: 'SET_LOADER', payload: false });461 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });462 }463 } catch (error) {464 yield put({ type: 'SET_LOADER', payload: false });465 console.log('error: ', error);466 const checkStatus = utils.checkAPIfailure(error);467 console.log(checkStatus);468 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {469 // change funcName to the current function name so that it gets called back470 const params = {471 funcName: getFeed,472 params: request473 };474 yield call(refreshTokenFunc, params);475 } else if (476 checkStatus.Error &&477 checkStatus.Error.Message &&478 checkStatus.Error.Message === 'Access Token has been revoked'479 ) {480 yield put({ type: 'LOGOUT_SUCCESS' });481 // window.localStorage.clear();482 window.localStorage.removeItem('notification');483 window.localStorage.removeItem('notifications');484 yield put(push('/user-analyst'));485 } else {486 console.log('Network Err! or Internal Server Err!');487 }488 // yield put({ type: 'SET_MESSAGE', payload: error });489 }490}491function* getSubFeed(request) {492 const signinData = yield select(getSigninData); // get the redux object493 yield put({ type: 'SET_LOADER', payload: true });494 try {495 const response = yield call(api.getSubFeed, signinData.token.AuthenticationResult.AccessToken);496 console.log('response', response);497 if (response.status === 200) {498 yield put({ type: 'SET_LOADER', payload: false });499 if (response.data && response.data.code === 200) {500 yield put({ type: 'SET_SUB_FEED', payload: response.data.response });501 } else if (response.data && response.data.code === 404) {502 yield put({ type: 'SET_LOADER', payload: false });503 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });504 } else {505 yield put({ type: 'SET_LOADER', payload: false });506 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });507 }508 } else {509 yield put({ type: 'SET_LOADER', payload: false });510 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });511 }512 } catch (error) {513 yield put({ type: 'SET_LOADER', payload: false });514 console.log('error: ', error);515 const checkStatus = utils.checkAPIfailure(error);516 console.log(checkStatus);517 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {518 // change funcName to the current function name so that it gets called back519 const params = {520 funcName: getSubFeed,521 params: request522 };523 yield call(refreshTokenFunc, params);524 } else if (525 checkStatus.Error &&526 checkStatus.Error.Message &&527 checkStatus.Error.Message === 'Access Token has been revoked'528 ) {529 yield put({ type: 'LOGOUT_SUCCESS' });530 // window.localStorage.clear();531 window.localStorage.removeItem('notification');532 window.localStorage.removeItem('notifications');533 yield put(push('/user-analyst'));534 } else {535 console.log('Network Err! or Internal Server Err!');536 }537 // yield put({ type: 'SET_MESSAGE', payload: error });538 }539}540// function* getFeedImages(request) {541// const signinData = yield select(getSigninData); // get the redux object542// yield put({ type: 'SET_LOADER', payload: true });543// try {544// const response = yield call(api.getFeedImages, request.payload);545// console.log('response', response);546// if (response.status === 200) {547// yield put({ type: 'SET_LOADER', payload: false });548// if (response.data && response.data.code === 200) {549// yield put({ type: 'SET_FEED_IMAGES', payload: response.data.response });550// } else if (response.data && response.data.code === 404) {551// // yield put({ type: 'SET_MESSAGE', payload: response.data.response });552// } else {553// // yield put({ type: 'SET_MESSAGE', payload: response.data.response });554// }555// } else {556// yield put({ type: 'SET_LOADER', payload: false });557// // yield put({ type: 'SET_MESSAGE', payload: response.statusText });558// }559// } catch (error) {560// yield put({ type: 'SET_LOADER', payload: false });561// console.log('error: ', error);562// const checkStatus = utils.checkAPIfailure(error);563// console.log(checkStatus);564// if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {565// // change funcName to the current function name so that it gets called back566// const params = {567// funcName: getFeedImages,568// params: request569// };570// yield call(refreshTokenFunc, params);571// } else {572// console.log('Network Err! or Internal Server Err!');573// }574// // yield put({ type: 'SET_MESSAGE', payload: error });575// }576// }577function* refreshTokenFunc(params) {578 console.log(`inside saga refresh token func ::: ${params}`);579 console.log(params);580 const signinData = yield select(getSigninData); // get the redux object581 const signinPayloads = {582 refreshToken: signinData.token.AuthenticationResult.RefreshToken,583 grant_type: 'REFRESH_TOKEN'584 };585 yield put({ type: 'SET_LOADING', payload: false });586 try {587 const response = yield call(api.signin, signinPayloads);588 const refreshRes = utils.checkAPIfailure(response);589 if (refreshRes.hasOwnProperty('success') && refreshRes.success === true) {590 const updatedSigninData = {591 groups: signinData.groups,592 token: {593 AuthenticationResult: {594 ExpiresIn: refreshRes.token.AuthenticationResult.ExpiresIn,595 IdToken: refreshRes.token.AuthenticationResult.IdToken,596 RefreshToken: signinData.token.AuthenticationResult.RefreshToken,597 TokenType: refreshRes.token.AuthenticationResult.TokenType,598 AccessToken: refreshRes.token.AuthenticationResult.AccessToken599 }600 },601 user: signinData.user602 };603 yield put({ type: 'SIGNIN_SUCCESS', signinData: updatedSigninData });604 yield call(params.funcName, params.params); // call the fucntion (saga func) where it got expired!605 } else {606 yield put({ type: 'LOGOUT_SUCCESS' });607 // window.localStorage.clear();608 window.localStorage.removeItem('notification');609 window.localStorage.removeItem('notifications');610 yield put(push('/user-analyst'));611 }612 } catch (error) {613 console.log(error);614 yield put({ type: 'LOGOUT_SUCCESS' });615 // window.localStorage.clear();616 window.localStorage.removeItem('notification');617 window.localStorage.removeItem('notifications');618 yield put(push('/user-analyst'));619 }620}621function* like(request) {622 const signinData = yield select(getSigninData); // get the redux object623 console.log('like!!!', request);624 let payload = '';625 try {626 if (request.payload.type === 'images') {627 payload = {628 image_id: request.payload.image_id,629 type: request.payload.type,630 accesstoken: signinData.token.AuthenticationResult.AccessToken631 };632 } else if (request.payload.type === 'videos') {633 payload = {634 video_id: request.payload.video_id,635 type: request.payload.type,636 accesstoken: signinData.token.AuthenticationResult.AccessToken637 };638 } else {639 payload = {640 link_id: request.payload.link_id,641 type: request.payload.type,642 accesstoken: signinData.token.AuthenticationResult.AccessToken643 };644 }645 // const payload = { image_id: request.payload.image_id, type: request.payload.type, accesstoken: signinData.token.AuthenticationResult.AccessToken };646 const likeRes = yield call(api.like, payload);647 const checkStatus = utils.checkAPIfailure(likeRes);648 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {649 // do nothing!650 } else {651 console.log('failed like');652 }653 } catch (error) {654 console.log('error: ', error);655 const checkStatus = utils.checkAPIfailure(error);656 console.log(checkStatus);657 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {658 // change funcName to the current function name so that it gets called back659 const params = {660 funcName: like,661 params: request662 };663 yield call(refreshTokenFunc, params);664 } else if (665 checkStatus.Error &&666 checkStatus.Error.Message &&667 checkStatus.Error.Message === 'Access Token has been revoked'668 ) {669 yield put({ type: 'LOGOUT_SUCCESS' });670 // window.localStorage.clear();671 window.localStorage.removeItem('notification');672 window.localStorage.removeItem('notifications');673 yield put(push('/user-analyst'));674 } else {675 console.log('Network Err! or Internal Server Err!');676 }677 // yield put({ type: 'SET_MESSAGE', payload: error });678 }679}680function* unLike(request) {681 const signinData = yield select(getSigninData); // get the redux object682 console.log('unlike', request);683 let payload = '';684 try {685 if (request.payload.type === 'images') {686 payload = {687 image_id: request.payload.image_id,688 type: request.payload.type,689 accesstoken: signinData.token.AuthenticationResult.AccessToken690 };691 } else if (request.payload.type === 'videos') {692 payload = {693 video_id: request.payload.video_id,694 type: request.payload.type,695 accesstoken: signinData.token.AuthenticationResult.AccessToken696 };697 } else {698 payload = {699 link_id: request.payload.link_id,700 type: request.payload.type,701 accesstoken: signinData.token.AuthenticationResult.AccessToken702 };703 }704 // const payload = { image_id: request.payload.image_id, type: request.payload.type, accesstoken: signinData.token.AuthenticationResult.AccessToken };705 const unLikeRes = yield call(api.unlike, payload, signinData.token.AuthenticationResult.AccessToken);706 const checkStatus = utils.checkAPIfailure(unLikeRes);707 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {708 // do nothing!709 } else {710 console.log('failed unlike');711 }712 } catch (error) {713 console.log('error: ', error);714 const checkStatus = utils.checkAPIfailure(error);715 console.log(checkStatus);716 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {717 // change funcName to the current function name so that it gets called back718 const params = {719 funcName: unLike,720 params: request721 };722 yield call(refreshTokenFunc, params);723 } else if (724 checkStatus.Error &&725 checkStatus.Error.Message &&726 checkStatus.Error.Message === 'Access Token has been revoked'727 ) {728 yield put({ type: 'LOGOUT_SUCCESS' });729 // window.localStorage.clear();730 window.localStorage.removeItem('notification');731 window.localStorage.removeItem('notifications');732 yield put(push('/user-analyst'));733 } else {734 console.log('Network Err! or Internal Server Err!');735 }736 // yield put({ type: 'SET_MESSAGE', payload: error });737 }738}739function* getComments(request) {740 const signinData = yield select(getSigninData); // get the redux object741 // yield put({ type: 'SET_LOADER', payload: true });742 let payload = '';743 try {744 if (request.payload.type === 'images') {745 payload = {746 imageId: request.payload.image_id,747 type: request.payload.type,748 url: `/api/feed/images/comments?image_id=${request.payload.image_id}`,749 accesstoken: signinData.token.AuthenticationResult.AccessToken750 };751 } else if (request.payload.type === 'videos') {752 payload = {753 videoId: request.payload.video_id,754 type: request.payload.type,755 url: `/api/feed/videos/comments?video_id=${request.payload.video_id}`,756 accesstoken: signinData.token.AuthenticationResult.AccessToken757 };758 } else {759 payload = {760 linkId: request.payload.link_id,761 type: request.payload.type,762 url: `/api/feed/links/comments?link_id=${request.payload.link_id}`,763 accesstoken: signinData.token.AuthenticationResult.AccessToken764 };765 }766 console.log(payload);767 // const payload = { imageId: request.payload.image_id, type: request.payload.type, accesstoken: signinData.token.AuthenticationResult.AccessToken };768 const response = yield call(api.getComments, payload);769 console.log('response', response);770 if (response.status === 200) {771 // yield put({ type: 'SET_LOADER', payload: false });772 if (response.data && response.data.code === 200) {773 yield put({ type: 'SET_COMMENTS', payload: response.data.response });774 } else if (response.data && response.data.code === 404) {775 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });776 } else {777 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });778 }779 } else {780 // yield put({ type: 'SET_LOADER', payload: false });781 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });782 }783 } catch (error) {784 // yield put({ type: 'SET_LOADER', payload: false });785 console.log('error: ', error);786 const checkStatus = utils.checkAPIfailure(error);787 console.log(checkStatus);788 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {789 // change funcName to the current function name so that it gets called back790 const params = {791 funcName: getComments,792 params: request793 };794 yield call(refreshTokenFunc, params);795 } else if (796 checkStatus.Error &&797 checkStatus.Error.Message &&798 checkStatus.Error.Message === 'Access Token has been revoked'799 ) {800 yield put({ type: 'LOGOUT_SUCCESS' });801 // window.localStorage.clear();802 window.localStorage.removeItem('notification');803 window.localStorage.removeItem('notifications');804 yield put(push('/user-analyst'));805 } else {806 console.log('Network Err! or Internal Server Err!');807 }808 // yield put({ type: 'SET_MESSAGE', payload: error });809 }810}811function* postComment(request) {812 const signinData = yield select(getSigninData); // get the redux object813 // yield put({ type: 'SET_LOADER', payload: true });814 let payload = '';815 try {816 if (request.payload.type === 'images') {817 payload = {818 image_id: request.payload.image_id,819 comment: request.payload.comment,820 type: request.payload.type,821 url: `/api/feed/images/comments`,822 accesstoken: signinData.token.AuthenticationResult.AccessToken823 };824 } else if (request.payload.type === 'videos') {825 payload = {826 video_id: request.payload.video_id,827 comment: request.payload.comment,828 type: request.payload.type,829 url: `/api/feed/videos/comments`,830 accesstoken: signinData.token.AuthenticationResult.AccessToken831 };832 } else {833 payload = {834 link_id: request.payload.link_id,835 comment: request.payload.comment,836 type: request.payload.type,837 url: `/api/feed/links/comments`,838 accesstoken: signinData.token.AuthenticationResult.AccessToken839 };840 }841 // const payload = {842 // image_id: request.payload.image_id,843 // comment: request.payload.comment,844 // accesstoken: signinData.token.AuthenticationResult.AccessToken845 // };846 const response = yield call(api.postComment, payload);847 console.log('response', response);848 if (response.status === 200) {849 console.log('success!!');850 // yield put({ type: 'SET_LOADER', payload: false });851 if (response.data && response.data.code === 200) {852 console.log('comment posted !');853 } else if (response.data && response.data.code === 404) {854 console.log('comment posted err 404!');855 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });856 } else {857 console.log('comment not posted ! no success');858 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });859 }860 } else {861 console.log('comment not posted else !');862 // yield put({ type: 'SET_LOADER', payload: false });863 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });864 }865 } catch (error) {866 // yield put({ type: 'SET_LOADER', payload: false });867 console.log('error: ', error);868 const checkStatus = utils.checkAPIfailure(error);869 console.log(checkStatus);870 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {871 // change funcName to the current function name so that it gets called back872 const params = {873 funcName: postComment,874 params: request875 };876 yield call(refreshTokenFunc, params);877 } else if (878 checkStatus.Error &&879 checkStatus.Error.Message &&880 checkStatus.Error.Message === 'Access Token has been revoked'881 ) {882 yield put({ type: 'LOGOUT_SUCCESS' });883 // window.localStorage.clear();884 window.localStorage.removeItem('notification');885 window.localStorage.removeItem('notifications');886 yield put(push('/user-analyst'));887 } else {888 console.log('Network Err! or Internal Server Err!');889 }890 // yield put({ type: 'SET_MESSAGE', payload: error });891 }892}893function* getSubscriptions(request) {894 const signinData = yield select(getSigninData); // get the redux object895 yield put({ type: 'SET_LOADER', payload: true });896 try {897 const response = yield call(api.getSubscriptions, signinData.token.AuthenticationResult.AccessToken);898 console.log('response', response);899 if (response.status === 200) {900 yield put({ type: 'SET_LOADER', payload: false });901 if (response.data && response.data.code === 200) {902 yield put({ type: 'SET_SUBSCRIPTION', payload: response.data.response });903 } else if (response.data && response.data.code === 404) {904 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });905 } else {906 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });907 }908 } else {909 yield put({ type: 'SET_LOADER', payload: false });910 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });911 }912 } catch (error) {913 yield put({ type: 'SET_LOADER', payload: false });914 console.log('error: ', error);915 const checkStatus = utils.checkAPIfailure(error);916 console.log(checkStatus);917 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {918 // change funcName to the current function name so that it gets called back919 const params = {920 funcName: getSubscriptions,921 params: request922 };923 yield call(refreshTokenFunc, params);924 } else if (925 checkStatus.Error &&926 checkStatus.Error.Message &&927 checkStatus.Error.Message === 'Access Token has been revoked'928 ) {929 yield put({ type: 'LOGOUT_SUCCESS' });930 // window.localStorage.clear();931 window.localStorage.removeItem('notification');932 window.localStorage.removeItem('notifications');933 yield put(push('/user-analyst'));934 } else {935 console.log('Network Err! or Internal Server Err!');936 }937 // yield put({ type: 'SET_MESSAGE', payload: error });938 }939}940function* get_preferences_worker(request) {941 let signinData = yield select(getSigninData);942 let token = signinData.token.AuthenticationResult.AccessToken;943 console.log('inside get_preferences');944 try {945 const response = yield call(api.getPreferences, token);946 const refreshResponse = utils.checkAPIfailure(response);947 if (refreshResponse.code === 200) {948 yield put({ type: 'GET_PREFERENCES_SUCCESS', preferences: refreshResponse.response });949 }950 } catch (error) {951 console.log('Error in get preferences', error);952 const checkStatus = utils.checkAPIfailure(error);953 console.log(checkStatus);954 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {955 // change funcName to the current function name so that it gets called back956 const params = {957 funcName: get_preferences_worker,958 params: request959 };960 yield call(refreshTokenFunc, params);961 } else if (962 checkStatus.Error &&963 checkStatus.Error.Message &&964 checkStatus.Error.Message === 'Access Token has been revoked'965 ) {966 yield put({ type: 'LOGOUT_SUCCESS' });967 // window.localStorage.clear();968 window.localStorage.removeItem('notification');969 window.localStorage.removeItem('notifications');970 yield put(push('/user-analyst'));971 }972 }973}974function* set_preferences_worker(request) {975 const params = request.payload;976 const url = request.url;977 const signinData = yield select(getSigninData);978 const token = signinData.token.AuthenticationResult.AccessToken;979 const payload = {980 params,981 token982 };983 try {984 const response = yield call(api.setPreferences, payload);985 const refreshResponse = utils.checkAPIfailure(response);986 if (refreshResponse.code === 200) {987 yield put({ type: 'SET_PREFERENCES_SUCCESS', newPreferences: payload.params.selected_preference_ids });988 yield put(push(url));989 }990 // yield put({type: 'SET_PREFERENCES_SUCCESS', newPreferences: payload.params.selected_preference_ids})991 } catch (error) {992 console.log('Error in set preferences', error);993 const checkStatus = utils.checkAPIfailure(error);994 console.log(checkStatus);995 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {996 // change funcName to the current function name so that it gets called back997 const params = {998 funcName: set_preferences_worker,999 params: request1000 };1001 yield call(refreshTokenFunc, params);1002 } else if (1003 checkStatus.Error &&1004 checkStatus.Error.Message &&1005 checkStatus.Error.Message === 'Access Token has been revoked'1006 ) {1007 yield put({ type: 'LOGOUT_SUCCESS' });1008 // window.localStorage.clear();1009 window.localStorage.removeItem('notification');1010 window.localStorage.removeItem('notifications');1011 yield put(push('/user-analyst'));1012 }1013 }1014}1015function* setKycDetails(request) {1016 const signinData = yield select(getSigninData); // get the redux object1017 console.log(request);1018 let KYCPayload = request.KYCPayload;1019 console.log(KYCPayload);1020 try {1021 const response = yield call(api.updateUserName, KYCPayload);1022 console.log('KYC response', response);1023 if (response.status === 200) {1024 if (response.data && response.data.success) {1025 yield put({ type: 'SET_KYC_DETAILS_SUCCESS', payload: KYCPayload.UserAttributes });1026 }1027 }1028 } catch (error) {1029 console.log('error: ', error);1030 const checkStatus = utils.checkAPIfailure(error);1031 console.log(checkStatus);1032 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1033 // change funcName to the current function name so that it gets called back1034 const params = {1035 funcName: setKycDetails,1036 params: request1037 };1038 yield call(refreshTokenFunc, params);1039 } else if (1040 checkStatus.Error &&1041 checkStatus.Error.Message &&1042 checkStatus.Error.Message === 'Access Token has been revoked'1043 ) {1044 yield put({ type: 'LOGOUT_SUCCESS' });1045 // window.localStorage.clear();1046 window.localStorage.removeItem('notification');1047 window.localStorage.removeItem('notifications');1048 yield put(push('/user-analyst'));1049 } else {1050 console.log('Network Err! or Internal Server Err!');1051 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1052 //yield put({ type: 'SET_LOADER', payload: false });1053 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1054 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1055 }1056 }1057}1058function* getRiskProfileQuestions(request) {1059 console.log(request);1060 let url = '/api/investor/risk-profiling';1061 let signinData = yield select(getSigninData);1062 let AccessToken = signinData.token.AuthenticationResult.AccessToken;1063 try {1064 let response = yield call(api.getRiskProfileQuestions, AccessToken);1065 console.log('questions', response);1066 const refreshResponse = utils.checkAPIfailure(response);1067 if (refreshResponse.code === 200) {1068 yield put({ type: 'GET_RISK_PROFILE_QUESTIONS_SUCCESS', questions: refreshResponse.response });1069 }1070 } catch (error) {1071 console.log('error ', error);1072 const checkStatus = utils.checkAPIfailure(error);1073 console.log(checkStatus);1074 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1075 // change funcName to the current function name so that it gets called back1076 const params = {1077 funcName: getRiskProfileQuestions,1078 params: request1079 };1080 yield call(refreshTokenFunc, params);1081 } else if (1082 checkStatus.Error &&1083 checkStatus.Error.Message &&1084 checkStatus.Error.Message === 'Access Token has been revoked'1085 ) {1086 yield put({ type: 'LOGOUT_SUCCESS' });1087 // window.localStorage.clear();1088 window.localStorage.removeItem('notification');1089 window.localStorage.removeItem('notifications');1090 yield put(push('/user-analyst'));1091 } else {1092 console.log('Network Err! or Internal Server Err!');1093 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1094 //yield put({ type: 'SET_LOADER', payload: false });1095 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1096 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1097 }1098 }1099}1100function* sendRiskProfileAnswers(request) {1101 let url = request.url;1102 let payload = request.payload;1103 let signinData = yield select(getSigninData);1104 let token = signinData.token.AuthenticationResult.AccessToken;1105 try {1106 let response = yield call(api.sendRiskProfileAnswers, url, payload, token);1107 const refreshResponse = utils.checkAPIfailure(response);1108 if (refreshResponse.code === 200) {1109 yield put({ type: 'SEND_RISK_PROFILE_ANSWERS_SUCCESS', answers: payload.risk_profiling });1110 yield put({ type: 'GET_RISK_PROFILING_SCORE_SUCCESS', score: refreshResponse.risk_profiling_score });1111 }1112 } catch (error) {1113 console.log('error ', error);1114 const checkStatus = utils.checkAPIfailure(error);1115 console.log(checkStatus);1116 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1117 // change funcName to the current function name so that it gets called back1118 const params = {1119 funcName: sendRiskProfileAnswers,1120 params: request1121 };1122 yield call(refreshTokenFunc, params);1123 } else if (1124 checkStatus.Error &&1125 checkStatus.Error.Message &&1126 checkStatus.Error.Message === 'Access Token has been revoked'1127 ) {1128 yield put({ type: 'LOGOUT_SUCCESS' });1129 // window.localStorage.clear();1130 window.localStorage.removeItem('notification');1131 window.localStorage.removeItem('notifications');1132 yield put(push('/user-analyst'));1133 } else {1134 console.log('Network Err! or Internal Server Err!');1135 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1136 //yield put({ type: 'SET_LOADER', payload: false });1137 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1138 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1139 }1140 }1141}1142function* allow_trade_entry(request) {1143 const signinData = yield select(getSigninData); // get the redux object1144 try {1145 const payload = { ...request.payload, token: signinData.token.AuthenticationResult.AccessToken };1146 const response = yield call(api.allowTradeEntry, payload);1147 console.log('response', response);1148 if (response.status === 200) {1149 if (response.data && response.data.code === 200) {1150 yield put({ type: 'SET_ALLOW_ENTRY', payload: response.data.response.allow_entry });1151 }1152 } else if (response.code === 400) {1153 yield put({ type: 'SET_MESSAGE', payload: response.response });1154 } else {1155 yield put({ type: 'SET_MESSAGE', payload: response.statusText });1156 }1157 } catch (error) {1158 console.log('error: ', error);1159 const checkStatus = utils.checkAPIfailure(error);1160 console.log(checkStatus);1161 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1162 // change funcName to the current function name so that it gets called back1163 const params = {1164 funcName: allow_trade_entry,1165 params: request1166 };1167 yield call(refreshTokenFunc, params);1168 } else if (1169 checkStatus.Error &&1170 checkStatus.Error.Message &&1171 checkStatus.Error.Message === 'Access Token has been revoked'1172 ) {1173 yield put({ type: 'LOGOUT_SUCCESS' });1174 // window.localStorage.clear();1175 window.localStorage.removeItem('notification');1176 window.localStorage.removeItem('notifications');1177 yield put(push('/user-analyst'));1178 } else {1179 console.log('Network Err! or Internal Server Err!');1180 }1181 }1182}1183function* getReferralCode(request) {1184 const signinData = yield select(getSigninData);1185 try {1186 const token = signinData.token.AuthenticationResult.AccessToken;1187 const response = yield call(api.getReferralCode, token);1188 const checkResponse = utils.checkAPIfailure(response);1189 if (checkResponse.code === 200) {1190 console.log(checkResponse);1191 yield put({ type: 'SET_REFERRAL_CODE', referral_code: checkResponse.response.referral_code });1192 }1193 } catch (error) {1194 console.log('error ', error);1195 const checkStatus = utils.checkAPIfailure(error);1196 console.log(checkStatus);1197 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1198 // change funcName to the current function name so that it gets called back1199 const params = {1200 funcName: getReferralCode,1201 params: request1202 };1203 yield call(refreshTokenFunc, params);1204 } else if (1205 checkStatus.Error &&1206 checkStatus.Error.Message &&1207 checkStatus.Error.Message === 'Access Token has been revoked'1208 ) {1209 yield put({ type: 'LOGOUT_SUCCESS' });1210 // window.localStorage.clear();1211 window.localStorage.removeItem('notification');1212 window.localStorage.removeItem('notifications');1213 yield put(push('/user-analyst'));1214 } else {1215 console.log('Network Err! or Internal Server Err!');1216 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1217 //yield put({ type: 'SET_LOADER', payload: false });1218 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1219 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1220 }1221 }1222}1223function* checkReferralCode(request) {1224 console.log('============', request.payload);1225 const payload = request.payload;1226 const signinData = yield select(getSigninData);1227 try {1228 const token = signinData.token.AuthenticationResult.AccessToken;1229 const response = yield call(api.checkReferralCode, payload, token);1230 const checkResponse = utils.checkAPIfailure(response);1231 if (checkResponse.response) {1232 yield put({ type: 'SET_MESSAGE', payload: 'Referral Code Successfull' });1233 yield put({ type: 'SET_REFERRAL_VERIFICATION', verified: true, referredBy: checkResponse.response.referred_by })1234 } else {1235 yield put({ type: 'REFERRAL_FAILED' });1236 }1237 } catch (error) {1238 console.log('error ', error);1239 const checkStatus = utils.checkAPIfailure(error);1240 console.log(checkStatus);1241 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1242 // change funcName to the current function name so that it gets called back1243 const params = {1244 funcName: checkReferralCode,1245 params: request1246 };1247 yield call(refreshTokenFunc, params);1248 } else if (1249 checkStatus.Error &&1250 checkStatus.Error.Message &&1251 checkStatus.Error.Message === 'Access Token has been revoked'1252 ) {1253 yield put({ type: 'LOGOUT_SUCCESS' });1254 // window.localStorage.clear();1255 window.localStorage.removeItem('notification');1256 window.localStorage.removeItem('notifications');1257 yield put(push('/user-analyst'));1258 } else {1259 console.log('Network Err! or Internal Server Err!');1260 yield put({ type: 'SET_MESSAGE', payload: 'Invalid Referral Code' });1261 //yield put({ type: 'SET_LOADER', payload: false });1262 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1263 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1264 }1265 }1266}1267function* getBlogListDesktopSaga(request){1268 const signinData = yield select(getSigninData)1269 try{1270 const token = signinData ? signinData.token.AuthenticationResult.AccessToken : null1271 const response = yield call(api.getBlogListDesktop, token)1272 const checkResponse = utils.checkAPIfailure(response);1273 if (checkResponse.code === 200) {1274 console.log('======',checkResponse)1275 yield put({ type: 'SET_BLOG_LIST_DESKTOP', payload: checkResponse.response });1276 }1277 } catch (error) {1278 console.log('error ', error);1279 const checkStatus = utils.checkAPIfailure(error);1280 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1281 // change funcName to the current function name so that it gets called back1282 const params = {1283 funcName: getBlogListDesktopSaga,1284 params: request1285 };1286 yield call(refreshTokenFunc, params);1287 } else if (1288 checkStatus.Error &&1289 checkStatus.Error.Message &&1290 checkStatus.Error.Message === 'Access Token has been revoked'1291 ) {1292 yield put({ type: 'LOGOUT_SUCCESS' });1293 // window.localStorage.clear();1294 window.localStorage.removeItem('notification');1295 window.localStorage.removeItem('notifications');1296 yield put(push('/user-analyst'));1297 } else {1298 console.log('Network Err! or Internal Server Err!');1299 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1300 //yield put({ type: 'SET_LOADER', payload: false });1301 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1302 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1303 }1304 }1305} 1306function* getReferredBy(request) {1307 const signinData = yield select(getSigninData);1308 try {1309 const token = signinData.token.AuthenticationResult.AccessToken;1310 const response = yield call(api.getReferredBy, token);1311 const checkResponse = utils.checkAPIfailure(response);1312 if (checkResponse.code === 200) {1313 console.log(checkResponse);1314 yield put({ type: 'SET_REFERRED_BY', referred_by: checkResponse.response.referred_by });1315 }1316 } catch (error) {1317 console.log('error ', error);1318 const checkStatus = utils.checkAPIfailure(error);1319 console.log(checkStatus);1320 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1321 // change funcName to the current function name so that it gets called back1322 const params = {1323 funcName: getReferredBy,1324 params: request1325 };1326 yield call(refreshTokenFunc, params);1327 } else if (1328 checkStatus.Error &&1329 checkStatus.Error.Message &&1330 checkStatus.Error.Message === 'Access Token has been revoked'1331 ) {1332 yield put({ type: 'LOGOUT_SUCCESS' });1333 // window.localStorage.clear();1334 window.localStorage.removeItem('notification');1335 window.localStorage.removeItem('notifications');1336 yield put(push('/user-analyst'));1337 } else {1338 console.log('Network Err! or Internal Server Err!');1339 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1340 //yield put({ type: 'SET_LOADER', payload: false });1341 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1342 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1343 }1344 }1345}1346function* getBlogListSaga(request){1347 const signinData = yield select(getSigninData);1348 try {1349 const token = signinData ? signinData.token.AuthenticationResult.AccessToken : null;1350 const response = yield call(api.getBlogList, token);1351 const checkResponse = utils.checkAPIfailure(response);1352 if (checkResponse.code === 200) {1353 console.log(checkResponse);1354 yield put({ type: 'SET_BLOG_LIST', blogList: checkResponse.response });1355 }1356 } catch (error) {1357 console.log('error ', error);1358 const checkStatus = utils.checkAPIfailure(error);1359 console.log(checkStatus);1360 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1361 // change funcName to the current function name so that it gets called back1362 const params = {1363 funcName: getBlogListSaga,1364 params: request1365 };1366 yield call(refreshTokenFunc, params);1367 } else if (1368 checkStatus.Error &&1369 checkStatus.Error.Message &&1370 checkStatus.Error.Message === 'Access Token has been revoked'1371 ) {1372 yield put({ type: 'LOGOUT_SUCCESS' });1373 // window.localStorage.clear();1374 window.localStorage.removeItem('notification');1375 window.localStorage.removeItem('notifications');1376 yield put(push('/user-analyst'));1377 } else {1378 console.log('Network Err! or Internal Server Err!');1379 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1380 //yield put({ type: 'SET_LOADER', payload: false });1381 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1382 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1383 }1384 }1385}1386function* getBlogDetailSaga(request){1387 const signinData = yield select(getSigninData);1388 try {1389 const token = signinData ? signinData.token.AuthenticationResult.AccessToken : null;1390 const response = yield call(api.getBlogDetail, token, request.id);1391 const checkResponse = utils.checkAPIfailure(response);1392 if (checkResponse.code === 200) {1393 console.log(checkResponse);1394 yield put({ type: 'SET_BLOG_DETAIL', blogDetail: checkResponse.response });1395 }1396 } catch (error) {1397 console.log('error ', error);1398 const checkStatus = utils.checkAPIfailure(error);1399 console.log(checkStatus);1400 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1401 // change funcName to the current function name so that it gets called back1402 const params = {1403 funcName: getBlogDetailSaga,1404 params: request1405 };1406 yield call(refreshTokenFunc, params);1407 } else if (1408 checkStatus.Error &&1409 checkStatus.Error.Message &&1410 checkStatus.Error.Message === 'Access Token has been revoked'1411 ) {1412 yield put({ type: 'LOGOUT_SUCCESS' });1413 // window.localStorage.clear();1414 window.localStorage.removeItem('notification');1415 window.localStorage.removeItem('notifications');1416 yield put(push('/user-analyst'));1417 } else {1418 console.log('Network Err! or Internal Server Err!');1419 yield put({ type: 'SET_BLOG_MESSAGE', payload: 'Invalid Url' });1420 //yield put({ type: 'SET_LOADER', payload: false });1421 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1422 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1423 }1424 }1425}1426function* getBlogCommentsSaga(request){1427 const signinData = yield select(getSigninData);1428 try {1429 const token = signinData ? signinData.token.AuthenticationResult.AccessToken : null;1430 const response = yield call(api.getBlogComments, token, request.id);1431 const checkResponse = utils.checkAPIfailure(response);1432 if (checkResponse.code === 200) {1433 console.log(checkResponse);1434 yield put({ type: 'SET_BLOG_COMMENTS', blogComments: checkResponse.response });1435 }1436 } catch (error) {1437 console.log('error ', error);1438 const checkStatus = utils.checkAPIfailure(error);1439 console.log(checkStatus);1440 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1441 // change funcName to the current function name so that it gets called back1442 const params = {1443 funcName: getBlogCommentsSaga,1444 params: request1445 };1446 yield call(refreshTokenFunc, params);1447 } else if (1448 checkStatus.Error &&1449 checkStatus.Error.Message &&1450 checkStatus.Error.Message === 'Access Token has been revoked'1451 ) {1452 yield put({ type: 'LOGOUT_SUCCESS' });1453 // window.localStorage.clear();1454 window.localStorage.removeItem('notification');1455 window.localStorage.removeItem('notifications');1456 yield put(push('/user-analyst'));1457 } else {1458 console.log('Network Err! or Internal Server Err!');1459 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1460 //yield put({ type: 'SET_LOADER', payload: false });1461 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1462 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1463 }1464 }1465}1466function* sendBlogCommentSaga(request){1467 const signinData = yield select(getSigninData);1468 try {1469 const token = signinData.token.AuthenticationResult.AccessToken;1470 const response = yield call(api.sendBlogComment,request.payload, request.id, token);1471 const checkResponse = utils.checkAPIfailure(response);1472 if (checkResponse.code === 200) {1473 console.log(checkResponse);1474 yield put({ type: 'SEND_BLOG_COMMENT_SUCCESS'});1475 yield call(getBlogCommentsSaga, request)1476 }1477 } catch (error) {1478 console.log('error ', error);1479 const checkStatus = utils.checkAPIfailure(error);1480 console.log(checkStatus);1481 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1482 // change funcName to the current function name so that it gets called back1483 const params = {1484 funcName: sendBlogCommentSaga,1485 params: request1486 };1487 yield call(refreshTokenFunc, params);1488 } else if (1489 checkStatus.Error &&1490 checkStatus.Error.Message &&1491 checkStatus.Error.Message === 'Access Token has been revoked'1492 ) {1493 yield put({ type: 'LOGOUT_SUCCESS' });1494 // window.localStorage.clear();1495 window.localStorage.removeItem('notification');1496 window.localStorage.removeItem('notifications');1497 yield put(push('/user-analyst'));1498 } else {1499 console.log('Network Err! or Internal Server Err!');1500 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1501 //yield put({ type: 'SET_LOADER', payload: false });1502 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1503 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1504 }1505 }1506}1507function* toggleBlogLikeSaga(request){1508 const signinData = yield select(getSigninData);1509 try {1510 const token = signinData.token.AuthenticationResult.AccessToken;1511 const response = yield call(api.toggleBlogLike,request.payload, token);1512 const checkResponse = utils.checkAPIfailure(response);1513 if (checkResponse.code === 200) {1514 console.log(checkResponse);1515 if(request.payload.like) yield put({ type: 'BLOG_LIKE_SUCCESS'});1516 else yield put({ type: 'BLOG_UNLIKE_SUCCESS'});1517 }1518 } catch (error) {1519 console.log('error ', error);1520 const checkStatus = utils.checkAPIfailure(error);1521 console.log(checkStatus);1522 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {1523 // change funcName to the current function name so that it gets called back1524 const params = {1525 funcName: sendBlogCommentSaga,1526 params: request1527 };1528 yield call(refreshTokenFunc, params);1529 } else if (1530 checkStatus.Error &&1531 checkStatus.Error.Message &&1532 checkStatus.Error.Message === 'Access Token has been revoked'1533 ) {1534 yield put({ type: 'LOGOUT_SUCCESS' });1535 // window.localStorage.clear();1536 window.localStorage.removeItem('notification');1537 window.localStorage.removeItem('notifications');1538 yield put(push('/user-analyst'));1539 } else {1540 console.log('Network Err! or Internal Server Err!');1541 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });1542 //yield put({ type: 'SET_LOADER', payload: false });1543 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });1544 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });1545 }1546 }1547}1548export default function* watchAll() {1549 return (1550 yield takeEvery('FETCH_ANALYSTS_FOR_SUBSCRIPTION', fetch_analysts_for_subscriptions),1551 yield takeEvery('FETCH_PERFORMANCE_AND_TRANSACTIONS_DATA', fetch_performance_and_transactions_data),1552 yield takeEvery('FETCH_USER_CARDS', fetch_user_cards),1553 yield takeEvery('FETCH_ALL_WEBINARS', fetch_all_webinars),1554 yield takeEvery('GET_ANALYST_SUBSCRIPTION_PLAN', getAnalystSubscriptionPlan),1555 yield takeEvery('GET_PAYMENT_SUBSCRIPTION_LINK', getPaymentSubscriptionLink),1556 yield takeEvery('GET_RECENTLY_CLOSED_TRADES', getRecentlyClosedTrades),1557 yield takeEvery('UNFOLLOW', unfollow),1558 yield takeEvery('FOLLOW', follow),1559 yield takeEvery('LIKE', like),1560 yield takeEvery('UNLIKE', unLike),1561 yield takeEvery('GET_FEED', getFeed),1562 yield takeEvery('GET_SUB_FEED', getSubFeed),1563 // yield takeEvery('GET_FEED_IMAGES', getFeedImages),1564 yield takeEvery('GET_COMMENTS', getComments),1565 yield takeEvery('POST_COMMENT', postComment),1566 yield takeEvery('GET_SUBSCRIPTION', getSubscriptions),1567 yield takeEvery('GET_PREFERENCES', get_preferences_worker),1568 yield takeEvery('SET_PREFERENCES', set_preferences_worker),1569 yield takeEvery('SET_KYC_DETAILS', setKycDetails),1570 yield takeEvery('GET_RISK_PROFILE_QUESTIONS', getRiskProfileQuestions),1571 yield takeEvery('SEND_RISK_PROFILE_ANSWERS', sendRiskProfileAnswers),1572 yield takeEvery('ALLOW_ENTRY', allow_trade_entry),1573 yield takeEvery('GET_REFERRAL_CODE', getReferralCode),1574 yield takeEvery('CHECK_REFERRAL_CODE', checkReferralCode),1575 yield takeEvery('GET_BLOG_LIST_DESKTOP', getBlogListDesktopSaga),1576 yield takeEvery('GET_REFERRED_BY', getReferredBy),1577 yield takeEvery('GET_BLOG_LIST', getBlogListSaga),1578 yield takeEvery('GET_BLOG_DETAIL', getBlogDetailSaga),1579 yield takeEvery('GET_BLOG_COMMENTS', getBlogCommentsSaga),1580 yield takeEvery('SEND_BLOG_COMMENT', sendBlogCommentSaga),1581 yield takeEvery('TOGGLE_BLOG_LIKE', toggleBlogLikeSaga)1582 );...

Full Screen

Full Screen

auth.js

Source:auth.js Github

copy

Full Screen

1import { call, put, takeEvery, takeLatest, select } from 'redux-saga/effects';2import { push } from 'connected-react-router/immutable';3import api from '../../network';4import utils from '../../theme/utils';5export const getSigninData = state => state.auth.signinData;6// ********** USER AUTH******************* //7function* user_auth_worker(request) {8 const signinData = yield select(getSigninData); // get the redux object9 const { userAuthPayloads, userAuthPath } = request;10 yield put({ type: 'USER_AUTH_START' });11 try {12 const response = yield call(api.userAuth, userAuthPayloads);13 const checkStatus = utils.checkAPIfailure(response);14 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {15 yield put({ type: 'USER_AUTH_SUCCESS', userAuthData: checkStatus });16 yield put({ type: 'SWITCH_TO_OTP', payload: true });17 if (userAuthPath) {18 yield put(push({ pathname: userAuthPath, state: { detail: 'userAuth', userAuthData: checkStatus } }));19 }20 } else {21 yield put({ type: 'SWITCH_TO_OTP', payload: false });22 yield put({ type: 'USER_AUTH_MID', userAuthMessage: checkStatus });23 yield put({ type: 'USER_AUTH_ALERT_SHOW_HIDE_DANGER' });24 }25 } catch (error) {26 const checkStatus = utils.checkAPIfailure(error);27 yield put({ type: 'SWITCH_TO_OTP', payload: false });28 yield put({ type: 'USER_AUTH_FAILURE', userAuthError: checkStatus });29 yield put({ type: 'USER_AUTH_ALERT_SHOW_HIDE_DANGER' });30 }31}32function* user_auth_alert_dismiss_worker(request) {33 const { path } = request;34 yield put(push(path));35}36// **********Sign In******************* //37function* signin_worker(request) {38 const signinData = yield select(getSigninData); // get the redux object39 const { signinPayloads, signinPath } = request;40 yield put({ type: 'SIGNIN_START' });41 console.log('signin data --->', signinPayloads);42 try {43 const response = yield call(api.signin, signinPayloads);44 console.log(`response ------------> `, response);45 const checkStatus = utils.checkAPIfailure(response);46 console.log('check status : ' + checkStatus.hasOwnProperty('groups'));47 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {48 if (checkStatus.hasOwnProperty('groups')) {49 if (checkStatus.groups[0].GroupName === signinPayloads.group) {50 yield put({ type: 'SIGNIN_SUCCESS', signinData: checkStatus });51 yield put(push(signinPath));52 } else {53 console.log('no group or not same group');54 yield put({ type: 'SIGNIN_FAILURE', signinError: 'User group does not matched the selected group' });55 yield put({ type: 'SIGNIN_ALERT_SHOW_HIDE_DANGER' });56 }57 } else {58 console.log('no group wrong otp');59 console.log(checkStatus);60 yield put({ type: 'SIGNIN_FAILURE', signinError: 'You have entered a wrong verification code!' });61 yield put(push({ pathname: 'verify-otp', state: { detail: 'userAuth', userAuthData: checkStatus } }));62 yield put({ type: 'SIGNIN_ALERT_SHOW_HIDE_DANGER' });63 }64 } else {65 console.log('error mid');66 yield put({ type: 'SIGNIN_MID', signinMessage: checkStatus });67 yield put({ type: 'SIGNIN_ALERT_SHOW_HIDE_DANGER' });68 }69 } catch (error) {70 console.log('singup failure in last catch');71 const checkStatus = utils.checkAPIfailure(error);72 yield put({ type: 'SIGNIN_FAILURE', signinError: checkStatus });73 yield put({ type: 'SIGNIN_ALERT_SHOW_HIDE_DANGER' });74 }75}76// ************* device token ********** //77function* device_token(request) {78 let signinData = yield select(getSigninData); // get the redux object79 let tokenData = localStorage.getItem('deviceToken');80 try {81 let payload = { device_token: JSON.parse(tokenData) };82 const tokenRes = yield call(api.deviceToken, payload, signinData.token.AuthenticationResult.AccessToken);83 const checkStatus = utils.checkAPIfailure(tokenRes);84 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {85 console.log(':::::::SILENTLY UPDATED:::::::::::');86 console.log(tokenRes);87 console.log('::::::::::::::::::::::::::::::::::');88 } else {89 console.log('failed updating device token');90 }91 } catch (error) {92 console.log(error);93 const checkStatus = utils.checkAPIfailure(error);94 console.log(checkStatus);95 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {96 // change funcName to the current function name so that it gets called back97 const params = {98 funcName: device_token,99 params: request100 };101 yield call(refreshTokenFunc, params);102 } else if (103 checkStatus.Error &&104 checkStatus.Error.Message &&105 checkStatus.Error.Message === 'Access Token has been revoked'106 ) {107 yield put({ type: 'LOGOUT_SUCCESS' });108 // window.localStorage.clear();109 window.localStorage.removeItem('notification');110 window.localStorage.removeItem('notifications');111 yield put(push('/user-analyst'));112 } else {113 console.log('Network Err! or Internal Server Err!');114 }115 }116}117// **********Sign Up******************* //118function* signup_worker(request) {119 const signinData = yield select(getSigninData); // get the redux object120 const { signupPayloads, signupPath } = request;121 yield put({ type: 'SIGNUP_START' });122 try {123 const response = yield call(api.signup, signupPayloads);124 const checkStatus = utils.checkAPIfailure(response);125 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {126 yield put({ type: 'SIGNUP_SUCCESS' });127 yield put(128 push({129 pathname: signupPath,130 state: { detail: 'signup', mobilenumber: signupPayloads.UserAttributes[0].Value }131 })132 );133 } else {134 yield put({ type: 'SIGNUP_MID', signupMessage: checkStatus });135 yield put({ type: 'SIGNUP_ALERT_SHOW_HIDE_DANGER' });136 }137 } catch (error) {138 const checkStatus = utils.checkAPIfailure(error);139 yield put({ type: 'SIGNUP_FAILURE', signupError: checkStatus });140 yield put({ type: 'SIGNUP_ALERT_SHOW_HIDE_DANGER' });141 }142}143// **********Verify Otp******************* //144function* verify_otp_worker(request) {145 const signinData = yield select(getSigninData); // get the redux object146 const { verifyOtpPayloads, verifyOtpPath } = request;147 yield put({ type: 'VERIFY_OTP_START' });148 try {149 const response = yield call(api.verifyOtp, verifyOtpPayloads);150 const checkStatus = utils.checkAPIfailure(response);151 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {152 console.log(verifyOtpPath);153 yield put({ type: 'VERIFY_OTP_SUCCESS', verifyOtpData: checkStatus });154 yield put(push({ pathname: verifyOtpPath }));155 } else {156 yield put({ type: 'VERIFY_OTP_MID', verifyOtpMessage: checkStatus });157 yield put({ type: 'VERIFY_OTP_ALERT_SHOW_HIDE_DANGER' });158 }159 } catch (error) {160 const checkStatus = utils.checkAPIfailure(error);161 yield put({ type: 'VERIFY_OTP_FAILURE', verifyOtpError: checkStatus });162 yield put({ type: 'VERIFY_OTP_ALERT_SHOW_HIDE_DANGER' });163 }164}165function* verify_otp_alert_dismiss_worker(request) {166 const { path } = request;167 yield put(push(path));168}169// **********Resend Otp******************* //170function* resend_otp_worker(request) {171 const signinData = yield select(getSigninData); // get the redux object172 const { resendOtpPayloads, resendOtpPath } = request;173 yield put({ type: 'RESEND_OTP_START' });174 try {175 const response = yield call(api.resendOtp, resendOtpPayloads);176 const checkStatus = utils.checkAPIfailure(response);177 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {178 yield put({ type: 'RESEND_OTP_SUCCESS', resendOtpData: checkStatus });179 yield put(push({ pathname: resendOtpPath }));180 } else {181 yield put({ type: 'RESEND_OTP_MID', resendOtpMessage: checkStatus });182 yield put({ type: 'RESEND_OTP_ALERT_SHOW_HIDE_DANGER' });183 }184 } catch (error) {185 const checkStatus = utils.checkAPIfailure(error);186 yield put({ type: 'RESEND_OTP_FAILURE', resendOtpError: checkStatus });187 yield put({ type: 'RESEND_OTP_ALERT_SHOW_HIDE_DANGER' });188 }189}190function* resend_otp_alert_dismiss_worker(request) {191 const { path } = request;192 yield put(push(path));193}194// **********Forgot Password******************* //195function* forgot_password_worker(request) {196 const signinData = yield select(getSigninData); // get the redux object197 const { forgotPasswordPayloads, forgotPasswordPath } = request;198 yield put({ type: 'FORGOT_PASSWORD_START' });199 try {200 const response = yield call(api.forgotPassword, forgotPasswordPayloads);201 const checkStatus = utils.checkAPIfailure(response);202 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {203 yield put({ type: 'FORGOT_PASSWORD_SUCCESS', forgotPasswordData: checkStatus });204 yield put(push({ pathname: forgotPasswordPath, state: { detail: 'forgotpassword' } }));205 } else {206 yield put({ type: 'FORGOT_PASSWORD_MID', forgotPasswordMessage: checkStatus });207 yield put({ type: 'FORGOT_PASSWORD_ALERT_SHOW_HIDE_DANGER' });208 }209 } catch (error) {210 const checkStatus = utils.checkAPIfailure(error);211 yield put({ type: 'FORGOT_PASSWORD_FAILURE', forgotPasswordError: checkStatus });212 yield put({ type: 'FORGOT_PASSWORD_ALERT_SHOW_HIDE_DANGER' });213 }214}215function* forgot_password_alert_dismiss_worker(request) {216 const { path } = request;217 yield put(push(path));218}219// **********Reset Password******************* //220function* reset_password_worker(request) {221 const signinData = yield select(getSigninData); // get the redux object222 const { resetPasswordPayloads, resetPasswordPath } = request;223 yield put({ type: 'RESET_PASSWORD_START' });224 try {225 const response = yield call(api.resetPassword, resetPasswordPayloads);226 const checkStatus = utils.checkAPIfailure(response);227 if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {228 yield put({ type: 'RESET_PASSWORD_SUCCESS', resetPasswordData: checkStatus });229 yield put(push({ pathname: resetPasswordPath }));230 } else {231 yield put({ type: 'RESET_PASSWORD_MID', resetPasswordMessage: checkStatus });232 yield put({ type: 'RESET_PASSWORD_ALERT_SHOW_HIDE_DANGER' });233 }234 } catch (error) {235 const checkStatus = utils.checkAPIfailure(error);236 yield put({ type: 'RESET_PASSWORD_FAILURE', resetPasswordError: checkStatus });237 yield put({ type: 'RESET_PASSWORD_ALERT_SHOW_HIDE_DANGER' });238 }239}240function* reset_password_alert_dismiss_worker(request) {241 const { path } = request;242 yield put(push(path));243}244// **********Log Out******************* //245function* logout_worker(request) {246 // const signinData = yield select(getSigninData); // get the redux object247 const { logoutPath } = request;248 console.log(logoutPath);249 // console.log(logoutPayloads);250 yield put({ type: 'LOGOUT_START' });251 try {252 yield put({ type: 'LOGOUT_SUCCESS' });253 // window.localStorage.clear();254 // window.localStorage.removeItem('notification');255 // window.localStorage.removeItem('notifications');256 window.localStorage.clear();257 yield put(push(logoutPath));258 // const response = yield call(api.logout, logoutPayloads);259 // const checkStatus = utils.checkAPIfailure(response);260 // console.log('___________________++++++++++++++++++' + JSON.stringify(checkStatus));261 // if (checkStatus.hasOwnProperty('success') && checkStatus.success === true) {262 // yield put({ type: 'LOGOUT_SUCCESS', logoutData: checkStatus });263 // yield put(push(logoutPath));264 // } else {265 // yield put({ type: 'LOGOUT_MID', logoutMessage: checkStatus });266 // yield put({ type: 'LOGOUT_ALERT_SHOW_HIDE_DANGER' });267 // }268 } catch (error) {269 const checkStatus = utils.checkAPIfailure(error);270 yield put({ type: 'LOGOUT_FAILURE', logoutError: checkStatus });271 yield put({ type: 'LOGOUT_ALERT_SHOW_HIDE_DANGER' });272 }273}274function* change_password(request) {275 const signinData = yield select(getSigninData); // get the redux object276 //console.log('request in ChangePassword.....',request)277 yield put({ type: 'SET_LOADER', payload: true });278 const { nextUrl } = request.payload;279 const { oldPassword, newPassword } = request.payload;280 try {281 const response = yield call(api.changePassword, request.payload);282 console.log('response', response);283 if (response.data) {284 yield put({ type: 'SET_LOADER', payload: false });285 //yield put({ type: 'SET_MESSAGE', payload: 'Password Changed Successfully' });286 if (response.status === 200) {287 yield put({ type: 'SET_LOADER', payload: false });288 if (response.data && response.data.success === true) {289 yield put({ type: 'SET_MESSAGE', payload: 'Password Changed Successfully' });290 } else {291 yield put({ type: 'SET_MESSAGE', payload: 'Error occured while changing password.' });292 }293 }294 }295 //console.log('response',response)296 } catch (error) {297 console.log('error: ', error);298 const checkStatus = utils.checkAPIfailure(error);299 console.log(checkStatus);300 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {301 // change funcName to the current function name so that it gets called back302 const params = {303 funcName: change_password,304 params: request305 };306 yield call(refreshTokenFunc, params);307 } else {308 console.log('Network Err! or Internal Server Err!');309 yield put({ type: 'SET_LOADER', payload: false });310 yield put({ type: 'SET_MESSAGE', payload: 'Error occured while changing password.' });311 // const checkStatus = utils.checkAPIfailure(error);312 // yield put({ type: 'LOGOUT_FAILURE', logoutError: checkStatus });313 // yield put({ type: 'LOGOUT_ALERT_SHOW_HIDE_DANGER' });314 }315 }316}317function* create_subscription_plan(request) {318 const signinData = yield select(getSigninData); // get the redux object319 console.log('request in create_subscription_plan.....', request);320 yield put({ type: 'SET_LOADER', payload: true });321 try {322 const payload = { ...request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };323 const response = yield call(api.createSubscriptionPlan, payload, 'post');324 console.log('response', response);325 if (response.status === 200) {326 yield put({ type: 'SET_LOADER', payload: false });327 if (response.data && response.data.code === 200) {328 const subscriptionPlanList = yield call(api.getSubscriptionPlanList, payload.accesstoken);329 console.log(subscriptionPlanList);330 if (subscriptionPlanList.status === 200 && subscriptionPlanList.data.code === 200) {331 yield put({ type: 'SET_SUBSCRIPTION_PLAN_LIST', payload: subscriptionPlanList.data.response });332 }333 yield put({ type: 'SET_MESSAGE', payload: 'Subscription Plan created successfully' });334 } else {335 yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: response.data.response });336 }337 }338 } catch (error) {339 console.log('error: ', error);340 const checkStatus = utils.checkAPIfailure(error);341 console.log(checkStatus);342 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {343 // change funcName to the current function name so that it gets called back344 const params = {345 funcName: create_subscription_plan,346 params: request347 };348 yield call(refreshTokenFunc, params);349 } else if (350 checkStatus.Error &&351 checkStatus.Error.Message &&352 checkStatus.Error.Message === 'Access Token has been revoked'353 ) {354 yield put({ type: 'LOGOUT_SUCCESS' });355 // window.localStorage.clear();356 window.localStorage.removeItem('notification');357 window.localStorage.removeItem('notifications');358 yield put(push('/user-analyst'));359 } else {360 console.log('Network Err! or Internal Server Err!');361 }362 // yield put({ type: 'SET_LOADER', payload: false });363 // yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while creating subscription' });364 // yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });365 }366}367function* create_analyst_portfolio(request) {368 const signinData = yield select(getSigninData); // get the redux object369 console.log('request in create_analyst_portfolio.....', request);370 yield put({ type: 'SET_LOADER', payload: true });371 try {372 const payload = { ...request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };373 console.log('request in create_analyst_portfolio.....', payload);374 const response = yield call(api.createAnalystPortfolio, payload, 'post');375 console.log('response', response);376 if (response.status === 200) {377 yield put({ type: 'SET_LOADER', payload: false });378 if (response.data && response.data.code === 200) {379 const analystPortfolio = yield call(api.getAnalystPortfolio, payload.accesstoken);380 console.log('analystPortfolio', analystPortfolio);381 if (analystPortfolio.status === 200 && analystPortfolio.data.code === 200) {382 yield put({ type: 'SET_ANALYST_PORTFOLIO', payload: analystPortfolio.data.response });383 yield put({ type: 'SET_MESSAGE', payload: 'Analyst Portfolio created successfully' });384 }385 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });386 } else if (response.data && response.data.code === 500) {387 yield put({ type: 'SET_MESSAGE', payload: response.data.response });388 } else {389 yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: response.data.response });390 }391 }392 } catch (error) {393 console.log('error: ', error);394 const checkStatus = utils.checkAPIfailure(error);395 // console.log(checkStatus);396 if (checkStatus) {397 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {398 // change funcName to the current function name so that it gets called back399 const params = {400 funcName: create_analyst_portfolio,401 params: request402 };403 yield call(refreshTokenFunc, params);404 } else if (405 checkStatus.Error &&406 checkStatus.Error.Message &&407 checkStatus.Error.Message === 'Access Token has been revoked'408 ) {409 yield put({ type: 'LOGOUT_SUCCESS' });410 // window.localStorage.clear();411 window.localStorage.removeItem('notification');412 window.localStorage.removeItem('notifications');413 yield put(push('/user-analyst'));414 } else {415 console.log('Network Err! or Internal Server Err!');416 }417 }418 }419}420function* place_trade(request) {421 const signinData = yield select(getSigninData); // get the redux object422 // const { accesstoken, payload } = request.payload423 // //console.log('request',request)424 // console.log('accesstoken',accesstoken)425 // console.log('payload',payload)426 console.log('request in place_trade.....', request);427 // console.log('isntrumeny_token in formdata', request.payload.payload.get('instrument_token'));428 // console.log('segmetn in formdata', request.payload.payload.get('segment'));429 // yield put({ type: 'SET_LOADER', payload: true });430 try {431 const newRequest = { ...request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };432 let response;433 // yield put({ type: 'SET_LOADER', payload: true });434 yield put({ type: 'SET_LOADING', payload: true });435 if (request.payload.payload.updated) {436 response = yield call(api.updateTrade, request.payload.payload.formData, newRequest.accesstoken);437 } else {438 // const { accesstoken, payload } = request.payloa;439 console.log('request in place_trade.....', request);440 console.log('isntrumeny_token in formdata', request.payload.payload.get('instrument_token'));441 console.log('segmetn in formdata', request.payload.payload.get('segment'));442 console.log('trade_type in formdata', request.payload.payload.get('trade_type'));443 console.log('transaction_type in formdata', request.payload.payload.get('order_type'));444 response = yield call(api.placeTrade, newRequest, 'post');445 }446 console.log(response);447 if (response.status === 200 || response.status === 400) {448 // yield put({ type: 'SET_LOADER', payload: false });449 if (response.data && (response.data.code === 200 || response.data.code === 400)) {450 const tradeList = yield call(api.getTradeList, newRequest.accesstoken);451 if (452 (tradeList.status === 200 || tradeList.status === 400) &&453 (tradeList.data.code === 200 || tradeList.data.code === 400)454 ) {455 yield put({ type: 'SET_TRADE_LIST', payload: tradeList.data.response });456 yield put({ type: 'SET_LOADING', payload: false });457 }458 console.log(response.data);459 yield put({ type: 'SET_LOADING', payload: false });460 yield put({461 type: 'SET_MESSAGE',462 payload: response.data.message ? response.data.message : response.data.response463 });464 } else {465 // add message received from backend here466 yield put({ type: 'SET_LOADING', payload: false });467 yield put({ type: 'SET_MESSAGE', payload: response.data.response });468 }469 }470 } catch (error) {471 console.log('error: ', error);472 yield put({ type: 'SET_LOADING', payload: false });473 const checkStatus = utils.checkAPIfailure(error);474 console.log(checkStatus);475 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {476 // change funcName to the current function name so that it gets called back477 const params = {478 funcName: place_trade,479 params: request480 };481 yield call(refreshTokenFunc, params);482 } else if (483 checkStatus.Error &&484 checkStatus.Error.Message &&485 checkStatus.Error.Message === 'Access Token has been revoked'486 ) {487 yield put({ type: 'LOGOUT_SUCCESS' });488 // window.localStorage.clear();489 window.localStorage.removeItem('notification');490 window.localStorage.removeItem('notifications');491 yield put(push('/user-analyst'));492 } else {493 console.log('Network Err! or Internal Server Err!');494 yield put({ type: 'SET_LOADER', payload: false });495 yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });496 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });497 }498 }499}500function* get_available_trade_balance(request) {501 const signinData = yield select(getSigninData); // get the redux object502 console.log('request in get_available_trade_balance.....', request);503 // yield put({ type: 'SET_LOADER', payload: true });504 try {505 const payload = { accesstoken: signinData.token.AuthenticationResult.AccessToken };506 const response = yield call(api.getAvailableTradeBalance, payload.accesstoken);507 console.log('response', response);508 if (response.status === 200) {509 yield put({ type: 'SET_LOADER', payload: false });510 if (response.data && response.data.code === 200) {511 yield put({ type: 'SET_AVAILABLE_TRADE_BALANCE', payload: response.data.response });512 } else {513 // add message received from backend here514 yield put({ type: 'SET_MESSAGE', payload: 'Unable to get available trade balance' });515 }516 }517 } catch (error) {518 console.log('error: ', error);519 const checkStatus = utils.checkAPIfailure(error);520 console.log(checkStatus);521 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {522 // change funcName to the current function name so that it gets called back523 const params = {524 funcName: get_available_trade_balance,525 params: request526 };527 yield call(refreshTokenFunc, params);528 } else if (529 checkStatus.Error &&530 checkStatus.Error.Message &&531 checkStatus.Error.Message === 'Access Token has been revoked'532 ) {533 yield put({ type: 'LOGOUT_SUCCESS' });534 // window.localStorage.clear();535 window.localStorage.removeItem('notification');536 window.localStorage.removeItem('notifications');537 yield put(push('/user-analyst'));538 } else {539 console.log('Network Err! or Internal Server Err!');540 yield put({ type: 'SET_MESSAGE', payload: 'Unable to get available trade balance' });541 //yield put({ type: 'SET_LOADER', payload: false });542 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });543 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });544 }545 }546}547function* upload_document(request) {548 const signinData = yield select(getSigninData); // get the redux object549 console.log('request in upload_document.....', request);550 // yield put({ type: 'SET_LOADER', payload: true });551 try {552 const newRequest = {553 payload: request.payload.payload,554 accesstoken: signinData.token.AuthenticationResult.AccessToken555 };556 yield put({ type: 'SET_LOADING', payload: true });557 const response = yield call(api.uploadDocument, newRequest, 'post');558 console.log('response', response);559 if (response.status === 200) {560 //yield put({ type: 'SET_LOADER', payload: false });561 if (response.data && response.data.code === 200) {562 //563 yield put({ type: 'SET_LOADING', payload: false });564 yield put({ type: 'DOCUMENT_UPDATED', payload: true });565 yield put({ type: 'SET_MESSAGE', payload: response.data.response });566 } else {567 yield put({ type: 'SET_LOADING', payload: false });568 // add message received from backend here569 yield put({ type: 'SET_MESSAGE', payload: response.data.response });570 }571 }572 } catch (error) {573 console.log('error: ', error);574 yield put({ type: 'SET_LOADING', payload: false });575 const checkStatus = utils.checkAPIfailure(error);576 console.log(checkStatus);577 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {578 // change funcName to the current function name so that it gets called back579 const params = {580 funcName: upload_document,581 params: request582 };583 yield call(refreshTokenFunc, params);584 } else if (585 checkStatus.Error &&586 checkStatus.Error.Message &&587 checkStatus.Error.Message === 'Access Token has been revoked'588 ) {589 yield put({ type: 'LOGOUT_SUCCESS' });590 // window.localStorage.clear();591 window.localStorage.removeItem('notification');592 window.localStorage.removeItem('notifications');593 yield put(push('/user-analyst'));594 } else {595 console.log('Network Err! or Internal Server Err!');596 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });597 //yield put({ type: 'SET_LOADER', payload: false });598 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });599 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });600 }601 }602}603function* update_analyst_basic_details(request) {604 const signinData = yield select(getSigninData); // get the redux object605 console.log('request in update_analyst_basic_details.....', request);606 yield put({ type: 'SET_LOADER', payload: true });607 try {608 const payload = { ...request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };609 const response = yield call(api.updateAnalystBasicDetails, payload, 'post');610 console.log('response', response);611 if (response.status === 200) {612 if (response.data && response.data.code === 200) {613 const analystDetails = yield call(api.getAnalystDetails, payload);614 if (analystDetails.status === 200 && analystDetails.data.code === 200) {615 yield put({ type: 'SET_ANALYST_DETAILS', payload: analystDetails.data.response });616 }617 if (payload.user) {618 let name = payload.user.first_name + ' ' + payload.user.last_name;619 //console.log('name:',name)620 yield put({621 type: 'UPDATE_NAME',622 Namepayload: {623 AccessToken: payload.accesstoken,624 UserAttributes: [625 {626 Name: 'name',627 Value: name628 }629 ]630 }631 });632 }633 yield put({ type: 'DOCUMENT_UPDATED', payload: false });634 yield put({ type: 'SET_MESSAGE', payload: response.data.response });635 yield put({ type: 'SWITCH_TO_PROFILE_DISPLAY', payload: true });636 } else {637 // add message received from backend here638 console.log(response);639 yield put({ type: 'SET_MESSAGE', payload: response.data.response });640 }641 yield put({ type: 'SET_LOADER', payload: true });642 }643 } catch (error) {644 console.log('error: ', error);645 const checkStatus = utils.checkAPIfailure(error);646 console.log(checkStatus);647 yield put({ type: 'SWITCH_TO_PROFILE_DISPLAY', payload: false });648 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {649 // change funcName to the current function name so that it gets called back650 const params = {651 funcName: update_analyst_basic_details,652 params: request653 };654 yield call(refreshTokenFunc, params);655 } else if (656 checkStatus.Error &&657 checkStatus.Error.Message &&658 checkStatus.Error.Message === 'Access Token has been revoked'659 ) {660 yield put({ type: 'LOGOUT_SUCCESS' });661 // window.localStorage.clear();662 window.localStorage.removeItem('notification');663 window.localStorage.removeItem('notifications');664 yield put(push('/user-analyst'));665 } else {666 console.log('Network Err! or Internal Server Err!');667 // yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });668 yield put({ type: 'SET_LOADER', payload: false });669 yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while updating details' });670 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });671 }672 }673}674function* fetch_instrument_tokens(request) {675 const signinData = yield select(getSigninData); // get the redux object676 console.log('request in fetch_instrument_tokens.....', request);677 yield put({ type: 'SAVE_INSTRUMENT_TOKENS', payload: [] });678 yield put({ type: 'SET_LOADER', payload: true });679 //yield put({ type: 'SET_LOADER', payload: true });680 try {681 const response = yield call(api.fetchInstrumentToken, {682 token: signinData.token.AuthenticationResult.AccessToken,683 segment: request.payload.payload.segment,684 trading_symbol: request.payload.payload.trading_symbol685 });686 console.log('response', response);687 yield put({ type: 'SET_LOADER', payload: false });688 if (response.status === 200) {689 // yield put({ type: 'SET_LOADER', payload: false });690 if (response.data && response.data.code === 200) {691 // let name=request.payload.user.first_name+" "+request.payload.user.last_name692 //console.log('name:',name)693 yield put({ type: 'SAVE_INSTRUMENT_TOKENS', payload: response.data.response });694 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });695 } else {696 yield put({ type: 'SAVE_INSTRUMENT_TOKENS', payload: [] });697 // add message received from backend here698 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });699 }700 }701 } catch (error) {702 console.log('error: ', error);703 const checkStatus = utils.checkAPIfailure(error);704 console.log(checkStatus);705 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {706 // change funcName to the current function name so that it gets called back707 const params = {708 funcName: fetch_instrument_tokens,709 params: request710 };711 yield call(refreshTokenFunc, params);712 } else if (713 checkStatus.Error &&714 checkStatus.Error.Message &&715 checkStatus.Error.Message === 'Access Token has been revoked'716 ) {717 yield put({ type: 'LOGOUT_SUCCESS' });718 // window.localStorage.clear();719 window.localStorage.removeItem('notification');720 window.localStorage.removeItem('notifications');721 yield put(push('/user-analyst'));722 } else {723 console.log('Network Err! or Internal Server Err!');724 yield put({ type: 'SET_LOADER', payload: false });725 yield put({ type: 'SAVE_INSTRUMENT_TOKENS', payload: null });726 // // yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });727 // yield put({ type: 'SET_LOADER', payload: false });728 // yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while updating details' });729 // //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });730 }731 }732}733function* get_webinar_list(request) {734 const signinData = yield select(getSigninData); // get the redux object735 console.log('request in get_webinar_list.....', request.payload.token);736 //yield put({ type: 'SET_LOADER', payload: true });737 try {738 const response = yield call(api.getWebinarList, request.payload.token);739 console.log('response', response);740 if (response.status === 200) {741 // yield put({ type: 'SET_LOADER', payload: false });742 if (response.data && response.data.code === 200) {743 // let name=request.payload.user.first_name+" "+request.payload.user.last_name744 //console.log('name:',name)745 yield put({ type: 'SAVE_WEBINAR_LIST', payload: response.data.response });746 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });747 } else {748 console.log('eror in getting webinar list : ', response.data.response);749 //yield put({ type: 'SAVE_INSTRUMENT_TOKENS', payload: [] });750 // add message received from backend here751 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });752 }753 }754 } catch (error) {755 console.log('error in last catch ::::::::::::: ', error);756 const checkStatus = utils.checkAPIfailure(error);757 console.log(checkStatus);758 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {759 const params = {760 funcName: get_webinar_list,761 params: request762 };763 yield call(refreshTokenFunc, params);764 } else if (765 checkStatus.Error &&766 checkStatus.Error.Message &&767 checkStatus.Error.Message === 'Access Token has been revoked'768 ) {769 yield put({ type: 'LOGOUT_SUCCESS' });770 // window.localStorage.clear();771 window.localStorage.removeItem('notification');772 window.localStorage.removeItem('notifications');773 yield put(push('/user-analyst'));774 } else {775 console.log('Network Err! or Internal Server Err!');776 }777 // yield put({ type: 'SAVE_INSTRUMENT_TOKENS', payload: null });778 // // yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });779 // yield put({ type: 'SET_LOADER', payload: false });780 // yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while updating details' });781 // //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });782 }783}784function* refreshTokenFunc(params) {785 console.log('inside saga refresh token func ::: ' + params);786 console.log(params);787 let signinData = yield select(getSigninData); // get the redux object788 const signinPayloads = {789 refreshToken: signinData.token.AuthenticationResult.RefreshToken,790 grant_type: 'REFRESH_TOKEN'791 };792 try {793 const response = yield call(api.signin, signinPayloads);794 const refreshRes = utils.checkAPIfailure(response);795 if (refreshRes.hasOwnProperty('success') && refreshRes.success === true) {796 const updatedSigninData = {797 groups: signinData.groups,798 token: {799 AuthenticationResult: {800 ExpiresIn: refreshRes.token.AuthenticationResult.ExpiresIn,801 IdToken: refreshRes.token.AuthenticationResult.IdToken,802 RefreshToken: signinData.token.AuthenticationResult.RefreshToken,803 TokenType: refreshRes.token.AuthenticationResult.TokenType,804 AccessToken: refreshRes.token.AuthenticationResult.AccessToken805 }806 },807 user: signinData.user808 };809 yield put({ type: 'SIGNIN_SUCCESS', signinData: updatedSigninData });810 yield call(params.funcName, params.params);811 } else {812 yield put({ type: 'LOGOUT_SUCCESS' });813 // window.localStorage.clear();814 window.localStorage.removeItem('notification');815 window.localStorage.removeItem('notifications');816 yield put(push('/user-analyst'));817 }818 } catch (error) {819 // console.log(error.Message);820 yield put({ type: 'LOGOUT_SUCCESS' });821 // window.localStorage.clear();822 window.localStorage.removeItem('notification');823 window.localStorage.removeItem('notifications');824 yield put(push('/user-analyst'));825 }826}827export default function* watchAll() {828 return (829 yield takeEvery('USER_AUTH', user_auth_worker),830 yield takeEvery('DEVICE_TOKEN', device_token),831 yield takeEvery('USER_AUTH_ALERT_SHOW_HIDE_DANGER_DISMISS', user_auth_alert_dismiss_worker),832 yield takeEvery('SIGNIN', signin_worker),833 yield takeEvery('SIGNUP', signup_worker),834 yield takeEvery('VERIFY_OTP', verify_otp_worker),835 yield takeEvery('RESEND_OTP', resend_otp_worker),836 yield takeEvery('FORGOT_PASSWORD', forgot_password_worker),837 yield takeEvery('RESET_PASSWORD', reset_password_worker),838 yield takeEvery('LOGOUT', logout_worker),839 yield takeEvery('CHANGE_PASSWORD', change_password),840 yield takeEvery('VERIFY_OTP_ALERT_SHOW_HIDE_DANGER_DISMISS', verify_otp_alert_dismiss_worker),841 yield takeEvery('RESEND_OTP_ALERT_SHOW_HIDE_DANGER_DISMISS', resend_otp_alert_dismiss_worker),842 yield takeEvery('FORGOT_PASSWORD_ALERT_SHOW_HIDE_DANGER_DISMISS', forgot_password_alert_dismiss_worker),843 yield takeEvery('RESET_PASSWORD_ALERT_SHOW_HIDE_DANGER_DISMISS', reset_password_alert_dismiss_worker),844 yield takeEvery('CREATE_SUBSCRIPTION_PLAN', create_subscription_plan),845 yield takeEvery('GET_AVAILABLE_TRADE_BALANCE', get_available_trade_balance),846 yield takeEvery('UPLOAD_DOCUMENT', upload_document),847 yield takeEvery('UPDATE_ANALYST_BASIC_DETAILS', update_analyst_basic_details),848 yield takeEvery('FETCH_INSTRUMENT_TOKENS', fetch_instrument_tokens),849 yield takeEvery('PLACE_TRADE', place_trade),850 yield takeEvery('GET_WEBINAR_LIST', get_webinar_list),851 yield takeEvery('CREATE_ANALYST_PORTFOLIO', create_analyst_portfolio)852 );...

Full Screen

Full Screen

account.js

Source:account.js Github

copy

Full Screen

1import { call, put, takeEvery, takeLatest, select } from 'redux-saga/effects';2import { push } from 'connected-react-router/immutable';3import api from '../../network';4import utils from '../../theme/utils';5export const getSigninData = state => state.auth.signinData;6export const getUserGroup = state => state.auth.userGroup;7// eslint-disable-next-line camelcase8function* create_bank_account(request) {9 const signinData = yield select(getSigninData); // get the redux object10 try {11 const response = yield call(12 api.createBankAccount,13 request.payload.params,14 signinData.token.AuthenticationResult.AccessToken15 );16 console.log('response', response);17 if (response.status === 200) {18 if (response.data && response.data.code === 200) {19 const bankDetail = yield call(api.getBankDetails, signinData.token.AuthenticationResult.AccessToken);20 console.log(bankDetail);21 if (bankDetail.status === 200 && bankDetail.data.code === 200) {22 yield put({ type: 'SAVE_BANK_ACCOUNT', payload: bankDetail.data.response });23 }24 yield put({ type: 'SWITCH_TO_ACCOUNT_DISPLAY', payload: true });25 yield put({ type: 'SET_MESSAGE', payload: response.data.response });26 } else {27 yield put({ type: 'SWITCH_TO_ACCOUNT_DISPLAY', payload: true });28 yield put({ type: 'SET_MESSAGE', payload: response.data.response });29 }30 } else {31 yield put({ type: 'SWITCH_TO_ACCOUNT_DISPLAY', payload: true });32 yield put({ type: 'SET_MESSAGE', payload: response.statusText });33 }34 } catch (error) {35 console.log('error: ', error);36 yield put({ type: 'SWITCH_TO_ACCOUNT_DISPLAY', payload: false });37 const checkStatus = utils.checkAPIfailure(error);38 console.log(checkStatus);39 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {40 // change funcName to the current function name so that it gets called back41 const params = {42 funcName: create_bank_account,43 params: request44 };45 yield call(refreshTokenFunc, params);46 } else if (47 checkStatus.Error &&48 checkStatus.Error.Message &&49 checkStatus.Error.Message === 'Access Token has been revoked'50 ) {51 yield put({ type: 'LOGOUT_SUCCESS' });52 // window.localStorage.clear();53 window.localStorage.removeItem('notification');54 window.localStorage.removeItem('notifications');55 yield put(push('/user-analyst'));56 } else {57 console.log('Network Err! or Internal Server Err!');58 yield put({ type: 'SET_MESSAGE', payload: error });59 }60 }61}62function* get_bank_account(request) {63 const signinData = yield select(getSigninData); // get the redux object64 try {65 const payload = { token: signinData.token.AuthenticationResult.AccessToken };66 const response = yield call(api.getBankDetails, payload.token);67 console.log('response', response);68 if (response.status === 200) {69 if (response.data && response.data.code === 200) {70 yield put({ type: 'SAVE_BANK_ACCOUNT', payload: response.data.response });71 } else {72 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });73 }74 } else {75 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });76 }77 } catch (error) {78 console.log('error: ', error);79 const checkStatus = utils.checkAPIfailure(error);80 console.log(checkStatus);81 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {82 // change funcName to the current function name so that it gets called back83 const params = {84 funcName: get_bank_account,85 params: request86 };87 yield call(refreshTokenFunc, params);88 } else if (89 checkStatus.Error &&90 checkStatus.Error.Message &&91 checkStatus.Error.Message === 'Access Token has been revoked'92 ) {93 yield put({ type: 'LOGOUT_SUCCESS' });94 // window.localStorage.clear();95 window.localStorage.removeItem('notification');96 window.localStorage.removeItem('notifications');97 yield put(push('/user-analyst'));98 } else {99 console.log('Network Err! or Internal Server Err!');100 }101 // yield put({ type: 'SET_MESSAGE', payload: error });102 }103}104function* getAnalystDetails(request) {105 const signinData = yield select(getSigninData); // get the redux object106 try {107 const payload = { ...request.payload, accesstoken: signinData.token.AuthenticationResult.AccessToken };108 // const response = yield call(api.getAnalystDetails, request.payload);109 const response = yield call(api.getAnalystDetails, payload, 'get');110 const bankDetail = yield call(api.getBankDetails, payload.accesstoken);111 if (bankDetail.status === 200 && bankDetail.data.code === 200) {112 yield put({ type: 'SAVE_BANK_ACCOUNT', payload: bankDetail.data.response });113 }114 console.log('response', response);115 if (response.status === 200) {116 if (response.data && response.data.code === 200) {117 yield put({ type: 'SET_ANALYST_DETAILS', payload: response.data.response });118 } else if (response.data && response.data.code === 404) {119 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });120 } else {121 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });122 }123 } else {124 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });125 }126 } catch (error) {127 console.log('error: ', error);128 const checkStatus = utils.checkAPIfailure(error);129 console.log(checkStatus);130 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {131 // change funcName to the current function name so that it gets called back132 const params = {133 funcName: getAnalystDetails,134 params: request135 };136 yield call(refreshTokenFunc, params);137 } else if (138 checkStatus.Error &&139 checkStatus.Error.Message &&140 checkStatus.Error.Message === 'Access Token has been revoked'141 ) {142 yield put({ type: 'LOGOUT_SUCCESS' });143 // window.localStorage.clear();144 window.localStorage.removeItem('notification');145 window.localStorage.removeItem('notifications');146 yield put(push('/user-analyst'));147 } else {148 console.log('Network Err! or Internal Server Err!');149 }150 // yield put({ type: 'SET_MESSAGE', payload: error });151 }152}153function* getSubscriptionPlanList(request) {154 const signinData = yield select(getSigninData); // get the redux object155 try {156 const payload = signinData.token.AuthenticationResult.AccessToken;157 const response = yield call(api.getSubscriptionPlanList, payload);158 console.log('response', response);159 if (response.status === 200) {160 if (response.data && response.data.code === 200) {161 yield put({ type: 'SET_SUBSCRIPTION_PLAN_LIST', payload: response.data.response });162 } else if (response.data && response.data.code === 404) {163 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });164 yield put({ type: 'SET_SUBSCRIPTION_PLAN_LIST', payload: [] });165 } else {166 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });167 }168 } else {169 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });170 }171 } catch (error) {172 console.log('error: ', error);173 const checkStatus = utils.checkAPIfailure(error);174 console.log(checkStatus);175 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {176 // change funcName to the current function name so that it gets called back177 const params = {178 funcName: getSubscriptionPlanList,179 params: request180 };181 yield call(refreshTokenFunc, params);182 } else if (183 checkStatus.Error &&184 checkStatus.Error.Message &&185 checkStatus.Error.Message === 'Access Token has been revoked'186 ) {187 yield put({ type: 'LOGOUT_SUCCESS' });188 // window.localStorage.clear();189 window.localStorage.removeItem('notification');190 window.localStorage.removeItem('notifications');191 yield put(push('/user-analyst'));192 } else {193 console.log('Network Err! or Internal Server Err!');194 }195 // yield put({ type: 'SET_MESSAGE', payload: error });196 }197}198function* getTradeList(request) {199 const signinData = yield select(getSigninData); // get the redux object200 yield put({ type: 'SET_LOADER', payload: true });201 try {202 const payload = signinData.token.AuthenticationResult.AccessToken;203 const response = yield call(api.getTradeList, payload);204 console.log('response', response);205 if (response.status === 200) {206 yield put({ type: 'SET_LOADER', payload: false });207 if (response.data && response.data.code === 200) {208 yield put({ type: 'SET_TRADE_LIST', payload: response.data.response });209 } else if (response.data && response.data.code === 404) {210 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });211 } else {212 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });213 }214 } else {215 yield put({ type: 'SET_LOADER', payload: false });216 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });217 }218 } catch (error) {219 yield put({ type: 'SET_LOADER', payload: false });220 console.log('error: ', error);221 const checkStatus = utils.checkAPIfailure(error);222 console.log(checkStatus);223 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {224 // change funcName to the current function name so that it gets called back225 const params = {226 funcName: getTradeList,227 params: request228 };229 yield call(refreshTokenFunc, params);230 } else if (231 checkStatus.Error &&232 checkStatus.Error.Message &&233 checkStatus.Error.Message === 'Access Token has been revoked'234 ) {235 yield put({ type: 'LOGOUT_SUCCESS' });236 // window.localStorage.clear();237 window.localStorage.removeItem('notification');238 window.localStorage.removeItem('notifications');239 yield put(push('/user-analyst'));240 } else {241 console.log('Network Err! or Internal Server Err!');242 }243 // yield put({ type: 'SET_MESSAGE', payload: error });244 }245}246function* getTradeCounts(request) {247 const signinData = yield select(getSigninData); // get the redux object248 yield put({ type: 'SET_LOADER', payload: true });249 try {250 const payload = signinData.token.AuthenticationResult.AccessToken;251 const response = yield call(api.getTradeCounts, payload);252 console.log('response', response);253 if (response.status === 200) {254 yield put({ type: 'SET_LOADER', payload: false });255 if (response.data && response.data.success === true) {256 yield put({ type: 'SET_TRADE_COUNTS', payload: response.data });257 } else if (response.data && response.data.code === 404) {258 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });259 } else {260 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });261 }262 } else {263 yield put({ type: 'SET_LOADER', payload: false });264 // yield put({ type: 'SET_MESSAGE', payload: response.statusText });265 }266 } catch (error) {267 yield put({ type: 'SET_LOADER', payload: false });268 console.log('error: ', error);269 const checkStatus = utils.checkAPIfailure(error);270 console.log(checkStatus);271 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {272 // change funcName to the current function name so that it gets called back273 const params = {274 funcName: getTradeCounts,275 params: request276 };277 yield call(refreshTokenFunc, params);278 } else if (279 checkStatus.Error &&280 checkStatus.Error.Message &&281 checkStatus.Error.Message === 'Access Token has been revoked'282 ) {283 yield put({ type: 'LOGOUT_SUCCESS' });284 // window.localStorage.clear();285 window.localStorage.removeItem('notification');286 window.localStorage.removeItem('notifications');287 yield put(push('/user-analyst'));288 } else {289 console.log('Network Err! or Internal Server Err!');290 }291 // yield put({ type: 'SET_MESSAGE', payload: error });292 }293}294function* updateName(request) {295 const signinData = yield select(getSigninData); // get the redux object296 try {297 const Namepayload = {298 UserAttributes: request.Namepayload.UserAttributes,299 AccessToken: signinData.token.AuthenticationResult.AccessToken300 };301 let userGroup = yield select(getUserGroup); // get the redux object302 const response = yield call(api.updateUserName, Namepayload);303 console.log('response', response);304 if (response.status === 200) {305 if (response.data && response.data.success) {306 yield put({ type: 'SET_UPDATED_NAME', payload: request.Namepayload.UserAttributes[0].Value });307 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });308 } else {309 // add message received from backend here310 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });311 }312 }313 } catch (error) {314 console.log('error: ', error);315 const checkStatus = utils.checkAPIfailure(error);316 console.log(checkStatus);317 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {318 // change funcName to the current function name so that it gets called back319 const params = {320 funcName: updateName,321 params: request322 };323 yield call(refreshTokenFunc, params);324 } else if (325 checkStatus.Error &&326 checkStatus.Error.Message &&327 checkStatus.Error.Message === 'Access Token has been revoked'328 ) {329 yield put({ type: 'LOGOUT_SUCCESS' });330 // window.localStorage.clear();331 window.localStorage.removeItem('notification');332 window.localStorage.removeItem('notifications');333 yield put(push('/user-analyst'));334 } else {335 console.log('Network Err! or Internal Server Err!');336 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });337 //yield put({ type: 'SET_LOADER', payload: false });338 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });339 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });340 }341 }342 // try {343 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);344 // console.log('response', response);345 // } catch (error) {346 // console.log('error: ', error);347 // }348}349function* updateEmail(request) {350 const signinData = yield select(getSigninData); // get the redux object351 console.log('request in create_bank_account.....', request);352 try {353 const EmailPayload = {354 UserAttributes: request.EmailPayload.UserAttributes,355 AccessToken: signinData.token.AuthenticationResult.AccessToken356 };357 const response = yield call(api.updateUserName, EmailPayload);358 console.log('response', response);359 if (response.status === 200) {360 if (response.data && response.data.success) {361 yield put({ type: 'SET_UPDATED_EMAIL', payload: EmailPayload.UserAttributes[0].Value });362 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });363 } else {364 // add message received from backend here365 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });366 }367 }368 } catch (error) {369 console.log('error: ', error);370 const checkStatus = utils.checkAPIfailure(error);371 console.log(checkStatus);372 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {373 // change funcName to the current function name so that it gets called back374 const params = {375 funcName: updateEmail,376 params: request377 };378 yield call(refreshTokenFunc, params);379 } else if (380 checkStatus.Error &&381 checkStatus.Error.Message &&382 checkStatus.Error.Message === 'Access Token has been revoked'383 ) {384 yield put({ type: 'LOGOUT_SUCCESS' });385 // window.localStorage.clear();386 window.localStorage.removeItem('notification');387 window.localStorage.removeItem('notifications');388 yield put(push('/user-analyst'));389 } else {390 console.log('Network Err! or Internal Server Err!');391 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });392 //yield put({ type: 'SET_LOADER', payload: false });393 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });394 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });395 }396 }397 // try {398 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);399 // console.log('response', response);400 // } catch (error) {401 // console.log('error: ', error);402 // }403}404function* updateProfileImage(request) {405 const signinData = yield select(getSigninData); // get the redux object406 try {407 const newRequest = {408 payload: request.profileImage.payload,409 accesstoken: signinData.token.AuthenticationResult.AccessToken410 };411 yield put({ type: 'SET_LOADING', payload: true });412 const response = yield call(api.uploadDocument, newRequest, 'post');413 console.log('response', response);414 if (response.status === 200) {415 if (response.data && response.data.code === 200) {416 const profileImage = yield call(api.getProfilePicture, newRequest.accesstoken);417 console.log(profileImage);418 if (profileImage.status === 200 && profileImage.data && profileImage.data.code === 200) {419 yield put({ type: 'SET_LOADING', payload: false });420 yield put({ type: 'SET_UPDATED_PROFILE_IMAGE', payload: profileImage.data.response.file });421 }422 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });423 } else {424 yield put({ type: 'SET_LOADING', payload: false });425 // add message received from backend here426 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });427 }428 }429 } catch (error) {430 console.log('error: ', error);431 yield put({ type: 'SET_LOADING', payload: false });432 const checkStatus = utils.checkAPIfailure(error);433 console.log(checkStatus);434 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {435 // change funcName to the current function name so that it gets called back436 const params = {437 funcName: updateProfileImage,438 params: request439 };440 yield call(refreshTokenFunc, params);441 } else if (442 checkStatus.Error &&443 checkStatus.Error.Message &&444 checkStatus.Error.Message === 'Access Token has been revoked'445 ) {446 yield put({ type: 'LOGOUT_SUCCESS' });447 // window.localStorage.clear();448 window.localStorage.removeItem('notification');449 window.localStorage.removeItem('notifications');450 yield put(push('/user-analyst'));451 } else {452 console.log('Network Err! or Internal Server Err!');453 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });454 //yield put({ type: 'SET_LOADER', payload: false });455 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });456 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });457 }458 }459 // try {460 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);461 // console.log('response', response);462 // } catch (error) {463 // console.log('error: ', error);464 // }465}466function* getProfileImage(request) {467 const signinData = yield select(getSigninData); // get the redux object468 console.log(request);469 try {470 const response = yield call(api.getProfilePicture, signinData.token.AuthenticationResult.AccessToken);471 console.log('response', response);472 if (response.status === 200) {473 if (response.data && response.data.code === 200) {474 yield put({ type: 'SET_UPDATED_PROFILE_IMAGE', payload: response.data.response.file });475 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });476 } else {477 // add message received from backend here478 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });479 }480 }481 } catch (error) {482 console.log('error: ', error);483 const checkStatus = utils.checkAPIfailure(error);484 console.log(checkStatus);485 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {486 // change funcName to the current function name so that it gets called back487 const params = {488 funcName: getProfileImage,489 params: request490 };491 yield call(refreshTokenFunc, params);492 } else if (493 checkStatus.Error &&494 checkStatus.Error.Message &&495 checkStatus.Error.Message === 'Access Token has been revoked'496 ) {497 yield put({ type: 'LOGOUT_SUCCESS' });498 // window.localStorage.clear();499 window.localStorage.removeItem('notification');500 window.localStorage.removeItem('notifications');501 yield put(push('/user-analyst'));502 } else {503 console.log('Network Err! or Internal Server Err!');504 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });505 //yield put({ type: 'SET_LOADER', payload: false });506 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });507 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });508 }509 }510 // try {511 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);512 // console.log('response', response);513 // } catch (error) {514 // console.log('error: ', error);515 // }516}517function* deleteSubscriptionPlan(request) {518 const signinData = yield select(getSigninData); // get the redux object519 console.log('request in create_subscription_plan.....', request);520 // yield put({ type: 'SET_LOADER', payload: true });521 try {522 const payload = {523 subscription_plan_id: request.payload.subscription_plan_id,524 accesstoken: signinData.token.AuthenticationResult.AccessToken525 };526 const response = yield call(api.deleteSubscriptionPlan, payload);527 console.log('response', response);528 if (response.status === 200) {529 // yield put({ type: 'SET_LOADER', payload: false });530 if (response.data && response.data.code === 200) {531 const subscriptionPlanList = yield call(api.getSubscriptionPlanList, payload.accesstoken);532 if (subscriptionPlanList.status === 200 && subscriptionPlanList.data.code === 200) {533 yield put({ type: 'SET_SUBSCRIPTION_PLAN_LIST', payload: subscriptionPlanList.data.response });534 } else if (subscriptionPlanList.status === 200 && subscriptionPlanList.data.code === 404) {535 yield put({ type: 'SET_SUBSCRIPTION_PLAN_LIST', payload: [] });536 }537 yield put({ type: 'SET_MESSAGE', payload: 'Subscription Plan Deleted successfully' });538 } else {539 yield put({ type: 'SET_MESSAGE', payload: 'Some Error occured while deleting' });540 // yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: response.data.response });541 }542 }543 } catch (error) {544 console.log('error: ', error);545 const checkStatus = utils.checkAPIfailure(error);546 console.log(checkStatus);547 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {548 // change funcName to the current function name so that it gets called back549 const params = {550 funcName: deleteSubscriptionPlan,551 params: request552 };553 yield call(refreshTokenFunc, params);554 } else if (555 checkStatus.Error &&556 checkStatus.Error.Message &&557 checkStatus.Error.Message === 'Access Token has been revoked'558 ) {559 yield put({ type: 'LOGOUT_SUCCESS' });560 // window.localStorage.clear();561 window.localStorage.removeItem('notification');562 window.localStorage.removeItem('notifications');563 yield put(push('/user-analyst'));564 } else {565 console.log('Network Err! or Internal Server Err!');566 yield put({ type: 'SET_LOADER', payload: false });567 yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while creating subscription' });568 // yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });569 }570 }571}572function* cancelTradeRequest(request) {573 const signinData = yield select(getSigninData); // get the redux object574 // yield put({ type: 'SET_LOADER', payload: true });575 try {576 const payload = {577 accesstoken: signinData.token.AuthenticationResult.AccessToken,578 record_id: request.payload.record_id579 };580 yield put({ type: 'SET_LOADING', payload: true });581 const response = yield call(api.cancelTradeList, payload);582 console.log('response', response);583 if (response.status === 200) {584 // yield put({ type: 'SET_LOADER', payload: false });585 if (response.data && response.data.code === 200) {586 const tradeList = yield call(api.getTradeList, payload.accesstoken);587 console.log(tradeList);588 yield put({ type: 'SET_MESSAGE', payload: 'Trade Canceled successfully' });589 if (tradeList.status === 200 && tradeList.data.code === 200) {590 yield put({ type: 'SET_TRADE_LIST', payload: tradeList.data.response });591 yield put({ type: 'SET_LOADING', payload: false });592 } else if (tradeList.status === 200 && tradeList.data.code === 404) {593 yield put({ type: 'SET_LOADING', payload: false });594 yield put({ type: 'SET_TRADE_LIST', payload: [] });595 }596 } else {597 yield put({ type: 'SET_LOADING', payload: false });598 yield put({ type: 'SET_MESSAGE', payload: 'Some Error occured while canceling' });599 // yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: response.data.response });600 }601 }602 } catch (error) {603 console.log('error: ', error);604 yield put({ type: 'SET_LOADING', payload: false });605 const checkStatus = utils.checkAPIfailure(error);606 console.log(checkStatus);607 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {608 // change funcName to the current function name so that it gets called back609 const params = {610 funcName: cancelTradeRequest,611 params: request612 };613 yield call(refreshTokenFunc, params);614 } else if (615 checkStatus.Error &&616 checkStatus.Error.Message &&617 checkStatus.Error.Message === 'Access Token has been revoked'618 ) {619 yield put({ type: 'LOGOUT_SUCCESS' });620 // window.localStorage.clear();621 window.localStorage.removeItem('notification');622 window.localStorage.removeItem('notifications');623 yield put(push('/user-analyst'));624 } else {625 console.log('Network Err! or Internal Server Err!');626 yield put({ type: 'SET_LOADER', payload: false });627 yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while canceling trade List' });628 // yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });629 }630 }631}632function* refreshTokenFunc(params) {633 console.log('inside saga refresh token func ::: ' + params);634 console.log(params);635 let signinData = yield select(getSigninData); // get the redux object636 const signinPayloads = {637 refreshToken: signinData.token.AuthenticationResult.RefreshToken,638 grant_type: 'REFRESH_TOKEN'639 };640 yield put({ type: 'SET_LOADING', payload: false });641 try {642 const response = yield call(api.signin, signinPayloads);643 const refreshRes = utils.checkAPIfailure(response);644 if (refreshRes.hasOwnProperty('success') && refreshRes.success === true) {645 const updatedSigninData = {646 groups: signinData.groups,647 token: {648 AuthenticationResult: {649 ExpiresIn: refreshRes.token.AuthenticationResult.ExpiresIn,650 IdToken: refreshRes.token.AuthenticationResult.IdToken,651 RefreshToken: signinData.token.AuthenticationResult.RefreshToken,652 TokenType: refreshRes.token.AuthenticationResult.TokenType,653 AccessToken: refreshRes.token.AuthenticationResult.AccessToken654 }655 },656 user: signinData.user657 };658 yield put({ type: 'SIGNIN_SUCCESS', signinData: updatedSigninData });659 yield call(params.funcName, params.params);660 } else {661 // console.log(refreshRes)662 yield put({ type: 'LOGOUT_SUCCESS' });663 // window.localStorage.clear();664 window.localStorage.removeItem('notification');665 window.localStorage.removeItem('notifications');666 yield put(push('/user-analyst'));667 }668 } catch (error) {669 console.log(error);670 yield put({ type: 'LOGOUT_SUCCESS' });671 // window.localStorage.clear();672 window.localStorage.removeItem('notification');673 window.localStorage.removeItem('notifications');674 yield put(push('/user-analyst'));675 }676}677function* updateDematAccounts(request) {678 const signinData = yield select(getSigninData); // get the redux object679 console.log('request in create_bank_account.....', request);680 try {681 const payload = {682 UserAttributes: request.payload.UserAttributes,683 AccessToken: signinData.token.AuthenticationResult.AccessToken684 };685 const response = yield call(api.updateUserName, payload);686 console.log('response', response);687 if (response.status === 200) {688 if (response.data && response.data.success) {689 yield put({ type: 'SET_UPDATED_DEMAT_ACCOUNTS', payload: payload.UserAttributes[0].Value });690 console.log('DONE');691 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });692 } else {693 // add message received from backend here694 // yield put({ type: 'SET_MESSAGE', payload: response.data.response });695 }696 }697 } catch (error) {698 console.log('error: ', error);699 const checkStatus = utils.checkAPIfailure(error);700 console.log(checkStatus);701 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {702 // change funcName to the current function name so that it gets called back703 const params = {704 funcName: updateDematAccounts,705 params: request706 };707 yield call(refreshTokenFunc, params);708 } else if (709 checkStatus.Error &&710 checkStatus.Error.Message &&711 checkStatus.Error.Message === 'Access Token has been revoked'712 ) {713 yield put({ type: 'LOGOUT_SUCCESS' });714 // window.localStorage.clear();715 window.localStorage.removeItem('notification');716 window.localStorage.removeItem('notifications');717 yield put(push('/user-analyst'));718 } else {719 console.log('Network Err! or Internal Server Err!');720 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });721 //yield put({ type: 'SET_LOADER', payload: false });722 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });723 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });724 }725 }726 // try {727 // const response = yield call(api.createBankAccount, request.payload.params, request.payload.token);728 // console.log('response', response);729 // } catch (error) {730 // console.log('error: ', error);731 // }732}733function* getAnalystFollowers(request) {734 const signinData = yield select(getSigninData); // get the redux object735 try {736 const token = signinData.token.AuthenticationResult.AccessToken;737 const response = yield call(api.getAnalystFollowers, token);738 if (response.status === 200) {739 if (response.data) {740 yield put({ type: 'SET_ANALYST_FOLLOWERS', payload: response.data.response });741 }742 }743 } catch (error) {744 console.log('error: ', error);745 const checkStatus = utils.checkAPIfailure(error);746 console.log(checkStatus);747 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {748 // change funcName to the current function name so that it gets called back749 const params = {750 funcName: getAnalystFollowers,751 params: request752 };753 yield call(refreshTokenFunc, params);754 } else if (755 checkStatus.Error &&756 checkStatus.Error.Message &&757 checkStatus.Error.Message === 'Access Token has been revoked'758 ) {759 yield put({ type: 'LOGOUT_SUCCESS' });760 // window.localStorage.clear();761 window.localStorage.removeItem('notification');762 window.localStorage.removeItem('notifications');763 yield put(push('/user-analyst'));764 } else {765 console.log('Network Err! or Internal Server Err!');766 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });767 //yield put({ type: 'SET_LOADER', payload: false });768 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });769 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });770 }771 }772}773function* getAnalystSubscribers(request) {774 const signinData = yield select(getSigninData); // get the redux object775 try {776 const token = signinData.token.AuthenticationResult.AccessToken;777 const response = yield call(api.getAnalystSubscribers, token);778 if (response.status === 200) {779 if (response.data) {780 yield put({ type: 'SET_ANALYST_SUBSCRIBERS', payload: response.data.response });781 }782 }783 } catch (error) {784 console.log('error: ', error);785 const checkStatus = utils.checkAPIfailure(error);786 console.log(checkStatus);787 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {788 // change funcName to the current function name so that it gets called back789 const params = {790 funcName: getAnalystSubscribers,791 params: request792 };793 yield call(refreshTokenFunc, params);794 } else if (795 checkStatus.Error &&796 checkStatus.Error.Message &&797 checkStatus.Error.Message === 'Access Token has been revoked'798 ) {799 yield put({ type: 'LOGOUT_SUCCESS' });800 // window.localStorage.clear();801 window.localStorage.removeItem('notification');802 window.localStorage.removeItem('notifications');803 yield put(push('/user-analyst'));804 } else {805 console.log('Network Err! or Internal Server Err!');806 yield put({ type: 'SET_MESSAGE', payload: 'Unable to upload Document' });807 //yield put({ type: 'SET_LOADER', payload: false });808 //yield put({ type: 'SET_MESSAGE', payload: 'Some error occured while placing trade' });809 //yield put({ type: 'ERROR_CREATE_SUBSCRIPTION_PLAN', payload: error });810 }811 }812}813function* getAnalystLeaderboard(request) {814 const signinData = yield select(getSigninData); // get the redux object815 try {816 // yield put({ type: 'ANALYST_LEADERBOARD', payload: request.payload });817 const payload = { token: signinData.token.AuthenticationResult.AccessToken };818 const response = yield call(api.getAnalystLeaderboardApi, payload);819 console.log('response', response);820 if (response.status === 200) {821 if (response.data && response.data.code === 200) {822 yield put({ type: 'SET_ANALYST_LEADERBOARD', payload: response.data.response });823 } else {824 yield put({ type: 'SET_MESSAGE', payload: 'Something went wrong' });825 console.log('leaderboard error', response);826 }827 } else {828 yield put({ type: 'SET_MESSAGE', payload: 'something went wrong' });829 }830 } catch (error) {831 const checkStatus = utils.checkAPIfailure(error);832 if (checkStatus.Error && checkStatus.Error.Message && checkStatus.Error.Message === 'Access Token has expired') {833 // change funcName to the current function name so that it gets called back834 const params = {835 funcName: getAnalystLeaderboard,836 params: request837 };838 yield call(refreshTokenFunc, params);839 } else if (840 checkStatus.Error &&841 checkStatus.Error.Message &&842 checkStatus.Error.Message === 'Access Token has been revoked'843 ) {844 yield put({ type: 'LOGOUT_SUCCESS' });845 // window.localStorage.clear();846 window.localStorage.removeItem('notification');847 window.localStorage.removeItem('notifications');848 yield put(push('/user-analyst'));849 } else {850 console.log('Network Err! or Internal Server Err!');851 yield put({ type: 'SET_MESSAGE', payload: 'something went wrong' });852 }853 }854}855export default function* watchAll() {856 return (857 yield takeEvery('CREATE_BANK_ACCOUNT', create_bank_account),858 yield takeEvery('UPDATE_NAME', updateName),859 yield takeEvery('UPDATE_EMAIL', updateEmail),860 yield takeEvery('UPDATE_PROFILE_IMAGE', updateProfileImage),861 yield takeEvery('GET_BANK_DETAILS', get_bank_account),862 yield takeEvery('GET_ANALYST_DETAILS', getAnalystDetails),863 yield takeEvery('GET_SUBSCRIPTION_PLAN_LIST', getSubscriptionPlanList),864 yield takeEvery('GET_TRADE_LIST', getTradeList),865 yield takeEvery('GET_TRADE_COUNTS', getTradeCounts),866 yield takeEvery('DELETE_SUBSCRIPTION_PLAN', deleteSubscriptionPlan),867 yield takeEvery('CANCEL_TRADE', cancelTradeRequest),868 yield takeEvery('GET_PROFILE_IMAGE', getProfileImage),869 yield takeEvery('UPDATE_DEMAT_ACCOUNTS', updateDematAccounts),870 yield takeEvery('GET_ANALYST_FOLLOWERS', getAnalystFollowers),871 yield takeEvery('GET_ANALYST_FOLLOWERS', getAnalystSubscribers),872 yield takeEvery('GET_ANALYST_LEADERBOARD', getAnalystLeaderboard)873 );...

Full Screen

Full Screen

reviewMajor_edit_admin.js

Source:reviewMajor_edit_admin.js Github

copy

Full Screen

1/**2 * 详情对话框3 */4var ReviewMajorInfoDlg = {5 data: {6 reviewId: "",7 direct: "",8 thesisCount: "",9 reviewCount: "",10 refuseCount: "",11 majorType: "",12 applyFrom: "",13 checkStatus: "",14 applyTime: "",15 agreeTime: "",16 refuseTime: "",17 cancelTime: "",18 belongDomain: "",19 pName: ""20 }21};22layui.use(['layer', 'form', 'admin', 'ax','laydate','upload','formSelects'], function () {23 var $ = layui.jquery;24 var $ax = layui.ax;25 var form = layui.form;26 var admin = layui.admin;27 var layer = layui.layer;28 //获取详情信息,填充表单29 var ajax = new $ax(Feng.ctxPath + "/reviewMajor/detail?reviewId=" + Feng.getUrlParam("reviewId"));30 var result = ajax.start();31 //转换状态值32 var checkStatus = result.data.checkStatus;33 debugger;34 if(checkStatus == 0){35 result.data.checkStatus = "已取消";36 }else if(checkStatus == 1){37 result.data.checkStatus = "申请中";38 }else if(checkStatus == 2){39 result.data.checkStatus = "已通过";40 }else if(checkStatus == 3){41 result.data.checkStatus = "未通过";42 }else{43 result.data.checkStatus = "-";44 }45 form.val('reviewMajorForm', result.data);46 //表单提交事件47 form.on('submit(btnSubmit)', function (data) {48 debugger;49 var param = data.field.checkStatus;50 var checkStatus = tranApplyType(param);51 data.field.checkStatus = checkStatus;52 if(checkStatus == 0){53 var operation = function () {54 var ajax = new $ax(Feng.ctxPath + "/reviewMajor/editItem", function (data) {55 Feng.success("修改成功!");56 //传给上个页面,刷新table用57 admin.putTempData('formOk', true);58 //关掉对话框59 admin.closeThisDialog();60 }, function (data) {61 Feng.error("修改失败!" + data.responseJSON.message)62 });63 ajax.set(data.field);64 ajax.start();65 };66 Feng.confirm("是否确认修改数据?", operation);67 }else {68 Feng.success("请先取消申请!");69 }70 return false;71 });72 //同意申请73 form.on('submit(btnAgree)', function (data) {74 debugger;75 var param = data.field.checkStatus;76 var checkStatus = tranApplyType(param);77 data.field.checkStatus = checkStatus;78 var operation = function () {79 var ajax = new $ax(Feng.ctxPath + "/reviewMajor/agreeApply", function (data) {80 Feng.success("通过申请成功!");81 //传给上个页面,刷新table用82 admin.putTempData('formOk', true);83 //关掉对话框84 admin.closeThisDialog();85 }, function (data) {86 Feng.error("通过申请失败!" + data.responseJSON.message)87 });88 ajax.set(data.field);89 ajax.start();90 };91 Feng.confirm("是否确认通过申请?", operation);92 return false;93 });94 //驳回申请95 form.on('submit(btnDisagree)', function (data) {96 debugger;97 var param = data.field.checkStatus;98 var checkStatus = tranApplyType(param);99 data.field.checkStatus = checkStatus;100 var operation = function () {101 var ajax = new $ax(Feng.ctxPath + "/reviewMajor/disAgreeApply", function (data) {102 Feng.success("驳回申请成功!");103 //传给上个页面,刷新table用104 admin.putTempData('formOk', true);105 //关掉对话框106 admin.closeThisDialog();107 }, function (data) {108 Feng.error("驳回申请失败!" + data.responseJSON.message)109 });110 ajax.set(data.field);111 ajax.start();112 };113 Feng.confirm("是否确认驳回申请?", operation);114 return false;115 });116 /**117 * 转换申请状态118 * 字符串→数字119 * @param param120 * @returns {number}121 */122 function tranApplyType(param) {123 var checkStatus = param;124 var status = '';125 if(checkStatus == "已取消"){126 status = 0;127 }else if(checkStatus == "申请中"){128 status = 1;129 }else if(checkStatus == "已通过"){130 status = 2;131 }else if(checkStatus == "未通过"){132 status = 3;133 }else{134 status = 0;135 }136 return status;137 }138 // 点击上级角色时139 $('#pName').click(function () {140 var formName = encodeURIComponent("parent.ReviewMajorInfoDlg.data.pName");141 var formId = encodeURIComponent("parent.ReviewMajorInfoDlg.data.belongDomain");142 var treeUrl = encodeURIComponent("/thesisDomain/tree?reviewId=" + Feng.getUrlParam("reviewId"));143 layer.open({144 type: 2,145 title: '专家领域',146 area: ['300px', '400px'],147 //content: Feng.ctxPath + '/thesisDomain/thesisDomainAssign?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,148 content: Feng.ctxPath + '/system/commonTree?formName=' + formName + "&formId=" + formId + "&treeUrl=" + treeUrl,149 end: function () {150 $("#belongDomain").val(ReviewMajorInfoDlg.data.belongDomain);151 $("#pName").val(ReviewMajorInfoDlg.data.pName);152 }153 });154 });...

Full Screen

Full Screen

script.js

Source:script.js Github

copy

Full Screen

...46})();47//Checks for all possible winning combinations in the gameboard48function checkCombinations(team) {49 disableTie = false50 if ((team == Square.One.checkStatus() && team == Square.Two.checkStatus() && team == Square.Three.checkStatus())51 || (team == Square.Four.checkStatus() && team == Square.Five.checkStatus() && team == Square.Six.checkStatus())52 || (team == Square.Seven.checkStatus() && team == Square.Eight.checkStatus() && team == Square.Nine.checkStatus())53 || (team == Square.One.checkStatus() && team == Square.Four.checkStatus() && team == Square.Seven.checkStatus())54 || (team == Square.Two.checkStatus() && team == Square.Five.checkStatus() && team == Square.Eight.checkStatus())55 || (team == Square.Three.checkStatus() && team == Square.Six.checkStatus() && team == Square.Nine.checkStatus())56 || (team == Square.One.checkStatus() && team == Square.Five.checkStatus() && team == Square.Nine.checkStatus())57 || (team == Square.Three.checkStatus() && team == Square.Five.checkStatus() && team == Square.Seven.checkStatus())) {58 disableTie = true;59 return true;60 } 61 if (checkTie() && disableTie == false) {62 document.querySelector(".result").innerHTML = "The game is a draw!";63 }; 64};65function checkTie() {66 return ('' !== Square.One.checkStatus() && '' !== Square.Two.checkStatus() && '' !== Square.Three.checkStatus() 67 && '' !== Square.Four.checkStatus() && '' !== Square.Five.checkStatus() && '' !== Square.Six.checkStatus()68 && '' !== Square.Seven.checkStatus() && '' !== Square.Eight.checkStatus() && '' !== Square.Nine.checkStatus())69};70//Event listener for each square71var s1 = document.querySelector("#square-1")72 s1.onclick = () => Square.One.playTurn(playerTurn);73var s2 = document.querySelector("#square-2")74 s2.onclick = () => Square.Two.playTurn(playerTurn); 75var s3 = document.querySelector("#square-3")76 s3.onclick = () => Square.Three.playTurn(playerTurn); 77var s4 = document.querySelector("#square-4")78 s4.onclick = () => Square.Four.playTurn(playerTurn);79var s5 = document.querySelector("#square-5")80 s5.onclick = () => Square.Five.playTurn(playerTurn); 81var s6 = document.querySelector("#square-6")82 s6.onclick = () => Square.Six.playTurn(playerTurn); 83var s7 = document.querySelector("#square-7")84 s7.onclick = () => Square.Seven.playTurn(playerTurn); 85var s8 = document.querySelector("#square-8")86 s8.onclick = () => Square.Eight.playTurn(playerTurn); 87var s9 = document.querySelector("#square-9")88 s9.onclick = () => Square.Nine.playTurn(playerTurn); 89var btnReset = document.querySelector("#reset")90 btnReset.onclick = () => Square.resetBoard();91//Updates tic-tac-toe square divs92function updateDisplay() {93 s1.innerHTML = Square.One.checkStatus();94 s2.innerHTML = Square.Two.checkStatus();95 s3.innerHTML = Square.Three.checkStatus();96 s4.innerHTML = Square.Four.checkStatus();97 s5.innerHTML = Square.Five.checkStatus();98 s6.innerHTML = Square.Six.checkStatus();99 s7.innerHTML = Square.Seven.checkStatus();100 s8.innerHTML = Square.Eight.checkStatus();101 s9.innerHTML = Square.Nine.checkStatus();102 if (playerTurn == "X") {103 document.querySelector(".turn").innerHTML = "Turn: Player Two"104 };105 if (playerTurn == "O") {106 document.querySelector(".turn").innerHTML = "Turn: Player One";107 };108};109/*110Gameboard object has 9 squares111each square has 3 status: x/o/null112 square status is connect to DOM113Gb object has win/lose property114win/lose property determined by correct lines115correct lines can be defined by either player X or player O...

Full Screen

Full Screen

areaEdit.js

Source:areaEdit.js Github

copy

Full Screen

1import $ from 'jquery'2const checkAllTohoku = function checkAll() {3 const checkStatus = $('input[name="tohoku"]').prop('checked')4 $('input[value="hokkaido"]').prop('checked', checkStatus)5 $('input[value="aomori"]').prop('checked', checkStatus)6 $('input[value="iwate"]').prop('checked', checkStatus)7 $('input[value="miyagi"]').prop('checked', checkStatus)8 $('input[value="akita"]').prop('checked', checkStatus)9 $('input[value="yamagata"]').prop('checked', checkStatus)10 $('input[value="hukushima"]').prop('checked', checkStatus)11}12const checkAllKanto = function checkAll() {13 const checkStatus = $('input[name="kanto"]').prop('checked')14 $('input[value="ibaraki"]').prop('checked', checkStatus)15 $('input[value="tochigi"]').prop('checked', checkStatus)16 $('input[value="gunma"]').prop('checked', checkStatus)17 $('input[value="saitama"]').prop('checked', checkStatus)18 $('input[value="chiba"]').prop('checked', checkStatus)19 $('input[value="tokyo"]').prop('checked', checkStatus)20 $('input[value="kanagawa"]').prop('checked', checkStatus)21}22const checkAllHokuriku = function checkAll() {23 const checkStatus = $('input[name="hokuriku"]').prop('checked')24 $('input[value="niigata"]').prop('checked', checkStatus)25 $('input[value="toyama"]').prop('checked', checkStatus)26 $('input[value="ishikawa"]').prop('checked', checkStatus)27 $('input[value="hukui"]').prop('checked', checkStatus)28 $('input[value="yamanashi"]').prop('checked', checkStatus)29 $('input[value="nagano"]').prop('checked', checkStatus)30}31const checkAllTokai = function checkAll() {32 const checkStatus = $('input[name="tokai"]').prop('checked')33 $('input[value="gihu"]').prop('checked', checkStatus)34 $('input[value="shizuoka"]').prop('checked', checkStatus)35 $('input[value="aichi"]').prop('checked', checkStatus)36 $('input[value="mie"]').prop('checked', checkStatus)37}38const checkAllKinki = function checkAll() {39 const checkStatus = $('input[name="kinki"]').prop('checked')40 $('input[value="shiga"]').prop('checked', checkStatus)41 $('input[value="kyoto"]').prop('checked', checkStatus)42 $('input[value="osaka"]').prop('checked', checkStatus)43 $('input[value="hyogo"]').prop('checked', checkStatus)44 $('input[value="nara"]').prop('checked', checkStatus)45 $('input[value="wakayama"]').prop('checked', checkStatus)46}47const checkAllChugoku = function checkAll() {48 const checkStatus = $('input[name="chugoku"]').prop('checked')49 $('input[value="tottori"]').prop('checked', checkStatus)50 $('input[value="shimane"]').prop('checked', checkStatus)51 $('input[value="okayama"]').prop('checked', checkStatus)52 $('input[value="hiroshima"]').prop('checked', checkStatus)53 $('input[value="yamaguchi"]').prop('checked', checkStatus)54 $('input[value="tokushima"]').prop('checked', checkStatus)55 $('input[value="kagawa"]').prop('checked', checkStatus)56 $('input[value="ehime"]').prop('checked', checkStatus)57 $('input[value="kochi"]').prop('checked', checkStatus)58}59const checkAllKyusyu = function checkAll() {60 const checkStatus = $('input[name="kyusyu"]').prop('checked')61 $('input[value="hukuoka"]').prop('checked', checkStatus)62 $('input[value="saga"]').prop('checked', checkStatus)63 $('input[value="nagasaki"]').prop('checked', checkStatus)64 $('input[value="kumamoto"]').prop('checked', checkStatus)65 $('input[value="oita"]').prop('checked', checkStatus)66 $('input[value="miyazaki"]').prop('checked', checkStatus)67 $('input[value="kagoshima"]').prop('checked', checkStatus)68 $('input[value="okinawa"]').prop('checked', checkStatus)69}70window.checkAllTohoku = checkAllTohoku71window.checkAllKanto = checkAllKanto72window.checkAllHokuriku = checkAllHokuriku73window.checkAllTokai = checkAllTokai74window.checkAllKinki = checkAllKinki75window.checkAllChugoku = checkAllChugoku...

Full Screen

Full Screen

hp_list.js

Source:hp_list.js Github

copy

Full Screen

...12 });13 })14 //修改15 $('.bt_update').on('click', function() {16 var checkStatus = layui.table.checkStatus($('table').attr("id"));17 if (checkStatus.data.length<1) {18 layer.msg("至少选择一行数据", {icon: 2, time: 1500});19 return;20 }21 if (checkStatus.data.length>1) {22 layer.msg("至多只能选择一行数据", {icon: 2, time: 1500});23 return;24 }25 var id = checkStatus.data[0].id;26 var d = $(this).attr("data");27 layer.open({28 type : 2,29 title : '修改',30 shadeClose : true,31 area : [ d.split(",")[0], d.split(",")[1]],32 content : $(this).attr("data-url")+"?id="+id33 });34 })35 //删除36 $('.bt_delete').on('click', function() {37 console.log("ok");38 var checkStatus = layui.table.checkStatus($('table').attr("id"));39 if (checkStatus.data.length<1) {40 layer.msg("至少选择一行数据", {icon: 2, time: 1500});41 return;42 };43 let url= $(this).attr("data-url");44 // 接着,进行删除确认45 layer.confirm("确认要删除吗,删除后不能恢复", { title: "删除确认" }, function (index) {46 $.ajax({47 type: "POST",48 url: url,49 contentType : "application/json",50 dataType: 'json',51 data: JSON.stringify(checkStatus.data),52 success: function(data){53 if (data.result==true) {54 layer.msg(data.msg, {icon: 1, time: 1500});55 layui.table.reload($('table.layui-hide').attr("id"));56 }else {57 layer.msg(data.msg, {icon: 2, time: 1500});58 }59 },60 error: function(res){61 layer.msg("未知异常", {icon: 2});62 }63 });64 });65 });66 //分配角色67 $('.bt_setRole').on('click', function() {68 console.log("ok");69 var checkStatus = layui.table.checkStatus($('table').attr("id"));70 if (checkStatus.data.length<1) {71 layer.msg("至少选择一行数据", {icon: 2, time: 1500});72 return;73 }74 if (checkStatus.data.length>1) {75 layer.msg("至多只能选择一行数据", {icon: 2, time: 1500});76 return;77 }78 var id = checkStatus.data[0].id;79 var d = $(this).attr("data");80 layer.open({81 type : 2,82 title : '设置角色',83 shadeClose : true,84 area : [ d.split(",")[0], d.split(",")[1]],85 content : $(this).attr("data-url")+"?id="+id86 });87 });88 //分配权限89 $('.bt_setMenu').on('click', function() {90 console.log("ok");91 var checkStatus = layui.table.checkStatus($('table').attr("id"));92 if (checkStatus.data.length<1) {93 layer.msg("至少选择一行数据", {icon: 2, time: 1500});94 return;95 }96 if (checkStatus.data.length>1) {97 layer.msg("至多只能选择一行数据", {icon: 2, time: 1500});98 return;99 }100 var id = checkStatus.data[0].id;101 var d = $(this).attr("data");102 layer.open({103 type : 2,104 title : '设置权限',105 shadeClose : true,...

Full Screen

Full Screen

controller.js

Source:controller.js Github

copy

Full Screen

...15 showEle("#repassBox");16 show("model","添加用户",550,500);17 }18 $scope.showUpdate=function(){19 var checkStatus = table.checkStatus('userTable');20 fomrReset("manager");21 if(checkStatus.data.length!=0){22 $('input[name="id"]').val(checkStatus.data[0].id);23 $('input[name="loginName"]').val(checkStatus.data[0].loginName);24 $("#sex").val(checkStatus.data[0].sex);25 $("#password").attr("verify", "");26 $("#repass").attr("verify", "");27 hideEle("#passwordBox");28 hideEle("#repassBox");29 $('input[name="userName"]').val(checkStatus.data[0].userName);30 $('input[name="email"]').val(checkStatus.data[0].email);31 $('input[name="phone"]').val(checkStatus.data[0].phone);32 show("model","修改用户",550,500);33 }else{34 showMes("info","请选择数据!");35 }36 37 }38 $scope.showDelete=function(){39 var checkStatus = table.checkStatus('userTable');40 if(checkStatus.data.length!=0){41 $scope.userNameText=checkStatus.data[0].userName;42 show("modelDelete","删除用户",300,200);43 }else{44 showMes("info","请选择用户!");45 }46 47 48 }49 $scope.showRole=function(){50 var checkStatus = table.checkStatus('userTable');51 if(checkStatus.data.length!=0){52 show("modelRole","授予角色",600,600);53 user.setRole(checkStatus.data[0].id);54 }else{55 showMes("info","请选择用户!");56 }57 58 59 }60 $scope.saveRole=function(){61 var getData = transfer.getData('roleList'); //获取右侧数据62 console.log(JSON.stringify(getData))63 var checkStatus = table.checkStatus('userTable');64 if(checkStatus.data.length!=0){65 user.saveRole(checkStatus.data[0].id,getData);66 }else{67 showMes("info","请选择用户!");68 }69 }70 $scope.updatePassword=function(){71 var checkStatus = table.checkStatus('userTable');72 if(checkStatus.data.length!=0){73 console.log(checkStatus.data[0].id)74 user.updatePassword(checkStatus.data[0].id);75 }else{76 showMes("info","请选择用户!");77 }78 }79 $scope.close=function(){80 hide("modelDelete");81 hide("model");82 hide("modelRole");83 }84 $scope.ok=function(){85 var checkStatus = table.checkStatus('userTable');86 user.deleteUser(checkStatus.data[0].id);87 hide("modelDelete");88 }89 $scope.save=function(){90 if(verificationForm("manager")){91 user.save();92 }93 }94 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 const articleHeader = await Selector('.result-content').find('h1');6 let headerText = await articleHeader.innerText;7 console.log(headerText);8});9import { Selector } from 'testcafe';10test('My first test', async t => {11 .typeText('#developer-name', 'John Smith')12 .click('#submit-button');13 const articleHeader = await Selector('.result-content').find('h1');14 let headerText = await articleHeader.innerText;15 console.log(headerText);16});17import { Selector } from 'testcafe';18test('My first test', async t => {19 .typeText('#developer-name', 'John Smith')20 .click('#submit-button');21 const articleHeader = await Selector('.result-content').find('h1');22 let headerText = await articleHeader.innerText;23 console.log(headerText);24});25import { Selector } from 'testcafe';26test('My first test', async t => {27 .typeText('#developer-name', 'John Smith')28 .click('#submit-button');29 const articleHeader = await Selector('.result-content').find('h1');30 let headerText = await articleHeader.innerText;31 console.log(headerText);32});33import {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 .typeText('#developer-name', 'John Smith')10 .click('#submit-button');11 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');12});13import { Selector } from 'testcafe';14test('My first test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button');17 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');18});19import { Selector } from 'testcafe';20test('My first test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#submit-button');23 await t.expect(Selector('#article-header').innerText).eql('Thank you, John Smith!');24});25import { Selector } from 'testcafe';

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My test', async t => {3 const developerNameInput = Selector('#developer-name');4 .typeText(developerNameInput, 'Peter')5 .click('#submit-button')6 .checkStatus(200);7});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 console.log(await t.checkStatus());4});5import { Selector } from 'testcafe';6export default class TestCafePage {7 constructor () {8 this.nameInput = Selector('#developer-name');9 this.submitButton = Selector('#submit-button');10 }11 async checkStatus () {12 return 'ok';13 }14}15import TestCafePage from './src/index';16test('My first test', async t => {17 const testCafePage = new TestCafePage();18 console.log(await testCafePage.checkStatus());19});20import { Selector } from 'testcafe';21export default class TestCafePage {22 constructor () {23 this.nameInput = Selector('#developer-name');24 this.submitButton = Selector('#submit-button');25 }26 async checkStatus () {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My first test', async t => {3 .click(Selector('button').withText('Sign In'))4 .click(Selector('button').withText('Sign In'))5 .expect(Selector('p').innerText).eql('You are not logged in.');6});7import { Selector } from 'testcafe';8test('My first test', async t => {9 .click(Selector('button').withText('Sign In'))10 .click(Selector('button').withText('Sign In'))11 .expect(Selector('p').innerText).eql('You are not logged in.');12});13The fix is to use the checkStatus method of TestCafe. This method will wait until the element is in the expected state (in this case, the text of the button is “Sign In”), and then it will continue with the test. The code for this test is:14import { Selector } from 'testcafe';15test('My first test', async t => {16 .click(Selector('button').withText('Sign In'))17 .click(Selector('button').withText('Sign In').checkStatus('Sign In'))18 .expect(Selector('p').innerText).eql('You are not logged in.');19});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { Selector } from 'testcafe';2test('My Test', async t => {3 .typeText('#developer-name', 'John Smith')4 .click('#submit-button');5 await t.checkStatus(200);6});7import { Selector } from 'testcafe';8test('My Test', async t => {9 .typeText('#developer-name', 'John Smith')10 .click('#submit-button');11 await t.checkStatus(200);12});13import { Selector } from 'testcafe';14test('My Test', async t => {15 .typeText('#developer-name', 'John Smith')16 .click('#submit-button')17 .checkStatus(200);18});19import { Selector } from 'testcafe';20test('My Test', async t => {21 .typeText('#developer-name', 'John Smith')22 .click('#submit-button')23 .checkStatus(200);24});

Full Screen

Using AI Code Generation

copy

Full Screen

1import { checkStatus } from 'testcafe';2import { Selector } from 'testcafe';3test('My Test', async t => {4 .expect(checkStatus()).eql(200)5 .expect(Selector('body').innerText).contains('Hello, world!');6});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcafe automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful