Commit 865594a5 authored by Roman's avatar Roman

BRCD-1762 feat(Entities) - added action to remove entities fields

parent 4c9a4439
......@@ -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,
......
......@@ -26,6 +26,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 +81,10 @@ class Customer extends Component {
this.props.onChange(e);
};
onChangeCustomField = (fieldPath) => {
this.props.onRemoveField(fieldPath);
};
renderPaymentGatewayLabel = () => {
const { customer, supportedGateways } = this.props;
const customerPgName = customer.getIn(['payment_gateway', 'active', 'name'], '');
......@@ -299,6 +304,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));
}
onChangeCustomerField = (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}
/>
......
......@@ -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,7 +271,7 @@ class Product extends Component {
entityName="rates"
entity={product}
onChangeField={this.onChangeTariffCategory}
onRemoveField={this.onChangeTariffCategory}
onRemoveField={this.onRemoveAdditionalField}
fieldsFilter={this.filterTariffCategory}
editable={editable}
/>
......@@ -322,7 +327,7 @@ class Product extends Component {
entityName="rates"
entity={product}
onChangeField={this.onChangeAdditionalField}
onRemoveField={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,7 +284,7 @@ export default class ServiceDetails extends Component {
entityName="services"
entity={item}
onChangeField={this.onChangeAdditionalField}
onRemoveField={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,
......@@ -33,13 +34,14 @@ const DefaultRate = Immutable.Record({
export default function (state = defaultState, action) {
switch (action.type) {
case PRODUCT_UPDATE_FIELD_VALUE: {
const { path, value } = action;
if (typeof value === 'undefined') {
return state.deleteIn(path);
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.setIn(path, value);
}
return state.deleteIn([action.path]);
case PRODUCT_UPDATE_TO_VALUE: {
return state.updateIn(action.path, Immutable.List(), (list) => {
......
......@@ -12,6 +12,7 @@ import {
CLONE_RESET_SERVICE,
CLEAR_SERVICE,
UPDATE_SERVICE,
DELETE_SERVICE_FIELD,
ADD_GROUP_SERVICE,
REMOVE_GROUP_SERVICE } from '../actions/serviceActions';
......@@ -35,13 +36,14 @@ const serviceReducer = (state = DefaultState, action) => {
case GOT_SERVICE:
return Immutable.fromJS(action.item);
case UPDATE_SERVICE: {
const { path, value } = action;
if (typeof value === 'undefined') {
return state.deleteIn(path);
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.setIn(path, value);
}
return state.deleteIn([action.path]);
case CLONE_RESET_SERVICE: {
const keysToDeleteOnClone = ['_id', 'from', 'to', 'originalValue', ...action.uniquefields];
......
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