Commit ac66c6e3 authored by Roman's avatar Roman

BRCD-1677 feat(Play) - filter subscriber Plan and services by Play

parent e6882d9d
......@@ -307,7 +307,7 @@ export const getEntityByIdQuery = (collection, id) => ({
],
});
export const getEntitesQuery = (collection, project = {}, query = {}) => {
export const getEntitesQuery = (collection, project = {}, query = {}, sort = null) => {
let action;
switch (collection) {
case 'users':
......@@ -324,7 +324,7 @@ export const getEntitesQuery = (collection, project = {}, query = {}) => {
{ size: 9999 },
{ query: JSON.stringify(query) },
{ project: JSON.stringify(project) },
{ sort: JSON.stringify(project) },
{ sort: JSON.stringify(sort || project) },
],
});
};
......@@ -353,7 +353,7 @@ export const getDeleteLineQuery = id => ({
// List
export const getPlansQuery = (project = { name: 1 }) => getEntitesQuery('plans', project);
export const getServicesQuery = (project = { name: 1 }) => getEntitesQuery('services', project);
export const getServicesKeysWithInfoQuery = () => getEntitesQuery('services', { name: 1, description: 1, quantitative: 1, balance_period: 1 });
export const getServicesKeysWithInfoQuery = () => getEntitesQuery('services', { name: 1, description: 1, play: 1, quantitative: 1, balance_period: 1 }, {}, { name: 1 });
export const getPrepaidIncludesQuery = () => getEntitesQuery('prepaidincludes');
export const getProductsKeysQuery = (project = { key: 1, description: 1 }, query = {}) => getEntitesQuery('rates', project, query);
export const getRetailProductsKeysQuery = (project = { key: 1, description: 1 }) => {
......@@ -369,7 +369,7 @@ export const getIncludedServicesKeysQuery = () => getEntitesQuery('services', {
quantitative: { $ne: true },
balance_period: { $exists: false },
});
export const getPlansKeysQuery = (project = { name: 1, description: 1 }) => getEntitesQuery('plans', project);
export const getPlansKeysQuery = (project = { name: 1, description: 1 }, query = {}, sort = { name: 1 }) => getEntitesQuery('plans', project, query, sort);
export const getUserKeysQuery = () => getEntitesQuery('users', { username: 1 });
export const getAllGroupsQuery = () => ([
getGroupsQuery('plans'),
......
......@@ -89,7 +89,7 @@ class CustomerSetup extends Component {
this.props.dispatch(setPageTitle(pageTitle));
} else {
this.props.dispatch(getList('available_gateways', getPaymentGatewaysQuery()));
this.props.dispatch(getList('available_plans', getPlansKeysQuery({ name: 1, description: 1, 'include.services': 1 })));
this.props.dispatch(getList('available_plans', getPlansKeysQuery({ name: 1, play: 1, description: 1, 'include.services': 1 })));
this.props.dispatch(getList('available_services', getServicesKeysWithInfoQuery()));
}
}
......
......@@ -129,6 +129,8 @@ class Subscription extends Component {
onChangePlay = (play) => {
this.updateSubscriptionField(['play'], play);
this.filterSubscriptionServicesByPlay(play);
this.filterSubscriptionPlanByPlay(play);
}
onChangeServiceDetails = (index, key, value) => {
......@@ -143,6 +145,32 @@ class Subscription extends Component {
this.updateSubscriptionField(['services'], newServices);
}
filterSubscriptionPlanByPlay = (play) => {
const { subscription } = this.state;
const { allPlans } = this.props;
const selectedPlanPlays = allPlans.find(
plan => plan.get('name', '') === subscription.get('plan', ''),
null, Immutable.Map(),
).get('play', Immutable.List());
if (!selectedPlanPlays.isEmpty() && !selectedPlanPlays.includes(play)) {
this.updateSubscriptionField(['plan'], '');
}
}
filterSubscriptionServicesByPlay = (play) => {
const { allServices } = this.props;
const { subscription } = this.state;
const services = subscription.get('services', Immutable.List()) || Immutable.List();
const newServices = services.filter((service) => {
const servicePlays = allServices.find(
option => option.get('name', '') === service.get('name', ''),
null, Immutable.Map(),
).get('play', Immutable.List());
return servicePlays.isEmpty() || servicePlays.includes(play);
});
this.updateSubscriptionField(['services'], newServices);
}
getServiceType = (service) => {
const { allServices } = this.props;
const serviceName = (Immutable.Map.isMap(service)) ? service.get('name', '') : service;
......@@ -226,7 +254,17 @@ class Subscription extends Component {
label: item.get('description', item.get('name', '')),
}));
getAvailablePlans = () => this.formatSelectOptions(this.props.allPlans);
getAvailablePlans = () => {
const { subscription } = this.state;
const { allPlans } = this.props;
const play = subscription.get('play', false);
if ([false, ''].includes(play)) {
return this.formatSelectOptions(allPlans);
}
return this.formatSelectOptions(allPlans
.filter(allPlan => allPlan.get('play', Immutable.List()).isEmpty() || allPlan.get('play', Immutable.List()).includes(play)),
);
}
getPlanIncludedServices = (planName) => {
if (planName === '') {
......@@ -238,7 +276,17 @@ class Subscription extends Component {
return includedServices.size ? includedServices.join(', ') : '-';
}
getAvailableServices = () => this.formatSelectOptions(this.props.allServices);
getAvailableServices = () => {
const { subscription } = this.state;
const { allServices } = this.props;
const play = subscription.get('play', false);
if ([false, ''].includes(play)) {
return this.formatSelectOptions(allServices);
}
return this.formatSelectOptions(allServices
.filter(allService => allService.get('play', Immutable.List()).isEmpty() || allService.get('play', Immutable.List()).includes(play)),
);
}
filterCustomFields = (field) => {
const hiddenFields = ['plan', 'services', 'play'];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment