Commit 7c4c67ee authored by Shani's avatar Shani

Merge branch 'BRCD-1762' into 'dev'

BRCD-1762 - fix bug with range field belong to play

See merge request !965
parents 83f4d770 8b082ef3
......@@ -42,6 +42,11 @@ export const saveSubscription = (subscription, action) => dispatch =>
dispatch(saveEntity('subscribers', subscription, action))
.then(response => Object.assign(response, { subscription, action }));
export const removeCustomerField = path => ({
type: actions.DELETE_ENTITY_FIELD,
collection: 'customer',
path,
});
export const updateCustomerField = (path, value) => ({
type: actions.UPDATE_ENTITY_FIELD,
......
......@@ -18,6 +18,7 @@ export const PRODUCT_CLEAR = 'PRODUCT_CLEAR';
export const PRODUCT_CLONE_RESET = 'PRODUCT_CLONE_RESET';
export const PRODUCT_ADD_RATE = 'PRODUCT_ADD_RATE';
export const PRODUCT_REMOVE_RATE = 'PRODUCT_REMOVE_RATE';
export const PRODUCT_DELETE_FIELD = 'PRODUCT_DELETE_FIELD';
export const PRODUCT_UPDATE_FIELD_VALUE = 'PRODUCT_UPDATE_FIELD_VALUE';
export const PRODUCT_UPDATE_USAGET_VALUE = 'PRODUCT_UPDATE_USAGET_VALUE';
export const PRODUCT_UPDATE_TO_VALUE = 'PRODUCT_UPDATE_TO_VALUE';
......@@ -38,6 +39,11 @@ export const onFieldUpdate = (path, value) => ({
value,
});
export const onFieldRemove = path => ({
type: PRODUCT_DELETE_FIELD,
path,
});
export const onToUpdate = (path, index, value) => ({
type: PRODUCT_UPDATE_TO_VALUE,
path,
......
......@@ -16,6 +16,7 @@ import {
export const GOT_SERVICE = 'GOT_SERVICE';
export const UPDATE_SERVICE = 'UPDATE_SERVICE';
export const DELETE_SERVICE_FIELD = 'DELETE_SERVICE_FIELD';
export const SAVE_SERVICE = 'SAVE_SERVICE';
export const CLEAR_SERVICE = 'CLEAR_SERVICE';
export const CLONE_RESET_SERVICE = 'CLONE_RESET_SERVICE';
......@@ -44,6 +45,11 @@ export const updateService = (path, value) => ({
value,
});
export const deleteServiceField = path => ({
type: DELETE_SERVICE_FIELD,
path,
});
export const addGroup = (groupName, usages, unit, value, shared, pooled, quantityAffected, products) => ({
type: ADD_GROUP_SERVICE,
groupName,
......
......@@ -11,11 +11,10 @@ import { ConfirmModal } from '../../components/Elements';
import { currencySelector, paymentGatewaysSelector } from '../../selectors/settingsSelector';
import OfflinePayment from '../Payments/OfflinePayment';
import CyclesSelector from '../Cycle/CyclesSelector';
import { getExpectedInvoiceQuery, getSettingsQuery } from '../../common/ApiQueries'
import { buildRequestUrl, apiBillRun } from '../../common/Api'
import { getExpectedInvoiceQuery } from '../../common/ApiQueries';
import { buildRequestUrl } from '../../common/Api';
import EntityFields from '../Entity/EntityFields';
import { getSettings } from '../../actions/settingsActions';
import { getList } from '../../actions/listActions';
import Credit from '../Credit/Credit';
class Customer extends Component {
......@@ -26,6 +25,7 @@ class Customer extends Component {
supportedGateways: PropTypes.instanceOf(Immutable.List),
onChangePaymentGateway: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired,
onRemoveField: PropTypes.func.isRequired,
action: PropTypes.string,
currency: PropTypes.string,
fields: PropTypes.instanceOf(Immutable.List),
......@@ -80,6 +80,10 @@ class Customer extends Component {
this.props.onChange(e);
};
onRemoveCustomField = (fieldPath) => {
this.props.onRemoveField(fieldPath);
};
renderPaymentGatewayLabel = () => {
const { customer, supportedGateways } = this.props;
const customerPgName = customer.getIn(['payment_gateway', 'active', 'name'], '');
......@@ -178,8 +182,8 @@ class Customer extends Component {
onClickExpectedInvoice = () => {
const { customer } = this.props;
const { expectedCyclesNames } = this.state;
let query = getExpectedInvoiceQuery(customer.get('aid'),expectedCyclesNames);
window.open(buildRequestUrl(query))
const query = getExpectedInvoiceQuery(customer.get('aid'), expectedCyclesNames);
window.open(buildRequestUrl(query));
}
......@@ -299,6 +303,7 @@ class Customer extends Component {
entityName={['subscribers', 'account']}
entity={customer}
onChangeField={this.onChangeCustomField}
onRemoveField={this.onRemoveCustomField}
/>
{ (action !== 'create') && this.renderChangePaymentGateway() }
{ (action !== 'create') && this.renderDebt() }
......
......@@ -18,6 +18,7 @@ import {
saveSubscription,
saveCustomer,
updateCustomerField,
removeCustomerField,
clearCustomer,
getCustomer,
getSubscription,
......@@ -131,6 +132,10 @@ class CustomerSetup extends Component {
this.props.dispatch(updateCustomerField(id, value));
}
onRemoveCustomerField = (path) => {
this.props.dispatch(removeCustomerField(path));
}
afterSaveCustomer = (response) => {
const { mode } = this.props;
if (response.status) {
......@@ -248,6 +253,7 @@ class CustomerSetup extends Component {
fields={accountFields}
supportedGateways={gateways}
onChange={this.onChangeCustomerField}
onRemoveField={this.onRemoveCustomerField}
onChangePaymentGateway={this.onClickChangePaymentGateway}
/>
</Panel>
......
......@@ -249,6 +249,10 @@ class Subscription extends Component {
this.setState(prevState => ({ subscription: prevState.subscription.setIn(path, value) }));
}
removeSubscriptionField = (path, value) => {
this.setState(prevState => ({ subscription: prevState.subscription.deleteIn(path, value) }));
}
formatSelectOptions = items => items.map(item => ({
value: item.get('name', ''),
label: item.get('description', item.get('name', '')),
......@@ -438,6 +442,7 @@ class Subscription extends Component {
entityName={['subscribers', 'subscriber']}
entity={subscription}
onChangeField={this.updateSubscriptionField}
onRemoveField={this.removeSubscriptionField}
fieldsFilter={this.filterCustomFields}
editable={allowEdit}
/>
......
......@@ -20,6 +20,7 @@ export default class DiscountDetails extends Component {
currency: PropTypes.string,
errorMessages: PropTypes.object,
onFieldUpdate: PropTypes.func.isRequired,
onFieldRemove: PropTypes.func.isRequired,
availablePlans: PropTypes.instanceOf(Immutable.List),
availableServices: PropTypes.instanceOf(Immutable.List),
}
......@@ -71,6 +72,10 @@ export default class DiscountDetails extends Component {
this.props.onFieldUpdate(field, value);
}
onRemoveAdditionalField = (field) => {
this.props.onFieldRemove(field);
}
onChangeDiscountType = (e) => {
const { value } = e.target;
this.props.onFieldUpdate(['discount_type'], value);
......@@ -261,6 +266,7 @@ export default class DiscountDetails extends Component {
entityName="discounts"
entity={discount}
onChangeField={this.onChangeAdditionalField}
onRemoveField={this.onRemoveAdditionalField}
editable={editable}
/>
......
......@@ -142,6 +142,10 @@ class DiscountSetup extends Component {
}
}
onRemoveFieldValue = (path) => {
this.props.dispatch(deleteDiscountValue(path));
}
onChangeFieldValue = (path, value) => {
const stringPath = Array.isArray(path) ? path.join('.') : path;
const deletePathOnEmptyValue = ['limit', 'cycles', 'params.plan'];
......@@ -239,6 +243,7 @@ class DiscountSetup extends Component {
mode={mode}
currency={currency}
onFieldUpdate={this.onChangeFieldValue}
onFieldRemove={this.onRemoveFieldValue}
availablePlans={availablePlans}
availableServices={availableServices}
/>
......
......@@ -26,6 +26,7 @@ class EntityFields extends Component {
editable: PropTypes.bool,
isPlaysEnabled: PropTypes.bool,
onChangeField: PropTypes.func,
onRemoveField: PropTypes.func,
dispatch: PropTypes.func.isRequired,
};
......@@ -37,6 +38,7 @@ class EntityFields extends Component {
editable: true,
isPlaysEnabled: false,
onChangeField: () => {},
onRemoveField: () => { console.error('Please implement onRemoveField function for EntityFields'); },
}
componentDidMount() {
......@@ -59,12 +61,12 @@ class EntityFields extends Component {
).get('multiple', false);
const shouldResetFields = isMultiple ?
!Immutable.is(entity.get('play', Immutable.List()), oldEntity.get('play', Immutable.List()))
: entity.get('play', '') !== oldEntity.get('play', '')
: entity.get('play', '') !== oldEntity.get('play', '');
if (shouldResetFields) {
fields.forEach((field) => {
const shoudPlayBeDisplayd = this.filterPlayFields(field);
if (!shoudPlayBeDisplayd) {
this.props.onChangeField(field.get('field_name', '').split('.'), '');
this.props.onRemoveField(field.get('field_name', '').split('.'));
}
});
}
......
......@@ -15,6 +15,7 @@ import {
savePlan,
clearPlan,
onPlanFieldUpdate,
onPlanFieldRemove,
onPlanCycleUpdate,
onPlanTariffAdd,
onPlanTariffRemove,
......@@ -153,6 +154,10 @@ class PlanSetup extends Component {
this.props.dispatch(onPlanFieldUpdate(path, value));
}
onRemoveFieldValue = (path) => {
this.props.dispatch(onPlanFieldRemove(path));
}
onDeleteField = (path, value) => {
this.props.dispatch(onPlanFieldUpdate(path, value));
}
......@@ -242,6 +247,7 @@ class PlanSetup extends Component {
mode={mode}
plan={item}
onChangeFieldValue={this.onChangeFieldValue}
onRemoveField={this.onRemoveFieldValue}
onPlanCycleUpdate={this.onPlanCycleUpdate}
onPlanTariffAdd={this.onPlanTariffAdd}
onPlanTariffRemove={this.onPlanTariffRemove}
......
......@@ -21,6 +21,7 @@ export default class Plan extends Component {
plan: React.PropTypes.instanceOf(Immutable.Map).isRequired,
mode: React.PropTypes.string.isRequired,
onChangeFieldValue: React.PropTypes.func.isRequired,
onRemoveField: React.PropTypes.func.isRequired,
onPlanCycleUpdate: React.PropTypes.func.isRequired,
onPlanTariffAdd: React.PropTypes.func.isRequired,
onPlanTariffRemove: React.PropTypes.func.isRequired,
......@@ -116,6 +117,10 @@ export default class Plan extends Component {
this.props.onChangeFieldValue(field, value);
}
onRemoveAdditionalField = (field) => {
this.props.onRemoveField(field);
}
getPeriodicityOptions = () => {
const periodicityOptions = { '': 'Select...', month: 'Monthly', year: 'Yearly' };
return Object.keys(periodicityOptions).map((key, i) =>
......@@ -259,6 +264,7 @@ export default class Plan extends Component {
entityName="plans"
entity={plan}
onChangeField={this.onChangeAdditionalField}
onRemoveField={this.onRemoveAdditionalField}
editable={editable}
/>
......
......@@ -34,6 +34,7 @@ class Product extends Component {
planName: PropTypes.string,
errorMessages: PropTypes.object,
onFieldUpdate: PropTypes.func.isRequired,
onFieldRemove: PropTypes.func.isRequired,
onProductRateAdd: PropTypes.func.isRequired,
onProductRateRemove: PropTypes.func.isRequired,
onToUpdate: PropTypes.func.isRequired,
......@@ -164,6 +165,10 @@ class Product extends Component {
this.props.onFieldUpdate(field, value);
}
onRemoveAdditionalField = (field) => {
this.props.onFieldRemove(field);
}
isRetailRate = (tariffCategory = null) => {
const { product } = this.props;
const category = tariffCategory === null
......@@ -266,6 +271,7 @@ class Product extends Component {
entityName="rates"
entity={product}
onChangeField={this.onChangeTariffCategory}
onRemoveField={this.onRemoveAdditionalField}
fieldsFilter={this.filterTariffCategory}
editable={editable}
/>
......@@ -322,6 +328,7 @@ class Product extends Component {
entityName="rates"
entity={product}
onChangeField={this.onChangeAdditionalField}
onRemoveField={this.onRemoveAdditionalField}
highlightPramas={ratingParams}
editable={editable}
/>
......
......@@ -11,6 +11,7 @@ import {
onRateAdd,
onRateRemove,
onFieldUpdate,
onFieldRemove,
onToUpdate,
onUsagetUpdate,
getProduct,
......@@ -156,6 +157,10 @@ class ProductSetup extends Component {
this.props.dispatch(onFieldUpdate(path, value));
}
onFieldRemove = (path) => {
this.props.dispatch(onFieldRemove(path));
}
onToUpdate = (path, index, value) => {
this.props.dispatch(onToUpdate(path, index, value));
}
......@@ -233,6 +238,7 @@ class ProductSetup extends Component {
<Product
mode={mode}
onFieldUpdate={this.onFieldUpdate}
onFieldRemove={this.onFieldRemove}
onToUpdate={this.onToUpdate}
onProductRateAdd={this.onProductRateAdd}
onProductRateRemove={this.onProductRateRemove}
......
......@@ -20,6 +20,7 @@ export default class ServiceDetails extends Component {
item: PropTypes.instanceOf(Immutable.Map).isRequired,
mode: PropTypes.string.isRequired,
updateItem: PropTypes.func.isRequired,
onFieldRemove: PropTypes.func.isRequired,
errorMessages: PropTypes.object,
}
......@@ -89,6 +90,10 @@ export default class ServiceDetails extends Component {
this.props.updateItem(field, value);
}
onRemoveAdditionalField = (field) => {
this.props.onFieldRemove(field);
}
onChangeServicePeriodType = (e) => {
const { value } = e.target;
this.props.updateItem(['balance_period', 'type'], value);
......@@ -279,6 +284,7 @@ export default class ServiceDetails extends Component {
entityName="services"
entity={item}
onChangeField={this.onChangeAdditionalField}
onRemoveField={this.onRemoveAdditionalField}
editable={editable}
/>
......
......@@ -14,7 +14,16 @@ import {
getConfig,
getItemId,
} from '../../common/Util';
import { addGroup, removeGroup, getService, clearService, updateService, saveService, setCloneService } from '../../actions/serviceActions';
import {
addGroup,
removeGroup,
getService,
clearService,
updateService,
deleteServiceField,
saveService,
setCloneService,
} from '../../actions/serviceActions';
import { showSuccess } from '../../actions/alertsActions';
import { setPageTitle } from '../../actions/guiStateActions/pageActions';
import { clearItems, getRevisions, clearRevisions } from '../../actions/entityListActions';
......@@ -145,6 +154,10 @@ class ServiceSetup extends Component {
this.props.dispatch(updateService(path, value));
}
onRemoveFieldValue = (path) => {
this.props.dispatch(deleteServiceField(path));
}
afterSave = (response) => {
const { mode } = this.props;
this.setState({ progress: false });
......@@ -205,7 +218,12 @@ class ServiceSetup extends Component {
<Tab title="Details" eventKey={1}>
<Panel style={{ borderTop: 'none' }}>
<ServiceDetails item={item} mode={mode} updateItem={this.onUpdateItem} />
<ServiceDetails
item={item}
mode={mode}
updateItem={this.onUpdateItem}
onFieldRemove={this.onRemoveFieldValue}
/>
</Panel>
</Tab>
......
import Immutable from 'immutable';
import {
PRODUCT_DELETE_FIELD,
PRODUCT_UPDATE_FIELD_VALUE,
PRODUCT_UPDATE_USAGET_VALUE,
PRODUCT_UPDATE_TO_VALUE,
......@@ -36,6 +37,12 @@ export default function (state = defaultState, action) {
case PRODUCT_UPDATE_FIELD_VALUE:
return state.setIn(action.path, action.value);
case PRODUCT_DELETE_FIELD:
if (Array.isArray(action.path)) {
return state.deleteIn(action.path);
}
return state.deleteIn([action.path]);
case PRODUCT_UPDATE_TO_VALUE: {
return state.updateIn(action.path, Immutable.List(), (list) => {
if (action.index < list.size - 1) {
......
......@@ -12,6 +12,7 @@ import {
CLONE_RESET_SERVICE,
CLEAR_SERVICE,
UPDATE_SERVICE,
DELETE_SERVICE_FIELD,
ADD_GROUP_SERVICE,
REMOVE_GROUP_SERVICE } from '../actions/serviceActions';
......@@ -38,6 +39,12 @@ const serviceReducer = (state = DefaultState, action) => {
case UPDATE_SERVICE:
return state.setIn(action.path, action.value);
case DELETE_SERVICE_FIELD:
if (Array.isArray(action.path)) {
return state.deleteIn(action.path);
}
return state.deleteIn([action.path]);
case CLONE_RESET_SERVICE: {
const keysToDeleteOnClone = ['_id', 'from', 'to', 'originalValue', ...action.uniquefields];
return state.withMutations((itemWithMutations) => {
......
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