Move data selection to a reusable service

[MAILPOET-2553]
This commit is contained in:
Pavel Dohnal
2020-12-01 17:12:10 +01:00
committed by Veljko V
parent daaeada3da
commit 344a338376
8 changed files with 75 additions and 64 deletions

View File

@@ -57,8 +57,8 @@ export const EventOptions = ({
(data) => ({ id: data.id, name: data.text })
),
selected: () => selected,
getLabel: undefined,
getValue: undefined,
getLabel: _.property('name'),
getValue: _.property('id'),
},
onValueChange: handleEventOptionChange,
item: {
@@ -67,15 +67,11 @@ export const EventOptions = ({
};
if (eventOptions.endpoint === 'product_categories') {
fieldProps.field.getLabel = _.property('cat_name');
fieldProps.field.name = 'category_id';
fieldProps.field.getValue = _.property('term_id');
fieldProps.item = { action: 'purchasedCategory' };
}
if (eventOptions.endpoint === 'products') {
fieldProps.field.getLabel = _.property('title');
fieldProps.field.getValue = _.property('ID');
fieldProps.field.name = 'product_id';
fieldProps.item = { action: 'purchasedProduct' };
}

View File

@@ -18,8 +18,8 @@ const categoriesField = {
resetSelect2OnUpdate: true,
placeholder: MailPoet.I18n.t('selectWooPurchasedCategory'),
forceSelect2: true,
getLabel: _.property('cat_name'),
getValue: _.property('term_id'),
getLabel: _.property('name'),
getValue: _.property('id'),
};
const productsField = {
@@ -29,8 +29,8 @@ const productsField = {
resetSelect2OnUpdate: true,
placeholder: MailPoet.I18n.t('selectWooPurchasedProduct'),
forceSelect2: true,
getLabel: _.property('title'),
getValue: _.property('ID'),
getLabel: _.property('name'),
getValue: _.property('id'),
};
export default (formItems) => {