Commit 2db1d4c1 authored by Roman's avatar Roman

BRCD-1762 fix(Plays-Service) - remove play field on play change

parent ec9b0048
......@@ -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('.'));
}
});
}
......
......@@ -89,6 +89,10 @@ export default class ServiceDetails extends Component {
this.props.updateItem(field, value);
}
onRemoveAdditionalField = (field) => {
this.props.updateItem(field, null);
}
onChangeServicePeriodType = (e) => {
const { value } = e.target;
this.props.updateItem(['balance_period', 'type'], value);
......@@ -279,6 +283,7 @@ export default class ServiceDetails extends Component {
entityName="services"
entity={item}
onChangeField={this.onChangeAdditionalField}
onRemoveField={this.onRemoveAdditionalField}
editable={editable}
/>
......
......@@ -35,8 +35,13 @@ const serviceReducer = (state = DefaultState, action) => {
case GOT_SERVICE:
return Immutable.fromJS(action.item);
case UPDATE_SERVICE:
return state.setIn(action.path, action.value);
case UPDATE_SERVICE: {
const { path, value } = action;
if (value === null) {
return state.deleteIn(path);
}
return state.setIn(path, value);
}
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