Skip to content

Commit 1e7c757

Browse files
Merge pull request #1461 from FromDoppler/DOP-1705-update-congrats-action-sf
DOP-1705 - Update congrats action for smart form
2 parents 6da2115 + 25103c0 commit 1e7c757

File tree

6 files changed

+44
-11
lines changed

6 files changed

+44
-11
lines changed

src/customJs/tools/smartforms/helper.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { $t } from '../../localization';
22
import { dropdownProperty } from '../../properties/helpers';
33
import { UnlayerProperty } from '../../types';
4-
import { CustomField, ListOption, SubscriptionList } from './types';
4+
import {
5+
CustomField,
6+
ListOption,
7+
SmartFormAction,
8+
SubscriptionList,
9+
} from './types';
510

611
export const behaviorListProperty: () => UnlayerProperty<string> = () =>
712
dropdownProperty({
@@ -16,14 +21,19 @@ export const behaviorListProperty: () => UnlayerProperty<string> = () =>
1621
],
1722
} as const);
1823

19-
export const congratsBehaviorListProperty: () => UnlayerProperty<string> = () =>
20-
dropdownProperty({
21-
label: $t('_dp.smart_forms.behavior.action.label'),
22-
defaultValue: '0',
23-
options: [
24-
{ label: $t('_dp.smart_forms.behavior.action.option_0'), value: '0' },
25-
],
26-
} as const);
24+
export const congratsBehaviorListProperty: () => UnlayerProperty<SmartFormAction> =
25+
() =>
26+
dropdownProperty({
27+
label: $t('_dp.smart_forms.behavior.action.label'),
28+
defaultValue: 'message',
29+
options: [
30+
{
31+
label: $t('_dp.smart_forms.behavior.action.option_0'),
32+
value: 'message',
33+
},
34+
{ label: $t('_dp.smart_forms.behavior.action.option_1'), value: 'url' },
35+
],
36+
} as const);
2737

2838
const mapListOption = (list: SubscriptionList): ListOption => {
2939
return { label: list.name, value: list.listId };

src/customJs/tools/smartforms/index.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { $t } from '../../localization';
22
import { SmartFormViewer } from './smartFormViewer';
33
import { ReactToolDefinitionFrom } from '../../types';
4-
import { SmartFormBase } from './types';
4+
import { SmartFormBase, SmartFormValues } from './types';
55
import { ASSETS_BASE_URL } from '../../constants';
66
import {
77
alignmentProperty,
@@ -18,6 +18,7 @@ import {
1818
SubscriptionListProperty,
1919
availableFields,
2020
} from './helper';
21+
import { urlProperty } from '../../properties/url';
2122

2223
const DEFAULT_GREEN_COLOR = '#64BF91';
2324

@@ -36,6 +37,9 @@ export const getSmartFormToolDefinition: () =>
3637
options: {
3738
display: behaviorListProperty(),
3839
congratBehavior: congratsBehaviorListProperty(),
40+
congratUrl: urlProperty({
41+
label: $t('_dp.smart_forms.behavior.congratsUrl.label'),
42+
}),
3943
descriptionHtml: richTextProperty({
4044
label: $t('_dp.smart_forms.behavior.message'),
4145
}),
@@ -212,5 +216,13 @@ export const getSmartFormToolDefinition: () =>
212216
},
213217
},
214218
},
219+
propertyStates: (values: SmartFormValues) => ({
220+
congratUrl: {
221+
enabled: values.congratBehavior === 'url',
222+
},
223+
descriptionHtml: {
224+
enabled: values.congratBehavior === 'message',
225+
},
226+
}),
215227
};
216228
};

src/customJs/tools/smartforms/smartFormViewer.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const SmartFormViewer: ViewerComponent<any> = ({ values }) => {
3838
}, '');
3939
};
4040

41+
const congratUrlEncode = encodeURI(values.congratUrl);
4142
const getCheboxList = (field: UnlayerField): string => {
4243
const labelStyle = `
4344
display: block; text-align: left; vertical-align: middle; color: rgb(68, 68, 68); font-size: 14px;
@@ -155,6 +156,8 @@ export const SmartFormViewer: ViewerComponent<any> = ({ values }) => {
155156
style={formStyle}
156157
data-field-instance={values.display}
157158
data-target-id-list={values.list}
159+
data-action-on-finish={values.congratBehavior}
160+
data-action-on-finish-url={congratUrlEncode}
158161
>
159162
<div color="#000">
160163
{fields.map((field) => (

src/customJs/tools/smartforms/types.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { UrlValue } from '../../properties/url/UrlValue';
12
import {
23
Alignment,
34
AutoWidth,
@@ -13,6 +14,8 @@ import {
1314

1415
export type ListOption = { value: string; label: string };
1516

17+
export type SmartFormAction = 'message' | 'url';
18+
1619
export type CustomField = {
1720
predefined: boolean;
1821
name: string;
@@ -53,7 +56,8 @@ export type UnlayerField = {
5356
export type SmartFormBase = {
5457
behavior: {
5558
display: string;
56-
congratBehavior: string;
59+
congratBehavior: SmartFormAction;
60+
congratUrl: UrlValue;
5761
descriptionHtml: string;
5862
};
5963
formAction: {

src/i18n/en.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export const messages_en: IntlMessages = {
108108
'_dp.smart_forms.action.title': `List Manager`,
109109
'_dp.smart_forms.behavior.action.label': `Action for form completed`,
110110
'_dp.smart_forms.behavior.action.option_0': `Show congrats message`,
111+
'_dp.smart_forms.behavior.action.option_1': `Redirect a webpage`,
112+
'_dp.smart_forms.behavior.congratsUrl.label': `Open new tab at`,
111113
'_dp.smart_forms.behavior.label': `Visible field by print`,
112114
'_dp.smart_forms.behavior.message': `The message that the user sees when the form is completed `,
113115
'_dp.smart_forms.behavior.option_0': `All`,

src/i18n/es.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ export const messages_es = {
108108
'_dp.smart_forms.action.title': `Administrar Lista`,
109109
'_dp.smart_forms.behavior.action.label': `Acción al finalizar el formulario`,
110110
'_dp.smart_forms.behavior.action.option_0': `Mostrar mensaje de agradecimiento`,
111+
'_dp.smart_forms.behavior.action.option_1': `Redireccionar a pagina web`,
112+
'_dp.smart_forms.behavior.congratsUrl.label': `Abrir nueva pestaña`,
111113
'_dp.smart_forms.behavior.label': `Campos a visualizar por impresion`,
112114
'_dp.smart_forms.behavior.message': `Mensaje que visualizará el usuario al completar el formulario`,
113115
'_dp.smart_forms.behavior.option_0': `Todos`,

0 commit comments

Comments
 (0)