trc-client-core
Version:
The core of the TRC Client
37 lines (30 loc) • 1.02 kB
JavaScript
import UserStore from 'trc-client-core/src/user/UserStore';
import regions from 'trc-client-core/src/constants/Regions';
import { Map, fromJS, OrderedMap } from 'immutable';
//
// GapReportUser
// We need to infer user's region and dealerCode from info provided by the user's UserStore
//
const getDetails = () => {
const currentBranchCode = UserStore.get('currentBranchCode');
var userInfo = {};
// currentBranchCode may be a dealerCode or a region - check it against the list of region constants
const isRegion = fromJS(regions)
.map(ii => ii.get('value'))
.toSet()
.includes(currentBranchCode)
if(currentBranchCode == 'TMCA') { // TMCA see all regions
userInfo.region = 'ALL_REGIONS';
} else if(isRegion) {
userInfo.region = currentBranchCode;
} else {
userInfo.dealerCode = currentBranchCode;
}
return userInfo;
};
const merge = (params) => fromJS(params).merge(fromJS(getDetails())).toJS();
const GapReportUser = {
getDetails,
merge
};
export default GapReportUser;