Skip to content

Commit 07a438c

Browse files
authored
Merge pull request #1632 from FromDoppler/dow-111-remove-options-for-woocommerce
[DOW-111] Hidde some options for WooCommerce
2 parents 8d105ef + 07c1796 commit 07a438c

1 file changed

Lines changed: 25 additions & 11 deletions

File tree

src/customJs/tools/promo_code/index.ts

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { $t } from '../../localization';
22
import { PromoCodeViewer } from './PromoCodeViewer';
3-
import { ReactToolDefinitionFrom, UnlayerProperty } from '../../types';
3+
import { ReactToolDefinitionFrom, Store } from '../../types';
44
import { PromoCodeBase, PromoCodeValues, PromoCodeTypes } from './types';
55
import { getConfiguration } from '../../configuration';
66
import { ASSETS_BASE_URL, EMPTY_SELECTION } from '../../constants';
@@ -32,16 +32,29 @@ export const getPromoCodeToolDefinition: () =>
3232
return undefined;
3333
}
3434

35-
const PromoCodeTypeProperty: () => UnlayerProperty<PromoCodeTypes> = () =>
36-
dropdownProperty({
35+
const PromoCodeTypeProperty = ({ stores }: { stores: Store[] }) => {
36+
const options = [
37+
{ label: $t('_dp.promo_code_type_percent'), value: 'percent' as const },
38+
{ label: $t('_dp.promo_code_type_amount'), value: 'money' as const },
39+
...(stores.some((s) => s.name !== 'WooCommerce')
40+
? [
41+
{
42+
label: $t('_dp.promo_code_type_shipping'),
43+
value: 'shipping' as const,
44+
},
45+
]
46+
: []),
47+
] as [
48+
{ label: string; value: PromoCodeTypes },
49+
...{ label: string; value: PromoCodeTypes }[],
50+
];
51+
52+
return dropdownProperty({
3753
label: $t('_dp.promo_code_type'),
3854
defaultValue: 'percent',
39-
options: [
40-
{ label: $t('_dp.promo_code_type_percent'), value: 'percent' },
41-
{ label: $t('_dp.promo_code_type_amount'), value: 'money' },
42-
{ label: $t('_dp.promo_code_type_shipping'), value: 'shipping' },
43-
],
44-
} as const);
55+
options,
56+
});
57+
};
4558

4659
return {
4760
name: 'promo_code',
@@ -69,7 +82,7 @@ export const getPromoCodeToolDefinition: () =>
6982
dynamic_code: {
7083
title: $t('_dp.promo_code_dynamic_type_title'),
7184
options: {
72-
type: PromoCodeTypeProperty(),
85+
type: PromoCodeTypeProperty({ stores: storesWithPromoCode }),
7386
amount: textProperty({
7487
label: $t('_dp.promo_code_dynamic_value'),
7588
defaultValue: '5',
@@ -155,7 +168,8 @@ export const getPromoCodeToolDefinition: () =>
155168
enabled:
156169
values.isDynamic &&
157170
values.advanced_options &&
158-
values.type !== 'shipping',
171+
values.type !== 'shipping' &&
172+
storesWithFirstConsumerPurchase.includes(values.store as string),
159173
},
160174
first_consumer_purchase: {
161175
enabled:

0 commit comments

Comments
 (0)