Fix code that set a default value for item.number_of_orders_type

[MAILPOET-3228]
This commit is contained in:
Rodrigo Primo
2021-04-14 14:19:03 -03:00
committed by Veljko V
parent 4f3738b0b1
commit 224348a55e

View File

@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import MailPoet from 'mailpoet';
import { assign, compose, find } from 'lodash/fp';
import Select from 'common/form/react_select/react_select';
@@ -69,6 +69,15 @@ export const WooCommerceFields: React.FunctionComponent<Props> = ({ onChange, it
let optionFields;
useEffect(() => {
if (
item.number_of_orders_type === undefined
&& item.action === WooCommerceActionTypes.NUMBER_OF_ORDERS
) {
onChange(assign(item, { number_of_orders_type: '=' }));
}
}, [onChange, item]);
if (item.action === WooCommerceActionTypes.PURCHASED_PRODUCT) {
optionFields = (
<Select
@@ -98,10 +107,6 @@ export const WooCommerceFields: React.FunctionComponent<Props> = ({ onChange, it
/>
);
} else if (item.action === WooCommerceActionTypes.NUMBER_OF_ORDERS) {
if (!item.number_of_orders_type) {
item.number_of_orders_type = '=';
}
optionFields = (
<div>
<Grid.CenteredRow className="mailpoet-form-field">