Match select boxes with same select boxes in segments
[MAILPOET-2553]
This commit is contained in:
@ -2,25 +2,20 @@ import React from 'react';
|
|||||||
import Selection from 'form/fields/selection.jsx';
|
import Selection from 'form/fields/selection.jsx';
|
||||||
import _ from 'underscore';
|
import _ from 'underscore';
|
||||||
|
|
||||||
const APIEndpoint = 'automatic_emails';
|
|
||||||
|
|
||||||
type EventOptions = {
|
type EventOptions = {
|
||||||
values: {
|
values?: {
|
||||||
id: string;
|
id: string;
|
||||||
name: string;
|
name: string;
|
||||||
}[];
|
}[];
|
||||||
multiple: boolean;
|
multiple: boolean;
|
||||||
placeholder: string;
|
placeholder: string;
|
||||||
type: string;
|
endpoint: string;
|
||||||
remoteQueryMinimumInputLength: number;
|
|
||||||
remoteQueryFilter: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
eventOptions: EventOptions;
|
eventOptions: EventOptions;
|
||||||
eventSlug: string;
|
eventSlug: string;
|
||||||
selected: string[];
|
selected: string[];
|
||||||
emailSlug: string;
|
|
||||||
onValueChange: (value) => void;
|
onValueChange: (value) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,7 +32,6 @@ export const EventOptions = ({
|
|||||||
eventOptions,
|
eventOptions,
|
||||||
eventSlug,
|
eventSlug,
|
||||||
selected,
|
selected,
|
||||||
emailSlug,
|
|
||||||
onValueChange,
|
onValueChange,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
function handleEventOptionChange(e) {
|
function handleEventOptionChange(e) {
|
||||||
@ -51,38 +45,39 @@ export const EventOptions = ({
|
|||||||
|
|
||||||
const fieldProps = {
|
const fieldProps = {
|
||||||
field: {
|
field: {
|
||||||
id: `event_options_${eventSlug}`,
|
|
||||||
name: `event_options_${eventSlug}`,
|
name: `event_options_${eventSlug}`,
|
||||||
forceSelect2: true,
|
forceSelect2: true,
|
||||||
|
endpoint: eventOptions.endpoint,
|
||||||
resetSelect2OnUpdate: true,
|
resetSelect2OnUpdate: true,
|
||||||
values: getEventOptionsValues(eventOptions),
|
values: getEventOptionsValues(eventOptions),
|
||||||
multiple: eventOptions.multiple || false,
|
multiple: eventOptions.multiple || false,
|
||||||
placeholder: eventOptions.placeholder || false,
|
placeholder: eventOptions.placeholder || false,
|
||||||
extendSelect2Options: {
|
|
||||||
minimumResultsForSearch: Infinity,
|
|
||||||
},
|
|
||||||
transformChangedValue: (value, valueTextPair) => _.map(
|
transformChangedValue: (value, valueTextPair) => _.map(
|
||||||
valueTextPair,
|
valueTextPair,
|
||||||
(data) => ({ id: data.id, name: data.text })
|
(data) => ({ id: data.id, name: data.text })
|
||||||
),
|
),
|
||||||
selected: () => selected,
|
selected: () => selected,
|
||||||
|
getLabel: undefined,
|
||||||
|
getValue: undefined,
|
||||||
},
|
},
|
||||||
onValueChange: handleEventOptionChange,
|
onValueChange: handleEventOptionChange,
|
||||||
|
item: {
|
||||||
|
action: '',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (eventOptions.type === 'remote') {
|
if (eventOptions.endpoint === 'product_categories') {
|
||||||
fieldProps.field = _.extend(fieldProps.field, {
|
fieldProps.field.getLabel = _.property('cat_name');
|
||||||
remoteQuery: {
|
fieldProps.field.name = 'category_id';
|
||||||
minimumInputLength: eventOptions.remoteQueryMinimumInputLength || null,
|
fieldProps.field.getValue = _.property('term_id');
|
||||||
endpoint: APIEndpoint,
|
fieldProps.item = { action: 'purchasedCategory' };
|
||||||
method: 'get_event_options',
|
}
|
||||||
data: {
|
|
||||||
filter: eventOptions.remoteQueryFilter || null,
|
if (eventOptions.endpoint === 'products') {
|
||||||
email_slug: emailSlug,
|
fieldProps.field.getLabel = _.property('title');
|
||||||
event_slug: eventSlug,
|
fieldProps.field.getValue = _.property('ID');
|
||||||
},
|
fieldProps.field.name = 'product_id';
|
||||||
},
|
fieldProps.item = { action: 'purchasedProduct' };
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -90,6 +85,7 @@ export const EventOptions = ({
|
|||||||
<Selection
|
<Selection
|
||||||
field={fieldProps.field}
|
field={fieldProps.field}
|
||||||
onValueChange={fieldProps.onValueChange}
|
onValueChange={fieldProps.onValueChange}
|
||||||
|
item={fieldProps.item}
|
||||||
/>
|
/>
|
||||||
<div className="mailpoet-gap" />
|
<div className="mailpoet-gap" />
|
||||||
</>
|
</>
|
||||||
|
@ -168,6 +168,27 @@ class Newsletters {
|
|||||||
$data['display_detailed_stats'] = Installer::getPremiumStatus()['premium_plugin_initialized'];
|
$data['display_detailed_stats'] = Installer::getPremiumStatus()['premium_plugin_initialized'];
|
||||||
$data['newsletters_templates_recently_sent_count'] = $this->newsletterTemplatesRepository->getRecentlySentCount();
|
$data['newsletters_templates_recently_sent_count'] = $this->newsletterTemplatesRepository->getRecentlySentCount();
|
||||||
|
|
||||||
|
$data['product_categories'] = $this->wp->getCategories(['taxonomy' => 'product_cat']);
|
||||||
|
|
||||||
|
usort($data['product_categories'], function ($a, $b) {
|
||||||
|
return strcmp($a->catName, $b->catName);
|
||||||
|
});
|
||||||
|
|
||||||
|
$data['products'] = $this->getProducts();
|
||||||
|
|
||||||
$this->pageRenderer->displayPage('newsletters.html', $data);
|
$this->pageRenderer->displayPage('newsletters.html', $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getProducts() {
|
||||||
|
$products = $this->wp->getResultsFromWpDb(
|
||||||
|
"SELECT `ID`, `post_title` FROM {$this->wp->getWPTableName('posts')} WHERE `post_type` = %s ORDER BY `post_title` ASC;",
|
||||||
|
'product'
|
||||||
|
);
|
||||||
|
return array_map(function ($product) {
|
||||||
|
return [
|
||||||
|
'title' => $product->post_title, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.NotCamelCaps
|
||||||
|
'ID' => $product->ID,
|
||||||
|
];
|
||||||
|
}, $products);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,10 +45,8 @@ class PurchasedInCategory {
|
|||||||
'listingScheduleDisplayTextPlural' => __('Email sent when a customer buys a product in categories: %s', 'mailpoet'),
|
'listingScheduleDisplayTextPlural' => __('Email sent when a customer buys a product in categories: %s', 'mailpoet'),
|
||||||
'options' => [
|
'options' => [
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'type' => 'remote',
|
'endpoint' => 'product_categories',
|
||||||
'remoteQueryMinimumInputLength' => 3,
|
'placeholder' => _x('Search category', 'Search input for product category (ecommerce)', 'mailpoet'),
|
||||||
'remoteQueryFilter' => 'woocommerce_product_purchased_get_categories',
|
|
||||||
'placeholder' => _x('Start typing to search for categories…', 'Search input for product category (ecommerce)', 'mailpoet'),
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -66,11 +66,9 @@ class PurchasedProduct {
|
|||||||
'listingScheduleDisplayText' => WPFunctions::get()->__('Email sent when a customer buys product: %s', 'mailpoet'),
|
'listingScheduleDisplayText' => WPFunctions::get()->__('Email sent when a customer buys product: %s', 'mailpoet'),
|
||||||
'listingScheduleDisplayTextPlural' => WPFunctions::get()->__('Email sent when a customer buys products: %s', 'mailpoet'),
|
'listingScheduleDisplayTextPlural' => WPFunctions::get()->__('Email sent when a customer buys products: %s', 'mailpoet'),
|
||||||
'options' => [
|
'options' => [
|
||||||
'type' => 'remote',
|
|
||||||
'multiple' => true,
|
'multiple' => true,
|
||||||
'remoteQueryMinimumInputLength' => 3,
|
'endpoint' => 'products',
|
||||||
'remoteQueryFilter' => 'woocommerce_product_purchased_get_products',
|
'placeholder' => __('Search products', 'mailpoet'),
|
||||||
'placeholder' => WPFunctions::get()->__('Start typing to search for products...', 'mailpoet'),
|
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -29,6 +29,16 @@
|
|||||||
var mailpoet_premium_active = <%= json_encode(premium_plugin_active) %>;
|
var mailpoet_premium_active = <%= json_encode(premium_plugin_active) %>;
|
||||||
var mailpoet_transactional_emails_opt_in_notice_dismissed = '<%= transactional_emails_opt_in_notice_dismissed %>';
|
var mailpoet_transactional_emails_opt_in_notice_dismissed = '<%= transactional_emails_opt_in_notice_dismissed %>';
|
||||||
var mailpoet_mss_key_invalid = <%= mss_key_invalid ? 'true' : 'false' %>;
|
var mailpoet_mss_key_invalid = <%= mss_key_invalid ? 'true' : 'false' %>;
|
||||||
|
var mailpoet_product_categories = <%= json_encode(product_categories) %>;
|
||||||
|
mailpoet_product_categories = mailpoet_product_categories.map(function(category) {
|
||||||
|
category.id = category.cat_ID;
|
||||||
|
return category;
|
||||||
|
});
|
||||||
|
var mailpoet_products = <%= json_encode(products) %>;
|
||||||
|
mailpoet_products = mailpoet_products.map(function(product) {
|
||||||
|
product.id = product.ID;
|
||||||
|
return product;
|
||||||
|
});
|
||||||
|
|
||||||
var has_mss_key_specified = <%= json_encode(has_mss_key_specified) %>;
|
var has_mss_key_specified = <%= json_encode(has_mss_key_specified) %>;
|
||||||
var mailpoet_account_url = '<%= add_referral_id("https://account.mailpoet.com/?s=" ~ subscriber_count ~ "&email=" ~ current_wp_user.user_email) | escape('js') %>';
|
var mailpoet_account_url = '<%= add_referral_id("https://account.mailpoet.com/?s=" ~ subscriber_count ~ "&email=" ~ current_wp_user.user_email) | escape('js') %>';
|
||||||
|
Reference in New Issue
Block a user