forked from MichaelYick/mailpoet
Convert "is in Country" select to multiple select
[MAILPOET-3952]
This commit is contained in:
parent
9a9ab257c2
commit
8292cd9fd3
@ -57,7 +57,9 @@ export function validateWooCommerce(formItems: WooCommerceFormItem): boolean {
|
||||
if (formItems.action === WooCommerceActionTypes.PURCHASED_PRODUCT && purchasedProductIsInvalid) {
|
||||
return false;
|
||||
}
|
||||
if (formItems.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY && !formItems.country_code) {
|
||||
const countryCodeIsInvalid = formItems.country_code === undefined
|
||||
|| formItems.country_code.length === 0;
|
||||
if (formItems.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY && countryCodeIsInvalid) {
|
||||
return false;
|
||||
}
|
||||
const numberOfOrdersIsInvalid = !formItems.number_of_orders_count
|
||||
@ -320,21 +322,32 @@ export const WooCommerceFields: React.FunctionComponent<Props> = ({ filterIndex
|
||||
);
|
||||
} else if (segment.action === WooCommerceActionTypes.CUSTOMER_IN_COUNTRY) {
|
||||
optionFields = (
|
||||
<div>
|
||||
<ReactSelect
|
||||
dimension="small"
|
||||
key="select-segment-country"
|
||||
isFullWidth
|
||||
placeholder={MailPoet.I18n.t('selectWooCountry')}
|
||||
options={countryOptions}
|
||||
value={find(['value', segment.country_code], countryOptions)}
|
||||
onChange={(option: SelectOption): void => updateSegmentFilter(
|
||||
{ country_code: option.value },
|
||||
filterIndex
|
||||
)}
|
||||
automationId="select-segment-country"
|
||||
/>
|
||||
</div>
|
||||
<>
|
||||
<Grid.CenteredRow>
|
||||
<ReactSelect
|
||||
dimension="small"
|
||||
key="select-segment-country"
|
||||
isFullWidth
|
||||
isMulti
|
||||
placeholder={MailPoet.I18n.t('selectWooCountry')}
|
||||
options={countryOptions}
|
||||
value={
|
||||
filter(
|
||||
(option) => {
|
||||
if (!segment.country_code) return undefined;
|
||||
return segment.country_code.indexOf(option.value) !== -1;
|
||||
},
|
||||
countryOptions
|
||||
)
|
||||
}
|
||||
onChange={(options: SelectOption[]): void => updateSegmentFilter(
|
||||
{ country_code: (options || []).map((x: SelectOption) => x.value) },
|
||||
filterIndex
|
||||
)}
|
||||
automationId="select-segment-country"
|
||||
/>
|
||||
</Grid.CenteredRow>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -81,7 +81,7 @@ export interface WooCommerceFormItem extends FormItem {
|
||||
total_spent_type?: string;
|
||||
total_spent_amount?: number;
|
||||
total_spent_days?: number;
|
||||
country_code?: string;
|
||||
country_code?: string[];
|
||||
}
|
||||
|
||||
export interface WooCommerceSubscriptionFormItem extends FormItem {
|
||||
|
@ -51,6 +51,10 @@ class DynamicSegmentsResponseBuilder {
|
||||
$filter['id'] = $dynamicFilter->getId();
|
||||
$filter['segmentType'] = $dynamicFilter->getFilterData()->getFilterType(); // We need to add filterType with key segmentType due to BC
|
||||
$filter['action'] = $dynamicFilter->getFilterData()->getAction();
|
||||
if (isset($filter['country_code']) && !is_array($filter['country_code'])) {
|
||||
// Convert to multiple values filter
|
||||
$filter['country_code'] = [$filter['country_code']];
|
||||
}
|
||||
if (isset($filter['wordpressRole']) && !is_array($filter['wordpressRole'])) {
|
||||
// new filters are always array, they support multiple values, the old didn't convert old filters to new format
|
||||
$filter['wordpressRole'] = [$filter['wordpressRole']];
|
||||
|
@ -215,7 +215,7 @@
|
||||
'wooTotalSpentAmount': __('amount'),
|
||||
'selectWooPurchasedCategory': __('Search categories'),
|
||||
'selectWooPurchasedProduct': __('Search products'),
|
||||
'selectWooCountry': __('Select country'),
|
||||
'selectWooCountry': __('Search countries'),
|
||||
'woocommerce': _x('WooCommerce', 'Dynamic segment creation: User selects this to use any woocommerce filters'),
|
||||
|
||||
'dynamicSegmentSizeIsCalculated': __('Calculating segment size…'),
|
||||
|
Loading…
x
Reference in New Issue
Block a user