UNPKG

trc-client-core

Version:
133 lines (107 loc) 3.94 kB
import Reflux from 'reflux'; import xhr from 'trc-client-core/src/utils/xhr'; import UserStore from 'trc-client-core/src/user/UserStore'; import {createAction} from 'redux-actions'; import createRequestActions from 'trc-client-core/src/utils/createRequestActions'; import { Map, fromJS, OrderedMap } from 'immutable'; import { TECHNICAL_TRAINING, CLASS_SIZES, STREAM_CERTIFICATION, STREAM_ELIGIBILITY, LEARNING_PLAN_ENDPOINT, TECHNICAL_TRAINING_REQUESTS_ENDPOINT } from 'trc-client-core/src/constants/Endpoints'; import { GAP_REPORT_FETCH, GAP_REPORT_RECEIVE, GAP_REPORT_ERROR, TECHNICAL_TRAINING_REQUESTS_FETCH, TECHNICAL_TRAINING_REQUESTS_RECEIVE, TECHNICAL_TRAINING_REQUESTS_ERROR } from 'trc-client-core/src/constants/ActionTypes' var async = {asyncResult: true}; var ReportActions = Reflux.createActions({ 'changeRegion': {}, 'fetchClassSizes': async, 'fetchClassSizesAccumulative': async, 'fetchDealerCodes': async, 'fetchDmtData': async, 'fetchStreamCertification': async, 'fetchStreamEligibility': async, 'fetchTrainingDelivery': async }); ReportActions.fetchDealerCodes.listenAndPromise(function() { return xhr.get('/admin/region_dealer_map/service'); }); const gapReportFetch = createAction(GAP_REPORT_FETCH); const gapReportReceive = createAction(GAP_REPORT_RECEIVE); const gapReportError = createAction(GAP_REPORT_ERROR); ReportActions.gapReportRequest = function(query) { // query fix: backend doesn't understand dealerCode=ALL_DEALERS, so remove it // should be addressed as a backend fix if(query.dealerCode == 'ALL_DEALERS') { delete query.dealerCode; } // query fix: remove region from query if we're searching on a dealer code // or else back end will ignore the dealerCode param if(query.dealerCode) { delete query.region; } var {pathwayId} = query; var url; switch(pathwayId) { case 'incomplete_prerequisites': url = '/admin/report/incomplete_prerequisite'; break case 'incomplete_pt_prerequisites': url = '/api/admin/report/pt_incomplete_prerequisite'; break; case 'product_training_plan': var lexusSuffix = (UserStore.get('site') === 'LEXUS') ? '_lexus' : ''; url = LEARNING_PLAN_ENDPOINT + pathwayId + lexusSuffix; break; default: url = LEARNING_PLAN_ENDPOINT + pathwayId; } return (dispatch) => { if (!xhr.requests()[url]) { dispatch(gapReportFetch(query)); xhr.get(url, query).then( (data) => dispatch(gapReportReceive({ gapReport: data, pathwayId: pathwayId })), (error) => dispatch(gapReportError(error)) ); } }; } ReportActions.technicalTrainingRequestsRequest = createRequestActions( TECHNICAL_TRAINING_REQUESTS_FETCH, TECHNICAL_TRAINING_REQUESTS_RECEIVE, TECHNICAL_TRAINING_REQUESTS_ERROR, () => xhr.get(TECHNICAL_TRAINING_REQUESTS_ENDPOINT) ); // // Technical Reports ReportActions.fetchTrainingDelivery.listenAndPromise(function(query) { return xhr.get(TECHNICAL_TRAINING, query); }); ReportActions.fetchClassSizes.listenAndPromise(function(query) { return xhr.get(CLASS_SIZES, query); }); ReportActions.fetchClassSizesAccumulative.listenAndPromise(function(query) { query.accumulative = true; return xhr.get(CLASS_SIZES, query); }); ReportActions.fetchStreamCertification.listenAndPromise(function(query) { return xhr.get(STREAM_CERTIFICATION, query); }); ReportActions.fetchStreamEligibility.listenAndPromise(function(query) { return xhr.get(STREAM_ELIGIBILITY, query); }); ReportActions.fetchDmtData.listenAndPromise(function() { return xhr.get('/api/report/dmt?certCode=ANY'); }); module.exports = ReportActions;