|
1 | 1 | import { $t } from '../../localization'; |
2 | 2 | import { PromoCodeViewer } from './PromoCodeViewer'; |
3 | | -import { ReactToolDefinitionFrom, UnlayerProperty } from '../../types'; |
| 3 | +import { ReactToolDefinitionFrom, Store } from '../../types'; |
4 | 4 | import { PromoCodeBase, PromoCodeValues, PromoCodeTypes } from './types'; |
5 | 5 | import { getConfiguration } from '../../configuration'; |
6 | 6 | import { ASSETS_BASE_URL, EMPTY_SELECTION } from '../../constants'; |
@@ -32,16 +32,29 @@ export const getPromoCodeToolDefinition: () => |
32 | 32 | return undefined; |
33 | 33 | } |
34 | 34 |
|
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({ |
37 | 53 | label: $t('_dp.promo_code_type'), |
38 | 54 | 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 | + }; |
45 | 58 |
|
46 | 59 | return { |
47 | 60 | name: 'promo_code', |
@@ -69,7 +82,7 @@ export const getPromoCodeToolDefinition: () => |
69 | 82 | dynamic_code: { |
70 | 83 | title: $t('_dp.promo_code_dynamic_type_title'), |
71 | 84 | options: { |
72 | | - type: PromoCodeTypeProperty(), |
| 85 | + type: PromoCodeTypeProperty({ stores: storesWithPromoCode }), |
73 | 86 | amount: textProperty({ |
74 | 87 | label: $t('_dp.promo_code_dynamic_value'), |
75 | 88 | defaultValue: '5', |
@@ -155,7 +168,8 @@ export const getPromoCodeToolDefinition: () => |
155 | 168 | enabled: |
156 | 169 | values.isDynamic && |
157 | 170 | values.advanced_options && |
158 | | - values.type !== 'shipping', |
| 171 | + values.type !== 'shipping' && |
| 172 | + storesWithFirstConsumerPurchase.includes(values.store as string), |
159 | 173 | }, |
160 | 174 | first_consumer_purchase: { |
161 | 175 | enabled: |
|
0 commit comments