@capillarytech/creatives-library 9.1.7 → 9.1.8-alpha.sprint-cap-214249.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/constants/unified.js +0 -1
  2. package/index.js +0 -13
  3. package/package.json +1 -1
  4. package/services/getSchema.js +1 -4
  5. package/services/tests/getSchema.test.js +2 -2
  6. package/utils/common.js +0 -6
  7. package/utils/createMobilePushPayload.js +47 -33
  8. package/utils/tests/createMobilePushPayload.test.js +102 -8
  9. package/v2Components/CapMpushCTA/index.js +10 -9
  10. package/v2Components/CapMpushCTA/index.scss +29 -3
  11. package/v2Components/CapMpushCTA/tests/index.test.js +89 -0
  12. package/v2Components/CommonTestAndPreview/UnifiedPreview/MobilePushPreviewContent.js +26 -13
  13. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +13 -1
  14. package/v2Components/CommonTestAndPreview/constants.js +2 -0
  15. package/v2Components/CommonTestAndPreview/index.js +49 -11
  16. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/MobilePushPreviewContent.test.js +79 -5
  17. package/v2Components/CommonTestAndPreview/tests/index.test.js +86 -0
  18. package/v2Components/FormBuilder/Functional/tests/mpush.crossFlowParity.test.js +1 -1
  19. package/v2Components/FormBuilder/Functional/tests/mpush.shellEvents.test.js +1 -1
  20. package/v2Components/FormBuilder/Functional/tests/mpush.singlePlatform.test.js +1 -1
  21. package/v2Components/FormBuilder/tests/mpush.characterization.test.js +2 -2
  22. package/v2Components/TemplatePreview/_templatePreview.scss +12 -2
  23. package/v2Components/TemplatePreview/index.js +30 -17
  24. package/v2Components/TemplatePreview/tests/index.test.js +61 -0
  25. package/v2Containers/Cap/index.js +0 -3
  26. package/v2Containers/CreativesContainer/SlideBoxContent.js +70 -151
  27. package/v2Containers/CreativesContainer/index.js +3 -6
  28. package/v2Containers/CreativesContainer/tests/SlideBoxContent.test.js +29 -0
  29. package/v2Containers/MobilePushNew/components/CtaButtons.js +52 -47
  30. package/v2Containers/MobilePushNew/components/MediaUploaders.js +207 -192
  31. package/v2Containers/MobilePushNew/components/PlatformContentFields.js +116 -121
  32. package/v2Containers/MobilePushNew/components/tests/CtaButtons.test.js +30 -208
  33. package/v2Containers/MobilePushNew/components/tests/MediaUploaders.test.js +316 -72
  34. package/v2Containers/MobilePushNew/components/tests/PlatformContentFields.test.js +45 -16
  35. package/v2Containers/MobilePushNew/constants.js +5 -0
  36. package/v2Containers/MobilePushNew/hooks/tests/usePlatformSync.test.js +63 -1
  37. package/v2Containers/MobilePushNew/hooks/tests/useUpload.test.js +52 -0
  38. package/v2Containers/MobilePushNew/hooks/usePlatformSync.js +38 -1
  39. package/v2Containers/MobilePushNew/hooks/useUpload.js +29 -39
  40. package/v2Containers/MobilePushNew/index.js +453 -188
  41. package/v2Containers/MobilePushNew/index.scss +188 -4
  42. package/v2Containers/MobilePushNew/messages.js +86 -6
  43. package/v2Containers/MobilePushNew/tests/index.test.js +450 -1
  44. package/v2Containers/MobilePushNew/tests/utils.test.js +25 -0
  45. package/v2Containers/MobilePushNew/utils.js +8 -0
  46. package/v2Containers/Templates/_templates.scss +10 -2
  47. package/v2Containers/Templates/index.js +84 -90
  48. package/v2Containers/Templates/tests/index.test.js +68 -0
  49. package/v2Components/FormBuilder/Functional/tests/manual.typingPerf.test.js +0 -135
  50. package/v2Components/FormBuilder/Functional/tests/mpush.ctaFlows.parity.test.js +0 -320
  51. package/v2Components/FormBuilder/Functional/tests/mpush.editContainer.parity.test.js +0 -148
  52. package/v2Components/FormBuilder/Functional/tests/mpush.libraryValidity.parity.test.js +0 -152
  53. package/v2Containers/MobilePush/Create/_mobilePushCreate.scss +0 -70
  54. package/v2Containers/MobilePush/Create/actions.js +0 -52
  55. package/v2Containers/MobilePush/Create/constants.js +0 -26
  56. package/v2Containers/MobilePush/Create/index.js +0 -2149
  57. package/v2Containers/MobilePush/Create/messages.js +0 -349
  58. package/v2Containers/MobilePush/Create/reducer.js +0 -72
  59. package/v2Containers/MobilePush/Create/sagas.js +0 -79
  60. package/v2Containers/MobilePush/Create/selectors.js +0 -29
  61. package/v2Containers/MobilePush/Create/test/contentValidity.test.js +0 -154
  62. package/v2Containers/MobilePush/Create/test/saga.test.js +0 -19
  63. package/v2Containers/MobilePush/Create/test/stayOpenOnSave.test.js +0 -80
  64. package/v2Containers/MobilePush/Edit/_mobilePushCreate.scss +0 -65
  65. package/v2Containers/MobilePush/Edit/actions.js +0 -94
  66. package/v2Containers/MobilePush/Edit/constants.js +0 -37
  67. package/v2Containers/MobilePush/Edit/index.js +0 -2407
  68. package/v2Containers/MobilePush/Edit/messages.js +0 -341
  69. package/v2Containers/MobilePush/Edit/reducer.js +0 -113
  70. package/v2Containers/MobilePush/Edit/sagas.js +0 -113
  71. package/v2Containers/MobilePush/Edit/selectors.js +0 -33
  72. package/v2Containers/MobilePush/Edit/test/contentValidity.test.js +0 -149
  73. package/v2Containers/MobilePush/Edit/test/saga.test.js +0 -255
  74. package/v2Containers/MobilePush/Edit/test/stayOpenOnSave.test.js +0 -60
  75. package/v2Containers/MobilePush/commonMethods.js +0 -333
  76. package/v2Containers/MobilePush/eventsMap.js +0 -130
  77. package/v2Containers/MobilePush/tests/commonMethods.test.js +0 -401
  78. package/v2Containers/MobilepushWrapper/_mobilepushWrapper.scss +0 -22
  79. package/v2Containers/MobilepushWrapper/index.js +0 -178
  80. package/v2Containers/MobilepushWrapper/messages.js +0 -29
  81. /package/{v2Containers/MobilePush/initialSchema.js → v2Components/FormBuilder/Functional/tests/fixtures/mpushInitialSchema.js} +0 -0
@@ -1,2149 +0,0 @@
1
- /*
2
- *
3
- * Create
4
- *
5
- */
6
-
7
- import PropTypes, { object } from 'prop-types';
8
-
9
- import React from 'react';
10
- import { bindActionCreators } from 'redux';
11
- import { notification } from 'antd';
12
- import {get, set, filter, isEmpty, map, forEach, uniqueId, cloneDeep, isEqual, findIndex, isPlainObject} from 'lodash';
13
- import { createStructuredSelector } from 'reselect';
14
- import { intlShape, FormattedMessage } from 'react-intl';
15
- import styled from 'styled-components';
16
- import { CapSlideBox, CapHeader, CapTable, CapLink, CapRow, CapColumn, CapIcons, CapSpin, CapNotification } from '@capillarytech/cap-ui-library';
17
- import { makeSelectCreate, makeSelectCreateResponse, makeSelectIosCta } from './selectors';
18
- import { makeSelectMetaEntities, setInjectedTags } from '../../Cap/selectors';
19
- import FormBuilder from '../../../v2Components/FormBuilder';
20
- import './_mobilePushCreate.scss';
21
- import * as actions from './actions';
22
- import withCreatives from '../../../hoc/withCreatives';
23
- import * as globalActions from '../../Cap/actions';
24
- import {getMessageObject} from '../../../utils/messageUtils';
25
- import { gtmPush } from '../../../utils/gtmTrackers';
26
-
27
- import { makeSelectTemplates } from '../../Templates/selectors';
28
- import messages from './messages';
29
- import editMessages from '../Edit/messages';
30
- import getEventsMap from '../eventsMap';
31
- import { GA } from '@capillarytech/cap-ui-utils';
32
- import { CREATE, EDIT, TRACK_CREATE_MPUSH } from '../../App/constants';
33
- import { MOBILE_PUSH } from '../../CreativesContainer/constants';
34
- import { getContent, getMobilePushEmbeddedContentValidity } from '../commonMethods';
35
- import { getCdnUrl } from '../../../utils/cdnTransformation';
36
- import injectReducer from '../../../utils/injectReducer';
37
- import injectSaga from '../../../utils/injectSaga';
38
- import v2MobilePushCreateReducer from './reducer';
39
- import { v2MobilePushWatchDuplicateTemplateSaga } from './sagas';
40
- import { EXTERNAL_LINK_LOWERCASE } from './constants';
41
- import TestAndPreviewSlidebox from '../../../v2Components/TestAndPreviewSlidebox';
42
- import { checkForPersonalizationTokens, validateMobilePushContent } from '../../../utils/commonUtils';
43
- import formBuilderMessages from '../../../v2Components/FormBuilder/messages';
44
-
45
- const PrefixWrapper = styled.div`
46
- margin-right: 16px;
47
- `;
48
- export class Create extends React.Component { // eslint-disable-line react/prefer-stateless-function
49
- constructor(props) {
50
- super(props);
51
- const eventsMap = getEventsMap(this);
52
- if (this.props.Templates.selectedWeChatAccount) {
53
- this.state = {
54
- formData: {},
55
- tabCount: 1,
56
- currentTab: 1,
57
- // Full mode: id of the template created in this session; later saves update it
58
- savedTemplateId: '',
59
- loading: false,
60
- isFormValid: true,
61
- tabKey: '',
62
- checkValidation: false,
63
- schema: {},
64
- eventsMap,
65
- errorData: {},
66
- displayProps: {},
67
- modalContent: {title: this.props.intl.formatMessage(messages.alertMessage), body: this.props.intl.formatMessage(messages.templateNotConfigured), type: 'confirm'},
68
- injectedTags: {},
69
- };
70
- }
71
- this.hasFetchedInitialTagsRef = false;
72
- this.lastFetchedTagContextRef = null;
73
- // Tracks the last content-emptiness value reported to the parent so componentDidUpdate
74
- // does not dispatch on every render. Intentionally undefined (not true) so the first
75
- // render always reports the real validity rather than assuming the form starts invalid.
76
- this._lastReportedMobilePushContentEmpty = undefined;
77
- }
78
- componentDidUpdate() {
79
- // Reports live form validity so the host (CreativesContainer) can disable Done/Preview
80
- // and Test as soon as the message content is cleared — mirrors Sms/Create's own reporting.
81
- if (typeof this.props.onContentValidityChange !== 'function') {
82
- return;
83
- }
84
- const validity = getMobilePushEmbeddedContentValidity(this.state?.formData);
85
- const isContentEmpty = !!validity.isContentEmpty;
86
- if (this._lastReportedMobilePushContentEmpty === isContentEmpty) return;
87
- this._lastReportedMobilePushContentEmpty = isContentEmpty;
88
- this.props.onContentValidityChange({ isContentEmpty });
89
- }
90
- componentWillMount = () => {
91
- if (this.props.route.name === 'view') {
92
- this.setState({loading: false});
93
- this.removeStandAlone();
94
- }
95
- if (this.props.params.mode) {
96
- this.setState({mode: this.props.params.mode});
97
- }
98
- if (!this.props.Templates.selectedWeChatAccount) {
99
- const type = this.props.location.query.type;
100
- const module = this.props.location.query.module ? this.props.location.query.module : 'default';
101
- this.props.router.push({
102
- pathname: `/MOBILEPUSH/`,
103
- query: type === 'embedded' ? {type: 'embedded', module} : {module},
104
- });
105
- }
106
- };
107
-
108
- componentDidMount = () => {
109
- const query = {
110
- layout: 'MOBILEPUSH',
111
- type: 'LAYOUT',
112
- version: "v2",
113
- };
114
- this.props.globalActions.fetchSchemaForEntity(query);
115
- };
116
- componentWillReceiveProps = (nextProps) => {
117
- // Library mode: on Done click (transition to isGetFormData), run extractTags only when no existing validation errors (braces, personalization, etc.)
118
- if (nextProps.isGetFormData && !this.props.isGetFormData && !nextProps.isFullMode) {
119
- // If form already has validation errors (braces, personalization tags, etc.), do not call extractTags or return payload; always return early
120
- if (!this.state.isFormValid) {
121
- if (typeof nextProps.onValidationFail === 'function') {
122
- nextProps.onValidationFail();
123
- }
124
- return;
125
- }
126
- const hasAllValidationCallbacks =
127
- typeof nextProps.getLiquidTags === 'function' &&
128
- typeof nextProps.showLiquidErrorInFooter === 'function' &&
129
- typeof nextProps.onValidationFail === 'function';
130
-
131
- if (hasAllValidationCallbacks) {
132
- const formDataArr = [this.state.formData?.[0], this.state.formData?.[1]];
133
- validateMobilePushContent(formDataArr, {
134
- currentTab: this.state.currentTab,
135
- getLiquidTags: nextProps.getLiquidTags,
136
- formatMessage: this.props.intl.formatMessage,
137
- messages: formBuilderMessages,
138
- onError: (err) => {
139
- const { standardErrors = [], liquidErrors = [] } = err;
140
- // _validatePlatformSpecificContent passes { standardErrors: { ANDROID, IOS, generic }, liquidErrors: { ... } }; footer expects arrays
141
- const toArray = (v) => (Array.isArray(v) ? v : (v && typeof v === 'object' ? [].concat(...Object.values(v)) : []));
142
- const STANDARD_ERROR_MSG = toArray(standardErrors);
143
- const LIQUID_ERROR_MSG = toArray(liquidErrors);
144
- if (typeof nextProps.showLiquidErrorInFooter === 'function') {
145
- nextProps.showLiquidErrorInFooter(
146
- { STANDARD_ERROR_MSG, LIQUID_ERROR_MSG },
147
- this.state.currentTab
148
- );
149
- }
150
- // Only trigger onValidationFail when there are actual errors; skip when helper called onError with empty arrays (reset case)
151
- if ((STANDARD_ERROR_MSG.length > 0 || LIQUID_ERROR_MSG.length > 0) && typeof nextProps.onValidationFail === 'function') {
152
- nextProps.onValidationFail();
153
- }
154
- },
155
- onSuccess: () => {
156
- if (this.state.isFormValid && typeof nextProps.getFormLibraryData === 'function') {
157
- nextProps.getFormLibraryData(this.getFormData());
158
- }
159
- },
160
- });
161
- } else {
162
- // Fail closed: require full validation callback set; treat any missing callback as validation failure
163
- if (typeof nextProps.onValidationFail === 'function') {
164
- nextProps.onValidationFail();
165
- }
166
- }
167
- } else if (nextProps.isGetFormData && this.props.isGetFormData !== nextProps.isGetFormData && this.props.isFullMode && !this.props.Create.createTemplateInProgress) {
168
- // Re-arm per Save click (saves only on startValidation false → true).
169
- this.setState({ startValidation: false }, this.startValidation);
170
- }
171
- if (nextProps.Create.uploadedAssetData) {
172
- const formData = cloneDeep(this.state.formData);
173
- formData[this.state.currentTab - 1].image = nextProps.Create.uploadedAssetData.metaInfo.public_url;
174
- this.setState({formData});
175
- this.props.actions.clearAsset();
176
- }
177
- if (nextProps.params.mode) {
178
- this.setState({mode: nextProps.params.mode});
179
- }
180
- if (nextProps.Create.createTemplateError && !isEqual(nextProps.Create.createTemplateError, this.props.Create.createTemplateError)) {
181
- const message = getMessageObject('error', (nextProps.Create.createTemplateErrorMessage && nextProps.Create.createTemplateErrorMessage !== '') ? nextProps.Create.createTemplateErrorMessage : this.props.intl.formatMessage(messages.somethingWentWrong), true);
182
- this.props.onValidationFail();
183
- this.setState({showModal: false, startValidation: false});
184
- this.props.globalActions.addMessageToQueue(message);
185
- }
186
- if (nextProps.iosCtasData && isEmpty(this.state.templateCta)) {
187
- this.setState({showIosCtaTable: true});
188
- }
189
- if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && isEmpty(this.state.schema)) {
190
- const schema = cloneDeep(this.props.params.mode === "text" ? nextProps.metaEntities.layouts[0].definition.textSchema : nextProps.metaEntities.layouts[0].definition.imageSchema);
191
- const isAndroidSupported = get(this, "props.Templates.selectedWeChatAccount.configs.android") === '1';
192
- const isIosSupported = get(this, "props.Templates.selectedWeChatAccount.configs.ios") === '1';
193
- if (!isAndroidSupported) {
194
- const androidField = get(schema, "containers[0].panes[0]");
195
- androidField.isSupported = false;
196
- this.setState({currentTab: 2});
197
- set(schema, "containers[0].panes[0]", androidField);
198
- }
199
- if (!isIosSupported) {
200
- const iosField = get(schema, "containers[0].panes[1]");
201
- iosField.isSupported = false;
202
-
203
- set(schema, "containers[0].panes[1]", iosField);
204
- }
205
- schema.standalone.sections.splice(1, 1);
206
- this.injectEvents(schema);
207
- if (!this.hasFetchedInitialTagsRef) {
208
- this.hasFetchedInitialTagsRef = true;
209
- const context = this.props.getDefaultTags
210
- || (this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default');
211
- this.lastFetchedTagContextRef = typeof context === 'string' ? context.toLowerCase() : context;
212
- const query = {
213
- layout: 'mobilepush',
214
- type: 'TAG',
215
- context: this.lastFetchedTagContextRef,
216
- embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
217
- };
218
- this.props.globalActions.fetchSchemaForEntity(query);
219
- }
220
- }
221
- };
222
- componentWillUnmount = () => {
223
- this.props.actions.resetStore();
224
- window.removeEventListener("message", this.handleFrameTasks);
225
- };
226
- onTemplateChange = () => {
227
-
228
- };
229
-
230
- onFormDataChange = (formData, tabCount, currentTab, inputField) => {
231
- const newFormData = cloneDeep(formData);
232
- const {templateCta} = this.state;
233
- const { defaultData = {}, isFullMode, showTemplateName} = this.props;
234
-
235
- // Check for personalization tokens if restriction is enabled and notify parent
236
- if (this.props.restrictPersonalization) {
237
- const hasTokens = checkForPersonalizationTokens(newFormData);
238
- if (this.props.onPersonalizationTokensChange) {
239
- this.props.onPersonalizationTokensChange(hasTokens);
240
- }
241
- }
242
-
243
- if (!isEmpty(templateCta)) {
244
- newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-label`] = get(templateCta, 'name');
245
- newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action`] = get(templateCta, 'ctaTemplateDetails[0].buttonText');
246
- delete newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action2`];
247
- if (get(templateCta, 'ctaTemplateDetails[1]')) {
248
- newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action2`] = get(templateCta, 'ctaTemplateDetails[1].buttonText');
249
- }
250
- }
251
-
252
-
253
- const templateName = formData['template-name'];
254
- const defaultTemplateName = get(defaultData, 'template-name', '');
255
-
256
-
257
- // copy content code
258
- // if (newFormData[0]['copy-iphone-content'] === "") {
259
- //
260
- // if(!!formData[1]['message-editor2'] && !!formData[1]['message-title2']){
261
- // dispplayProps[0]['copy-iphone-content'] = true;
262
- // }
263
- // } else {
264
- // if(formData[1]['message-editor2'] === "" || formData[1]['message-title2'] === ""){
265
- // newFormData[0]['copy-iphone-content'] = "";
266
- // }
267
- // }
268
- // if (newFormData[1]['copy-android-content'] === "") {
269
- //
270
- // if(!!formData[0]['message-editor'] && !!formData[0]['message-title']){
271
- // newFormData[1]['copy-android-content'] = true;
272
- // }
273
- // } else {
274
- // if(formData[0]['message-editor'] === "" || formData[0]['message-title'] === ""){
275
- // newFormData[1]['copy-android-content'] = "";
276
- // }
277
- // }
278
- //assign newFormData['template-name'] to default name only once in inital render, if edited use latest form data
279
- if (isFullMode && defaultData && isEmpty(templateName) && !formData?.isTemplateNameEdited) {
280
- newFormData['template-name'] = defaultTemplateName;
281
- }
282
-
283
- if (inputField && inputField.id === "add-sec-cta") {
284
- if (!newFormData[0]["add-sec-cta"]) {
285
- newFormData[0]["add-sec-cta-2"] = false;
286
- }
287
- }
288
- const compareValue =
289
- newFormData?.[this.state?.currentTab - 1]?.[inputField?.id] || "";
290
- this.setState(
291
- {
292
- formData: newFormData,
293
- tabCount,
294
- },
295
- () => {
296
- if (isFullMode && showTemplateName) {
297
- showTemplateName({
298
- formData: this.state?.formData,
299
- onFormDataChange: this.onFormDataChange,
300
- });
301
- }
302
- }
303
- );
304
- this.setState({isSchemaChanged:
305
- (typeof compareValue === 'string' &&
306
- compareValue.toLowerCase() === EXTERNAL_LINK_LOWERCASE) ||
307
- !this.state?.isSchemaChanged});
308
- };
309
-
310
- onTagSelect = (data, currentTab, srcComp) => {
311
- const editorId = srcComp.target;
312
- this.insertAtCursor(document.getElementById(editorId), `{{${data}}}`, currentTab);
313
- document.getElementById(editorId).focus();
314
- };
315
-
316
- onTabChange = (data) => {
317
- this.setState({currentTab: data});
318
- };
319
- onTemplateNameChange = () => {
320
- //
321
- };
322
-
323
-
324
- onLinkTypeChange = (eventTriggered, formData, field) => {
325
- let schema = cloneDeep(this.state.schema);
326
- const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
327
-
328
- forEach(inputFields, (inputField, fieldIndex) => {
329
- if (inputField) {
330
- forEach(inputField.cols, (col) => {
331
- if (col.id === field.id) {
332
- const deeplinks = this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.configs && !!this.props.Templates.selectedWeChatAccount.configs.deeplink ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
333
- const deepLinkOptions = this.props.Templates.selectedWeChatAccount ? map(JSON.parse(deeplinks), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
334
- const deeplinkValue = formData[this.state.currentTab - 1][field.id];
335
- const componentIndex = fieldIndex + 1;
336
- const inputId = deeplinkValue && deeplinkValue.toLowerCase() === "deeplink" ? `${col.id}-select` : `${col.id}-text`;
337
- if ( deeplinkValue && deeplinkValue.toLowerCase() === "deeplink" && (fieldIndex === inputFields.length - 1 || inputFields[componentIndex].id !== "cta-deeplink-select-section")) {
338
- const row = {
339
- rowClassName: 'mobile-push-row',
340
- id: 'cta-deeplink-select-section',
341
- cols: [
342
-
343
- {
344
- id: inputId,
345
- placeholder: this.props.intl.formatMessage(messages.selectDeeplink),
346
- type: "select", //Resembles component to be used
347
- options: deepLinkOptions,
348
- metaType: "text",
349
- datatype: "string",
350
- errorMessage: this.props.intl.formatMessage(messages.selectADeeplink),
351
- required: true,
352
- fluid: true,
353
- width: 18,
354
- offset: 1,
355
- style: {
356
- width: '100%',
357
-
358
- marginBottom: '16px',
359
- },
360
- styling: "semantic",
361
- order: 1,
362
- customComponent: false,
363
- supportedEvents: [
364
- 'onSelect',
365
- ],
366
- },
367
- ],
368
- };
369
- if (!inputFields[fieldIndex + 1] || inputFields[componentIndex].id === "cta-external-link") {
370
- inputFields[componentIndex] = row;
371
- } else {
372
- inputFields.splice(componentIndex, 0, row);
373
- }
374
- } else if ( deeplinkValue && deeplinkValue.toLowerCase() === "external link") {
375
- const row = {
376
- rowClassName: 'mobile-push-row',
377
- id: 'cta-external-link',
378
- cols: [
379
- {
380
- // Add label control for external link input
381
- id: "title-tagList",
382
- label: "Add label",
383
- type: "tag-list",
384
- metaType: "List",
385
- datatype: "select",
386
- required: true,
387
- fluid: true,
388
- onlyDisplay: true,
389
- style: {
390
- marginRight: "24%",
391
- marginTop: "-3%",
392
- display: 'flex',
393
- justifyContent: 'end',
394
- width: '100%',
395
- },
396
- styling: "semantic",
397
- order: 2,
398
- customComponent: true,
399
- // Helps handler identify the destination input
400
- target: inputId,
401
- supportedEvents: [
402
- "onTagSelect",
403
- ],
404
- },
405
- {
406
- id: inputId,
407
- placeholder: this.props.intl.formatMessage(messages.externalLink),
408
- type: "input", //Resembles component to be used
409
- metaType: "text",
410
- datatype: "string",
411
- errorMessage: <FormattedMessage {...messages.invalidExternalLink}/>,
412
- required: true,
413
- fluid: true,
414
- width: 18,
415
- offset: 1,
416
- style: {
417
- width: '95%',
418
- },
419
- styling: "semantic",
420
- order: 1,
421
- customComponent: false,
422
- standalone: false,
423
- },
424
- ],
425
- };
426
- if (!inputFields[fieldIndex + 1] || inputFields[componentIndex].id === "cta-deeplink-select-section") {
427
- inputFields[componentIndex] = row;
428
- if (inputFields[componentIndex + 1] && inputFields[componentIndex + 1].id === "show-cta-deeplink-keys-label") {
429
- inputFields.splice(componentIndex + 1, 1);
430
- }
431
- if (inputFields[componentIndex + 1] && inputFields[componentIndex + 1].id === "cta-deeplink-keys") {
432
- let configkeys = filter(JSON.parse(deeplinks), (dl) => dl.link === formData[this.state.currentTab - 1][`${col.id}-select`]);
433
- if (configkeys[0]) {
434
- configkeys = configkeys[0].keys;
435
- }
436
- if (configkeys.length) {
437
- //inputFields = inputFields.slice(0, componentIndex + 1).concat(inputFields.slice( componentIndex + 1 + configkeys.length, inputFields.length));
438
-
439
- inputFields.splice(componentIndex + 1, configkeys.length);
440
- }
441
- }
442
- } else {
443
- inputFields.splice(componentIndex, 0, row);
444
- }
445
- }
446
- }
447
- });
448
- }
449
- });
450
- schema = set(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`, inputFields);
451
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true});
452
- this.injectEvents(schema);
453
- };
454
- onTemplateContentChange = () => {
455
-
456
- };
457
- onModalCancel = () => {
458
- if (this.state.modalContent && this.state.modalContent.show) {
459
- this.setState({modalContent: {...this.state.modalContent, show: false}});
460
- }
461
- };
462
- getLinkName = (link) => {
463
- const ck = this.props.Templates.selectedWeChatAccount.configs ? !!this.props.Templates.selectedWeChatAccount.configs.deeplink : false;
464
- const deeplinks = ck ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
465
- const deepLinkOptions = filter(JSON.parse(deeplinks), (l) => l.link === link);
466
- if (deepLinkOptions[0]) {
467
- return deepLinkOptions[0].name;
468
- }
469
- return undefined;
470
- };
471
-
472
- getMappedEvent = (id, event) => {
473
- const eventsMap = this.state.eventsMap;
474
- return eventsMap[id][event];
475
- };
476
- getCurrentWindow = (e) => {
477
- const response = {
478
- action: e.action,
479
- value: 'edit',
480
- direction: e.value,
481
- };
482
- parent.postMessage(JSON.stringify(response), '*');
483
- };
484
- getFormData = (e) => {
485
- const templateData = this.getTransformedData(this.state.formData);
486
- const response = {
487
- action: "getFormData",
488
- value: templateData,
489
- validity: this.state.isFormValid,
490
- type: templateData.type,
491
- };
492
- this.setState({checkValidation: true}, this.showError);
493
- if (e) {
494
- e.source.postMessage(JSON.stringify(response), e.origin);
495
- }
496
- return response;
497
- };
498
- setFormValidity = (isFormValid, errorData) => {
499
-
500
- const newState = {isFormValid, errorData};
501
- this.setState(newState);
502
- };
503
- getTransformedData = (formData) => {
504
- const obj = {};
505
- obj.versions = {
506
- base: {},
507
- };
508
- obj.type = 'MOBILEPUSH';
509
- obj.name = formData['template-name'];
510
- if (this.props?.Templates?.selectedWeChatAccount?.sourceTypeName === 'MAPP_SDK') {
511
- obj.definition = {
512
- accountId: this.props.Templates.selectedWeChatAccount.id,
513
- licenseCode: this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier,
514
- gatewayId: this.props.Templates.selectedWeChatAccount.configs.gatewayId,
515
- gatewayAccountId: this.props.Templates.selectedWeChatAccount.configs.gatewayAccountId,
516
- mode: this.props.params.mode,
517
- sourceType: this.props.Templates.selectedWeChatAccount.sourceTypeName,
518
- };
519
- } else {
520
- obj.definition = {
521
- accountId: this.props.Templates.selectedWeChatAccount.id,
522
- licenseCode: this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier,
523
- mode: this.props.params.mode,
524
- sourceType: this.props.Templates.selectedWeChatAccount.sourceTypeName,
525
- };
526
- }
527
- const android = {};
528
- Object.keys(formData[0]).forEach((data) => {
529
- if (!!formData[0][data] && data !== "tabKey") {
530
- android[data] = formData[0][data];
531
- }
532
- });
533
- const ios = {};
534
- Object.keys(formData[1]).forEach((data) => {
535
- if (!!formData[1][data] && data !== "tabKey") {
536
- ios[data] = formData[1][data];
537
- }
538
- });
539
- obj.versions.base = {};
540
- delete android.base;
541
- if (!isEmpty(android)) {
542
- obj.versions.base.ANDROID = {
543
- luid: "{{luid}}",
544
- cuid: "{{cuid}}",
545
- communicationId: "{{communicationId}}",
546
- title: android['message-title'],
547
- message: android['message-editor'],
548
- expandableDetails: {
549
- style: "BIG_TEXT",
550
- message: android['message-editor'],
551
- },
552
- custom: map(android, (field, key) => {
553
- if (key.indexOf('custom-value') > -1) {
554
- return field !== "" ? {key: key.replace('custom-value-', "").replace('-cta-deeplink-select', '').replace('-cta-deeplink-secondary-cta-0-select', '').replace('-cta-deeplink-secondary-cta-1-select', ''), value: field} : undefined;
555
- }
556
- return undefined;
557
- }).filter((custom) => custom),
558
- };
559
- obj.name = isEmpty(obj.name) ? android['message-title'] : obj.name;
560
- }
561
- if (android['cta-deeplink'] && android['cta-deeplink'] !== "") {
562
- obj.versions.base.ANDROID.cta = {
563
- type: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
564
- actionLink: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? android['cta-deeplink-select'] : android['cta-deeplink-text'],
565
- deepLinkName: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? this.getLinkName(android['cta-deeplink-select']) : undefined,
566
- };
567
- if (this.props.location.query.type === 'embedded') {
568
- delete obj.versions.base.ANDROID.cta.deepLinkName;
569
- }
570
- }
571
- if (!isEmpty(ios)) {
572
- obj.versions.base.IOS = {
573
- luid: "{{luid}}",
574
- cuid: "{{cuid}}",
575
- communicationId: "{{communicationId}}",
576
- title: ios['message-title2'],
577
- message: ios['message-editor2'],
578
- expandableDetails: {
579
- style: "BIG_TEXT",
580
- message: ios['message-editor2'],
581
- ctas: [
582
- ],
583
- },
584
- custom: map(ios, (field, key) => {
585
- if (key.indexOf('custom-value') > -1) {
586
- return field !== "" ? {key: key.replace('custom-value-', "").replace('-cta-deeplink2-select', '').replace('-cta-deeplink-secondary-cta-0-select', '').replace('-cta-deeplink-secondary-cta-1-select2', ''), value: field} : undefined;
587
- }
588
- return undefined;
589
- }).filter((custom) => custom),
590
- };
591
- obj.name = isEmpty(obj.name) ? ios['message-title2'] : obj.name;
592
- }
593
- if (ios['cta-deeplink2'] && ios['cta-deeplink2'] !== "") {
594
- obj.versions.base.IOS.cta = {
595
- type: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
596
- actionLink: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? ios['cta-deeplink2-select'] : ios['cta-deeplink2-text'],
597
- deepLinkName: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? this.getLinkName(ios['cta-deeplink2-select']) : undefined,
598
- };
599
- if (this.props.location.query.type === 'embedded') {
600
- delete obj.versions.base.IOS.cta.deepLinkName;
601
- }
602
- }
603
- if (obj.versions.base.ANDROID) {
604
- if (obj.versions.base.ANDROID.cta && obj.versions.base.ANDROID.cta.type === "DEEP_LINK") {
605
- const params = map(android, (field, key) => {
606
- let actionLink;
607
- if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-select') > -1) {
608
- const param = key.replace('custom-value-', "").replace('-cta-deeplink-select', '');
609
- actionLink = field !== "" ? `${param}=${field}` : undefined;
610
- }
611
- return actionLink;
612
- }).filter((actionLink) => actionLink);
613
- if (params.length) {
614
- obj.versions.base.ANDROID.cta.actionLink = `${obj.versions.base.ANDROID.cta.actionLink}?${params.join('&')}`;
615
- }
616
- }
617
- const secondaryCta1 = !!android["cta-deeplink-secondary-cta-0-select"] || !!android['secondary-cta-0-label'];
618
- const secondaryCta2 = !!android['cta-deeplink-secondary-cta-1-select'] || !!android['secondary-cta-1-label'];
619
- const imageLink = android.image;
620
- if (imageLink) {
621
- obj.versions.base.ANDROID.expandableDetails.image = getCdnUrl({url: imageLink, channelName: 'MOBILE_PUSH'});
622
- obj.versions.base.ANDROID.expandableDetails.style = "BIG_PICTURE";
623
- }
624
- if (secondaryCta1 || secondaryCta2 ) {
625
- obj.versions.base.ANDROID.expandableDetails.ctas = [];
626
- if (secondaryCta1) {
627
- const cta = {
628
- actionText: android['secondary-cta-0-label'],
629
- type: (android['cta-deeplink-secondary-cta-0'] || '').toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
630
- actionLink: (android['cta-deeplink-secondary-cta-0'] || '').toLowerCase() === "deeplink" ? android['cta-deeplink-secondary-cta-0-select'] : android['cta-deeplink-secondary-cta-0-text'],
631
- seccdeepLinkName: this.getLinkName(android['cta-deeplink-secondary-cta-0-select']),
632
- };
633
- if (this.props.location.query.type === 'embedded') {
634
- delete cta.seccdeepLinkName;
635
- }
636
- obj.versions.base.ANDROID.expandableDetails.ctas.push(cta);
637
- if (obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
638
- const params = map(android, (field, key) => {
639
- let actionLink;
640
- if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-0-select') > -1) {
641
- const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-0-select', '');
642
- actionLink = field !== "" ? `${param}=${field}` : undefined;
643
- }
644
- return actionLink;
645
- }).filter((actionLink) => actionLink);
646
- if (params.length) {
647
- obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].actionLink = `${obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].actionLink}?${params.join('&')}`;
648
- }
649
- }
650
- }
651
- if (secondaryCta2) {
652
- const cta = {
653
- actionText: android['secondary-cta-1-label'],
654
- type: (android['cta-deeplink-secondary-cta-1'] || '').toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
655
- actionLink: (android['cta-deeplink-secondary-cta-1'] || '').toLowerCase() === "deeplink" ? android['cta-deeplink-secondary-cta-1-select'] : android['cta-deeplink-secondary-cta-1-text'],
656
- seccdeepLinkName: this.getLinkName(android['cta-deeplink-secondary-cta-1-select']),
657
- };
658
- if (this.props.location.query.type === 'embedded') {
659
- delete cta.seccdeepLinkName;
660
- }
661
- obj.versions.base.ANDROID.expandableDetails.ctas.push(cta);
662
- if (obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
663
- const params = map(android, (field, key) => {
664
- let actionLink;
665
- if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-1-select') > -1) {
666
- const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-1-select', '');
667
- actionLink = field !== "" ? `${param}=${field}` : undefined;
668
- }
669
- return actionLink;
670
- }).filter((actionLink) => actionLink);
671
- if (params.length) {
672
- obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].actionLink = `${obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].actionLink}?${params.join('&')}`;
673
- }
674
- }
675
- }
676
- }
677
- }
678
- if (obj.versions.base.IOS) {
679
- if (obj.versions.base.IOS.cta && obj.versions.base.IOS.cta.type === "DEEP_LINK") {
680
- const params = map(ios, (field, key) => {
681
- let actionLink;
682
- if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink2-select') > -1) {
683
- const param = key.replace('custom-value-', "").replace('-cta-deeplink2-select', '');
684
- actionLink = field !== "" ? `${param}=${field}` : undefined;
685
- }
686
- return actionLink;
687
- }).filter((actionLink) => actionLink);
688
- if (params.length) {
689
- obj.versions.base.IOS.cta.actionLink = `${obj.versions.base.IOS.cta.actionLink}?${params.join('&')}`;
690
- }
691
- }
692
- const imageLinkIos = ios.image;
693
- const secondaryCtaIos = !!ios['cta-deeplink-secondary-cta-1-select'] || !!ios['secondary-cta-1-label'];
694
- if (imageLinkIos) {
695
- obj.versions.base.IOS.expandableDetails.image = getCdnUrl({url: imageLinkIos, channelName: 'MOBILE_PUSH'});
696
- obj.versions.base.IOS.expandableDetails.style = "BIG_PICTURE";
697
- }
698
- if (secondaryCtaIos) {
699
- obj.versions.base.IOS.expandableDetails.ctas = [];
700
- const templateCtaId = get(this.state, "templateCta.ctaTemplateDetails[0].id");
701
- const cta = {
702
- actionText: ios['secondary-cta-1-label'],
703
- actionLabel: ios['secondary-cta-1-action'],
704
- actionLabel2: ios['secondary-cta-1-action2'],
705
- type: ios['cta-deeplink-secondary-cta-1'] && (ios['cta-deeplink-secondary-cta-1'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL"),
706
- actionLink: ios['cta-deeplink-secondary-cta-1'] && (ios['cta-deeplink-secondary-cta-1'].toLowerCase() === "deeplink" ? (ios['cta-deeplink-secondary-cta-1-select2'] || ios['cta-deeplink-secondary-cta-1-select']) : ios['cta-deeplink-secondary-cta-1-text']),
707
- ioscdeepLinkName: this.getLinkName(ios['cta-deeplink-secondary-cta-1-select']),
708
- templateCtaId,
709
- };
710
- if (this.props.location.query.type === 'embedded') {
711
- delete cta.ioscdeepLinkName;
712
- }
713
- obj.versions.base.IOS.expandableDetails.ctas.push(cta);
714
- obj.versions.base.IOS.expandableDetails.categoryId = get(this.state, "templateCta.id");
715
- if (obj.versions.base.IOS.expandableDetails.ctas[obj.versions.base.IOS.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
716
- const params = map(ios, (field, key) => {
717
- let actionLink;
718
- if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-1-select') > -1) {
719
- const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-1-select2', '');
720
- actionLink = field !== "" ? `${param}=${field}` : undefined;
721
- }
722
- return actionLink;
723
- }).filter((actionLink) => actionLink);
724
- if (params.length) {
725
- obj.versions.base.IOS.expandableDetails.ctas[obj.versions.base.IOS.expandableDetails.ctas.length - 1].actionLink = `${obj.versions.base.IOS.expandableDetails.ctas[obj.versions.base.IOS.expandableDetails.ctas.length - 1].actionLink}?${params.join('&')}`;
726
- }
727
- }
728
- }
729
- }
730
- return obj;
731
- };
732
-
733
- setModalContent = (type) => {
734
- if (type === 'ios') {
735
- const modalContent = {
736
- title: this.props.intl.formatMessage(messages.alertMessage),
737
- body: this.props.intl.formatMessage(messages.androidNotConfigured),
738
- type: 'confirm',
739
- id: 'ios',
740
- };
741
- this.setState({modalContent, showModal: true});
742
- } else if (type === 'android') {
743
- const modalContent = {
744
- title: this.props.intl.formatMessage(messages.alertMessage),
745
- body: this.props.intl.formatMessage(messages.iosNotConfigured),
746
- type: 'confirm',
747
- id: 'android',
748
- };
749
- this.setState({modalContent, showModal: true});
750
- }
751
- }
752
- showError = () => {
753
- const {intl} = this.props;
754
- const {errorData, schema} = this.state;
755
- const errorMessage = {key: 'validation-error', message: intl.formatMessage(messages.validationError)};
756
- if (!isEmpty(this.state.formData) && !this.state.isFormValid) {
757
- let tab = this.state.currentTab;
758
- const isAndroidInvalid = Object.values(errorData[0] || {}).includes(true);
759
- const isIosInvalid = Object.values(errorData[1] || {}).includes(true);
760
- const isIosTabVisible = get(schema, 'containers[0].panes[1].isSupported', true) !== false;
761
- if (isAndroidInvalid) {
762
- tab = 1;
763
- errorMessage.description = intl.formatMessage(messages.invalidAndroidMessage);
764
- } else if (isIosInvalid && isIosTabVisible) {
765
- tab = 2;
766
- errorMessage.description = intl.formatMessage(messages.invalidIosMessage);
767
- }
768
- if (tab !== this.state.currentTab) {
769
- CapNotification.error(errorMessage);
770
- }
771
- }
772
- }
773
- stopValidation = () => {
774
- this.setState({startValidation: false}, () => {
775
- this.showError();
776
- this.props.onValidationFail();
777
- });
778
- }
779
- startValidation = () => {
780
- this.setState({startValidation: true});
781
- }
782
- openNotificationWithIcon = (type, message) => {
783
- const dur = (type === 'error' || type === 'warning') ? null : 5;
784
- notification[type]({
785
- message: (`${type.toUpperCase()} ! ! ! `),
786
- description: message, //'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
787
- duration: dur,
788
- });
789
- }
790
-
791
- handleCancelModal = () => {
792
- this.setState({showModal: false}, this.stopValidation);
793
- };
794
-
795
- moveToTemplates = () => {
796
- const modalContent = {
797
- title: this.props.intl.formatMessage(messages.alertMessage),
798
- body: this.props.intl.formatMessage(messages.goBackTemporaryChangesLost),
799
- type: 'confirm',
800
- id: 'template-back-confirm-modal',
801
- show: true,
802
- };
803
- this.setState({modalContent, showModal: true});
804
- };
805
-
806
- cancelTemplate = () => {
807
- const type = this.props.location.query.type;
808
- const module = this.props.location.query.module ? this.props.location.query.module : 'default';
809
- this.props.router.push({
810
- pathname: `/MOBILEPUSH/`,
811
- query: type === 'embedded' ? {type: 'embedded', module} : {module},
812
- });
813
- };
814
-
815
- injectEvents = (schema) => {
816
- const temp = schema;
817
- if (temp.standalone) {
818
- temp.standalone.sections = this.injectSections(temp.standalone.sections);
819
- }
820
- forEach(temp.containers, (container) => {
821
- let tempContainer = container;
822
- tempContainer = this.injectContainer(tempContainer);
823
- return tempContainer;
824
- });
825
-
826
- this.setState({schema, isSchemaChanged: true}, () => {
827
- this.removeStandAlone();
828
- });
829
- return schema;
830
- };
831
-
832
- injectContainer = (container) => {
833
- const temp = container;
834
- if (temp.type === 'tabs') {
835
- temp.injectedEvents = {};
836
- forEach(temp.supportedEvents, (event) => {
837
- temp.injectedEvents[event] = this.getMappedEvent(temp.id, event);
838
- });
839
- forEach(temp.panes, (pane) => {
840
- const tempPane = pane;
841
- tempPane.sectionsHeaders = this.injectSections(tempPane.sectionsHeaders);
842
- tempPane.sections = this.injectSections(tempPane.sections);
843
- });
844
- }
845
- return temp;
846
- };
847
-
848
- injectMultiColSection = (section) => {
849
- const { formatMessage } = this.props.intl;
850
- forEach(section.inputFields, (inputField) => {
851
- forEach(inputField.cols, (col) => {
852
- const temp = col;
853
- if (temp.type === 'popover') {
854
- temp.content.sections = this.injectSections(temp.content.sections);
855
- temp.value.sections = this.injectSections(temp.value.sections);
856
- return true;
857
- }
858
- if (temp.id === "discard-button") {
859
- temp.colStyle = {...temp.colStyle, display: 'none'};
860
- }
861
- if (temp.id === "cancel-button") {
862
- temp.offset = 11;
863
- }
864
- if (temp.id === "mobile-push-preview") {
865
- temp.content.appName = this.props.Templates.selectedWeChatAccount.name;
866
- }
867
-
868
- if (messages?.[temp?.value]) {
869
- temp.value = formatMessage(messages[temp.value]);
870
- }
871
- if (messages?.[temp?.label]) {
872
- temp.label = formatMessage(messages[temp.label]);
873
- }
874
- if (messages?.[temp?.errorMessage]) {
875
- temp.errorMessage = formatMessage(messages[temp.errorMessage]);
876
- }
877
- if (messages?.[temp?.placeholder]) {
878
- temp.placeholder = formatMessage(messages[temp.placeholder]);
879
- }
880
- if (messages?.[temp?.hoverText]) {
881
- temp.hoverText = formatMessage(messages[temp.hoverText]);
882
- }
883
- if (messages?.[temp?.previewProps?.label]) {
884
- temp.previewProps.label = formatMessage(messages[temp.previewProps.label]);
885
- }
886
- if (messages?.[temp?.previewProps?.inductiveText]) {
887
- temp.previewProps.inductiveText = formatMessage(messages[temp.previewProps.inductiveText]);
888
- }
889
- if (messages?.[temp?.previewProps?.errorMessage]) {
890
- temp.previewProps.errorMessage = formatMessage(messages[temp.previewProps.errorMessage]);
891
- }
892
-
893
- temp.injectedEvents = {};
894
-
895
- forEach(col.supportedEvents, (event) => {
896
- temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
897
- });
898
- return true;
899
- });
900
- });
901
- forEach(section.actionFields, (actionField) => {
902
- forEach(actionField.cols, (col) => {
903
- const temp = col;
904
- if (temp.type === 'popover') {
905
- temp.content.sections = this.injectSections(temp.content.sections);
906
- temp.value.sections = this.injectSections(temp.value.sections);
907
- return true;
908
- }
909
- temp.injectedEvents = {};
910
- forEach(col.supportedEvents, (event) => {
911
- temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
912
- });
913
- return true;
914
- });
915
- });
916
- return section;
917
- };
918
-
919
- injectColLabelSection = (section) => {
920
- forEach(section.inputFields, (inputField) => {
921
- const temp = inputField;
922
- if (temp.type === 'popover') {
923
- temp.content.sections = this.injectSections(temp.content.sections);
924
- temp.value.sections = this.injectSections(temp.value.sections);
925
- return true;
926
- }
927
- temp.injectedEvents = {};
928
- forEach(inputField.supportedEvents, (event) => {
929
- temp.injectedEvents[event] = this.getMappedEvent(inputField.id, event);
930
- });
931
- return true;
932
- });
933
- forEach(section.actionFields, (actionField) => {
934
- const temp = actionField;
935
- if (temp.type === 'popover') {
936
- temp.content.sections = this.injectSections(temp.content.sections);
937
- temp.value.sections = this.injectSections(temp.value.sections);
938
- return true;
939
- }
940
- temp.injectedEvents = {};
941
- forEach(actionField.supportedEvents, (event) => {
942
- temp.injectedEvents[event] = this.getMappedEvent(actionField.id, event);
943
- });
944
- return true;
945
- });
946
- return section;
947
- };
948
-
949
- injectSections = (sections) => {
950
- forEach(sections, (section) => {
951
- let temp = section;
952
- if (temp.type === 'col-label') {
953
- temp = this.injectColLabelSection(temp);
954
- } else if (section.type === 'multicols') {
955
- temp = this.injectMultiColSection(temp);
956
- } else if (section.type === 'parent') {
957
- temp = this.injectSections(temp.childSections);
958
- }
959
- });
960
- return sections;
961
- };
962
-
963
- injectParentSection = (section) => {
964
- forEach(section.childSections, (childSection) => {
965
- let temp = childSection;
966
- if (temp.type === 'col-label') {
967
- temp = this.injectColLabelSection(temp);
968
- } else if (section.type === 'multicols') {
969
- temp = this.injectMultiColSection(temp);
970
- } else if (section.type === 'parent') {
971
- temp = this.injectParentSection(temp);
972
- }
973
- });
974
- return section;
975
- };
976
- insertAtCursor = (field, myValue, currentTab) => {
977
- //IE support
978
- const myField = field;
979
- if (document.selection) {
980
- myField.focus();
981
- const sel = document.selection.createRange();
982
- sel.text = myValue;
983
- } else if (myField.selectionStart || myField.selectionStart === '0') { //MOZILLA and others
984
- const startPos = myField.selectionStart;
985
- const endPos = myField.selectionEnd;
986
- myField.value = myField.value.substring(0, startPos)
987
- + myValue
988
- + myField.value.substring(endPos, myField.value.length);
989
- myField.selectionStart = startPos + myValue.length;
990
- myField.selectionEnd = startPos + myValue.length;
991
- } else {
992
- myField.value += myValue;
993
- }
994
- const formData = cloneDeep(this.state.formData);
995
- formData[currentTab - 1][field.id] = myField.value;
996
- this.setState({formData});
997
- };
998
-
999
- startTemplateCreation = (data) => {
1000
- const content = data.content;
1001
- const id = uniqueId();
1002
- const tempData = {
1003
- 'message-editor': content,
1004
- 'base': true,
1005
- 'tabKey': id,
1006
- };
1007
- const formData = {};
1008
- formData[0] = tempData;
1009
- formData.base = tempData;
1010
- this.setState({formData, loading: false});
1011
- if (data.tags) {
1012
- this.props.globalActions.setInjectedTags(data.tags);
1013
- }
1014
- };
1015
-
1016
- startLoading = (ifEdit) => {
1017
- if (ifEdit) {
1018
- this.setState({loading: true});
1019
- }
1020
- };
1021
-
1022
- handleFrameTasks = (e) => {
1023
- const type = e.data;
1024
-
1025
- if (typeof type === 'object') {
1026
- const action = type.action;
1027
- switch (action) {
1028
- case "startTemplateCreation":
1029
- this.startTemplateCreation(type.value);
1030
- break;
1031
- case "startLoading":
1032
- this.startLoading(type.edit);
1033
- break;
1034
- case "getCurrentWindow":
1035
- this.getCurrentWindow(type);
1036
- break;
1037
- default:
1038
- break;
1039
- }
1040
- } else {
1041
- switch (type) {
1042
- case "getFormData":
1043
- this.getFormData(e);
1044
- break;
1045
- case "startTemplateCreation":
1046
-
1047
- //this.getFormData(e);
1048
- break;
1049
- case "moveToTemplates":
1050
-
1051
- this.moveToTemplates();
1052
- break;
1053
- case "validateContent":
1054
-
1055
- this.validateContent(e);
1056
- break;
1057
- default:
1058
- break;
1059
- }
1060
- }
1061
- };
1062
-
1063
- removeStandAlone = () => {
1064
- const schema = cloneDeep(this.state.schema);
1065
- if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty') {
1066
- schema.standalone.sections.splice(0, 1);
1067
- } else if ((this.props.location.query.type === 'embedded' && typeof this.props.location.query.module !== 'undefined') || this.props.isFullMode) {
1068
- delete schema.standalone;
1069
- } else {
1070
- schema.standalone.sections.splice(1, 1);
1071
- }
1072
- this.setState({ schema });
1073
- };
1074
-
1075
- validateContent = (e) => {
1076
- const response = {
1077
- action: "validateContent",
1078
- value: this.state.isFormValid,
1079
- };
1080
- e.source.postMessage(JSON.stringify(response), e.origin);
1081
- };
1082
-
1083
- discardValues = () => {
1084
- this.resetSchema();
1085
- this.resetState();
1086
- };
1087
-
1088
- resetState = () => {
1089
- this.setState({
1090
- formData: {},
1091
- tabCount: 1,
1092
- currentTab: 1,
1093
- });
1094
- };
1095
- resetSchema = () => {
1096
- this.setState({ schema: this.state.initialState ? this.state.initialState : this.state.schema});
1097
- };
1098
- showNext = () => {
1099
- const response = {
1100
- action: "showNext",
1101
- value: true,
1102
- };
1103
- parent.postMessage(JSON.stringify(response), '*');
1104
- };
1105
- copyContent = () => {
1106
-
1107
- };
1108
- addSecondoryCtaIos = (flag, formData, schemaField) => {
1109
- const id = schemaField.id;
1110
- if (formData[this.state.currentTab - 1][id]) {
1111
- if (!this.props.iosCtasData) {
1112
- this.props.actions.getIosCtas(this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier);//TODO: need to get license code of accoutn and send as arg
1113
- } else {
1114
- this.deleteSecondaryCtaIos(() => { // oncick of change
1115
- this.setState({showIosCtaTable: true});
1116
- });
1117
- }
1118
- } else {
1119
- const schema = cloneDeep(this.state.schema);
1120
- const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1121
- forEach(inputFields, (inputField, fieldIndex) => {
1122
- forEach(inputField.cols, (col) => {
1123
- if (col.id === id) {
1124
- const indexOfNextField = inputFields.length;
1125
- const deleteCount = indexOfNextField - fieldIndex;
1126
- const newInputFields = [...inputFields.slice(0, fieldIndex + 1), ...inputFields.slice(fieldIndex + deleteCount, inputField.length)];
1127
- set(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
1128
- this.setState({schema});
1129
- }
1130
- });
1131
- });
1132
- }
1133
- };
1134
- showSelectedIosCta = (selectedConfig) => {
1135
- const currentTab = this.state.currentTab;
1136
- const schema = cloneDeep(this.state.schema);
1137
- const deeplinks = this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.configs && !!this.props.Templates.selectedWeChatAccount.configs.deeplink ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
1138
- const deepLinkOptions = this.props.Templates.selectedWeChatAccount ? map(JSON.parse(deeplinks), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
1139
- const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1140
- forEach(inputFields, (inputField, fieldIndex) => {
1141
- forEach(inputField.cols, (col) => {
1142
- if (col.id === "add-sec-cta-ios") {
1143
- const inputId = `secondary-cta-${currentTab - 1}`;
1144
-
1145
- inputFields.splice(fieldIndex + 1, 0, {
1146
- rowClassName: 'mobile-push-row',
1147
- cols: [
1148
- {
1149
- id: `${inputId}-action-display`,
1150
- metaType: "label",
1151
- value: <CapRow>
1152
- <CapColumn span={18}>
1153
- <CapHeader
1154
- title={this.state.templateCta.name}
1155
- description={get(this.state, "templateCta.ctaTemplateDetails[0].buttonText")}
1156
- size={"label"}/>
1157
- </CapColumn>
1158
- <CapColumn span={6}>
1159
- <CapLink title={this.props.intl.formatMessage(messages.change)} onClick={() => this.addSecondoryCtaIos(true, this.state.formData, {id: "add-sec-cta-ios"})}/>
1160
- </CapColumn>
1161
- </CapRow>,
1162
- primitive: true,
1163
- dynamicTab: false,
1164
- type: "div",
1165
- width: 18,
1166
- offset: 1,
1167
- },
1168
- {
1169
- id: `${inputId}-action`,
1170
- metaType: "label",
1171
- value: "",
1172
- primitive: true,
1173
- dynamicTab: false,
1174
- type: "div",
1175
- width: 8,
1176
- offset: 0,
1177
- style: {
1178
- display: 'none',
1179
- },
1180
- },
1181
- {
1182
- id: `${inputId}-action2`,
1183
- metaType: "label",
1184
- value: "",
1185
- primitive: true,
1186
- dynamicTab: false,
1187
- type: "div",
1188
- width: 8,
1189
- offset: 0,
1190
- style: {display: 'none'},
1191
- },
1192
-
1193
- ],
1194
- });
1195
- const selectedConfigTemplateCtaId = get(selectedConfig, 'ctaTemplateDetails[0].id');
1196
- // the option to select deeplink and externa link should not come for these ctas
1197
- if (selectedConfigTemplateCtaId && (selectedConfigTemplateCtaId.id !== "3heicig" && selectedConfigTemplateCtaId.id !== "6eigf4f" && selectedConfigTemplateCtaId.id !== "c97d0ed")) {
1198
- inputFields.splice(fieldIndex + 2, 0, {
1199
- rowClassName: "mobile-push-row",
1200
- cols: [
1201
-
1202
- {
1203
- id: `cta-deeplink-${inputId}`,
1204
- type: "radioGroup", //Resembles component to be used
1205
- metaType: "text",
1206
- datatype: "string",
1207
- options: ["Deeplink", "External Link"],
1208
- inductiveText: [<FormattedMessage {...messages.aPageWithMobileApp}/>, <FormattedMessage {...messages.anExternalWebPage}/>],
1209
- value: "Deeplink",
1210
- required: true,
1211
- width: 18,
1212
- offset: 1,
1213
- errorMessage: this.props.intl.formatMessage(messages.selectLinkType),
1214
- fluid: true,
1215
-
1216
- styling: "semantic",
1217
- order: 1,
1218
- supportedEvents: ["onChange"],
1219
- customComponent: false,
1220
- },
1221
- ],
1222
- });
1223
- inputFields.splice(fieldIndex + 3, 0, {
1224
- rowClassName: 'mobile-push-row',
1225
- id: 'cta-deeplink-select-section',
1226
- cols: [
1227
-
1228
- {
1229
- id: `cta-deeplink-${inputId}-select2`,
1230
- placeholder: this.props.intl.formatMessage(messages.selectDeeplink),
1231
- type: "select", //Resembles component to be used
1232
- options: deepLinkOptions,
1233
- metaType: "text",
1234
- datatype: "string",
1235
- errorMessage: this.props.intl.formatMessage(messages.selectADeeplink),
1236
- required: true,
1237
- fluid: true,
1238
- width: 18,
1239
- offset: 1,
1240
- style: {
1241
- width: '100%',
1242
- marginBottom: '16px',
1243
- },
1244
- styling: "semantic",
1245
- order: 1,
1246
- customComponent: false,
1247
- supportedEvents: [
1248
- 'onSelect',
1249
- ],
1250
- },
1251
- ],
1252
- });
1253
- }
1254
- }
1255
- });
1256
- });
1257
- // set(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`, inputFields);
1258
-
1259
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true});
1260
- this.injectEvents(schema);
1261
- };
1262
- addPrimaryCta = (flag, formData, schemaField) => {
1263
- const id = schemaField.id;
1264
- const schema = cloneDeep(this.state.schema);
1265
- const deeplinks = this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.configs && !!this.props.Templates.selectedWeChatAccount.configs.deeplink ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
1266
- const deepLinkOptions = this.props.Templates.selectedWeChatAccount ? map(JSON.parse(deeplinks), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
1267
- // const eventsMap = cloneDeep(this.state.eventsMap);
1268
- const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1269
- forEach(inputFields, (inputField, fieldIndex) => {
1270
- forEach(inputField.cols, (col) => {
1271
- const colId = col.id;
1272
- if (colId === id) {
1273
- if (formData[this.state.currentTab - 1][id]) { // add primary cta
1274
- inputFields.splice(fieldIndex + 1, 0, {
1275
- rowClassName: 'mobile-push-row',
1276
- cols: [
1277
- {
1278
- id: `cta-deeplink${this.state.currentTab > 1 ? this.state.currentTab : ''}`,
1279
- type: "radioGroup", //Resembles component to be used
1280
- metaType: "text",
1281
- datatype: "string",
1282
- options: ["Deeplink", "External Link"],
1283
- inductiveText: [<FormattedMessage {...messages.aPageWithMobileApp}/>, <FormattedMessage {...messages.anExternalWebPage}/>],
1284
- value: "Deeplink",
1285
- required: true,
1286
- width: 18,
1287
- offset: 1,
1288
- errorMessage: this.props.intl.formatMessage(messages.selectLinkType),
1289
- fluid: true,
1290
- styling: "semantic",
1291
- order: 1,
1292
- customComponent: false,
1293
- supportedEvents: ["onChange"],
1294
- },
1295
-
1296
- ],
1297
- });
1298
- inputFields.splice(fieldIndex + 2, 0, {
1299
- rowClassName: 'mobile-push-row',
1300
- id: 'cta-deeplink-select-section',
1301
- cols: [
1302
-
1303
- {
1304
- id: `cta-deeplink${this.state.currentTab > 1 ? this.state.currentTab : ''}-select`,
1305
- placeholder: this.props.intl.formatMessage(messages.selectDeeplink),
1306
- type: "select", //Resembles component to be used
1307
- options: deepLinkOptions,
1308
- metaType: "text",
1309
- datatype: "string",
1310
- required: true,
1311
- errorMessage: this.props.intl.formatMessage(messages.selectADeeplink),
1312
- fluid: true,
1313
- width: 18,
1314
- offset: 1,
1315
- style: {
1316
- width: '100%',
1317
-
1318
-
1319
- marginBottom: '16px',
1320
- },
1321
- styling: "semantic",
1322
- order: 1,
1323
- customComponent: false,
1324
- supportedEvents: [
1325
- 'onSelect',
1326
- ],
1327
- },
1328
- ],
1329
- });
1330
- } else { // remove existing primary cta cuz primary cta is unchecked
1331
- const identifier = (this.state.currentTab - 1) ? 'add-sec-cta-ios' : 'add-sec-cta';
1332
- const indexOfNextField = findIndex(inputFields, {identifier});
1333
- const deleteCount = indexOfNextField - fieldIndex;
1334
- const newInputFields = [...inputFields.slice(0, fieldIndex + 1), ...inputFields.slice(fieldIndex + deleteCount, inputFields.length)];
1335
- set(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
1336
- }
1337
- }
1338
- });
1339
- });
1340
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true, formData}, () => this.injectEvents(schema));
1341
- };
1342
- addSecondoryCta = (flag, formData, schemaField) => {
1343
- const id = schemaField.id;
1344
- const schema = cloneDeep(this.state.schema);
1345
- const formDataCopy = cloneDeep(formData);
1346
- const ck = this.props.Templates.selectedWeChatAccount.configs ? !!this.props.Templates.selectedWeChatAccount.configs.deeplink : false;
1347
- const deeplinks = ck ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
1348
- const deepLinkOptions = this.props.Templates.selectedWeChatAccount ? map(JSON.parse(deeplinks), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
1349
- // const eventsMap = cloneDeep(this.state.eventsMap);
1350
- const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1351
- forEach(inputFields, (inputField, fieldIndex) => {
1352
- forEach(inputField.cols, (col) => {
1353
- if (col.id === id) {
1354
- if (formData[this.state.currentTab - 1][id]) {
1355
- const inputId = `secondary-cta-${col.fieldsCount}`;
1356
- inputFields.splice(fieldIndex + 1, 0, {
1357
- rowClassName: 'mobile-push-row',
1358
- cols: [
1359
-
1360
- {
1361
- id: `${inputId}-label`,
1362
- label: "Button label",
1363
- type: "input", //Resembles component to be used
1364
- metaType: "text",
1365
- datatype: "string",
1366
- required: true,
1367
- width: 18,
1368
- offset: 1,
1369
- placeholder: this.props.intl.formatMessage(messages.enterCTALabel),
1370
- fluid: true,
1371
- styling: "semantic",
1372
- order: 1,
1373
- customComponent: false,
1374
- errorMessage: this.props.intl.formatMessage(messages.ctaLabelCantEmpty),
1375
- },
1376
-
1377
- ],
1378
- });
1379
- inputFields.splice(fieldIndex + 2, 0, {
1380
- rowClassName: 'mobile-push-row',
1381
- cols: [
1382
-
1383
- {
1384
- id: `cta-deeplink-${inputId}`,
1385
- type: "radioGroup", //Resembles component to be used
1386
- metaType: "text",
1387
- datatype: "string",
1388
- options: ["Deeplink", "External Link"],
1389
- inductiveText: [<FormattedMessage {...messages.aPageWithMobileApp}/>, <FormattedMessage {...messages.anExternalWebPage}/>],
1390
- value: "Deeplink",
1391
- required: true,
1392
- width: 18,
1393
- offset: 1,
1394
- errorMessage: this.props.intl.formatMessage(messages.selectLinkType),
1395
- fluid: true,
1396
- styling: "semantic",
1397
- order: 1,
1398
-
1399
- customComponent: false,
1400
- supportedEvents: ["onChange"],
1401
- },
1402
- ],
1403
- });
1404
- inputFields.splice(fieldIndex + 3, 0, {
1405
- rowClassName: 'mobile-push-row',
1406
- id: 'cta-deeplink-select-section',
1407
- cols: [
1408
-
1409
-
1410
- {
1411
- id: `cta-deeplink-${inputId}-select`,
1412
- placeholder: this.props.intl.formatMessage(messages.selectDeeplink),
1413
- type: "select", //Resembles component to be used
1414
- options: deepLinkOptions,
1415
- errorMessage: this.props.intl.formatMessage(messages.selectADeeplink),
1416
- metaType: "text",
1417
- datatype: "string",
1418
- required: true,
1419
- fluid: true,
1420
- width: 18,
1421
- offset: 1,
1422
- style: {
1423
- width: '100%',
1424
- marginBottom: '16px',
1425
- },
1426
- styling: "semantic",
1427
- order: 1,
1428
- customComponent: false,
1429
- supportedEvents: [
1430
- 'onSelect',
1431
- ],
1432
- },
1433
- ],
1434
- });
1435
-
1436
- // eventsMap[`cta-deeplink-${inputId}`] = {"onChange": this.onLinkTypeChange};
1437
- } else {
1438
- const identifier = id === "add-sec-cta" ? 'add-sec-cta-2' : null;
1439
- const indexOfNextField = identifier ? findIndex(inputFields, {identifier}) : inputFields.length;
1440
- const deleteCount = indexOfNextField - fieldIndex;
1441
- const newInputFields = [...inputFields.slice(0, fieldIndex + 1), ...inputFields.slice(fieldIndex + deleteCount, inputFields.length)];
1442
- set(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
1443
- }
1444
- }
1445
- });
1446
- });
1447
- if (id === "add-sec-cta") {
1448
- //The following block of code enables and disables add secondary button based on the primary button
1449
- const indexOfSecondary = findIndex(inputFields, {identifier: 'add-sec-cta-2'});
1450
- inputFields[indexOfSecondary].cols[0].disabled = !formData[this.state.currentTab - 1][id];
1451
- //Calling the following function to unset the data set under secondary button
1452
- if (!formData[this.state.currentTab - 1][id]) {
1453
- formDataCopy[this.state.currentTab - 1]['add-sec-cta-2'] = false;
1454
- }
1455
- //Calling set state here to update the state and schema before manually triggering secondarycta update
1456
- this.setState(
1457
- {schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true},
1458
- () => {
1459
- this.injectEvents(schema);
1460
- this.addSecondoryCta(true, formDataCopy, inputFields[indexOfSecondary].cols[0]);
1461
- });
1462
- } else {
1463
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true}, () => { this.injectEvents(schema); });
1464
- }
1465
- };
1466
- copyIphoneContent = () => {
1467
- const formData = cloneDeep(this.state.formData);
1468
- if (!!formData[1]['message-title2'] && !!formData[1]['message-editor2']) {
1469
- formData[0]['message-title'] = formData[1]['message-title2'];
1470
- formData[0]['message-editor'] = formData[1]['message-editor2'];
1471
- this.setState({formData});
1472
- } else {
1473
- this.openNotificationWithIcon('warning', this.props.intl.formatMessage(messages.cantCopyEmptyFieldValues));
1474
- }
1475
- };
1476
- copyAndroidContent = () => {
1477
- const formData = cloneDeep(this.state.formData);
1478
- if (!!formData[0]['message-title'] && !!formData[0]['message-editor']) {
1479
- formData[1]['message-title2'] = formData[0]['message-title'];
1480
- formData[1]['message-editor2'] = formData[0]['message-editor'];
1481
- this.setState({formData});
1482
- } else {
1483
- this.openNotificationWithIcon('warning', this.props.intl.formatMessage(messages.cantCopyEmptyFieldValues));
1484
- }
1485
- };
1486
- uploadImage = (data) => {
1487
- if (data.fileParams.error) {
1488
- CapNotification.error({
1489
- message: this.props.intl.formatMessage(messages.uploadImageSizeErrorTitle),
1490
- description: this.props.intl.formatMessage(messages.uploadImageSizeErrorDescription),
1491
- duration: 2,
1492
- });
1493
- } else {
1494
- this.props.actions.uploadAsset(data.file, data.type, data.fileParams);
1495
- }
1496
- };
1497
- selectCtaIos = (selectedConfig) => {
1498
- this.showSelectedIosCta(selectedConfig);
1499
- };
1500
-
1501
- showCtaKeys = (eventTriggered, formData, field) => {
1502
- const schema = cloneDeep(this.state.schema);
1503
- const eventsMap = cloneDeep(this.state.eventsMap);
1504
- forEach(schema.containers, (container) => {
1505
- forEach(container.panes, (pane) => {
1506
- forEach(pane.sections, (section) => {
1507
- forEach(section.childSections, (childeSection) => {
1508
- forEach(childeSection.childSections, (child) => {
1509
- const formChaild = child;
1510
- if (child.type === 'multicols') {
1511
- forEach(child.inputFields, (inputField, fieldIndex) => {
1512
- forEach(inputField.cols, (col) => {
1513
- if (col.id === field.id) {
1514
- const formDataKey = col.id.replace("-show-keys", "");
1515
- const deeplinks = this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.configs && !!this.props.Templates.selectedWeChatAccount.configs.deeplink ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
1516
- let keys = this.props.Templates.selectedWeChatAccount ? filter(JSON.parse(deeplinks), (dl) => dl.link === formData[this.state.currentTab - 1][formDataKey]) : [];
1517
- if (keys[0]) {
1518
- keys = keys[0].keys;
1519
- }
1520
- let rows = map(keys, (key) => {
1521
- const row = {
1522
- rowClassName: 'mobile-push-row',
1523
- id: 'cta-deeplink-keys',
1524
- cols: [
1525
-
1526
-
1527
- {
1528
- id: `custom-value-${key}-${col.id}`,
1529
- label: key.replace('_', " "),
1530
- type: "input", //Resembles component to be used
1531
- metaType: "text",
1532
- datatype: "string",
1533
- required: true,
1534
- width: 18,
1535
- offset: 1,
1536
- placeholder: `${this.props.intl.formatMessage(messages.pleaseInput)} ${key.replace('_', " ")} ${this.props.intl.formatMessage(messages.here)}`,
1537
- fluid: true,
1538
- styling: "semantic",
1539
- order: 1,
1540
- customComponent: false,
1541
- errorMessage: this.props.intl.formatMessage(messages.valueCantEmpty),
1542
- },
1543
- ],
1544
- };
1545
- //eventsMap[`custome-${key}`] = {"onChange": this.onMessageTitleChange};
1546
- return row;
1547
- // formChaild.inputFields[fieldIndex + index] = field;
1548
- });
1549
-
1550
-
1551
- const configkeys = filter(JSON.parse(deeplinks), (dl) => dl.link === this.state.formData[this.state.currentTab - 1][field.id]);
1552
- if (configkeys.length) {
1553
- const options = configkeys[0].keys;
1554
- formChaild.inputFields = formChaild.inputFields.slice(0, fieldIndex + 1).concat(formChaild.inputFields.slice( fieldIndex + options.length + 1, formChaild.inputFields.length));
1555
- // delete formData[self.state.currentTab - 1][`cta-deeplink-${id.replace('delete', 'select')}`];
1556
- // delete formData[self.state.currentTab - 1][`cta-deeplink-${id.replace('-delete', '')}`];
1557
- }
1558
- if (formChaild.inputFields[fieldIndex + 1] && formChaild.inputFields[fieldIndex + 1].id === "cta-deeplink-keys") {
1559
- rows = formChaild.inputFields.slice(0, fieldIndex + 1).concat(rows).concat(formChaild.inputFields.slice(fieldIndex + 1, formChaild.inputFields.length));
1560
- formChaild.inputFields = rows;
1561
- } else {
1562
- rows = formChaild.inputFields.slice(0, fieldIndex + 1).concat(rows).concat(formChaild.inputFields.slice(fieldIndex + 1, formChaild.inputFields.length));
1563
- formChaild.inputFields = rows;
1564
- }
1565
- }
1566
- });
1567
- });
1568
- }
1569
- });
1570
- });
1571
- });
1572
- });
1573
- });
1574
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, eventsMap, isSchemaChanged: true});
1575
- this.injectEvents(schema);
1576
- };
1577
-
1578
- saveFormData = (formData) => {
1579
- //this function gets called from form bulder only when the form data is valid
1580
-
1581
- // Check for personalization tokens if restriction is enabled
1582
- if (this.props.restrictPersonalization) {
1583
- const hasTokens = checkForPersonalizationTokens(formData);
1584
- if (hasTokens) {
1585
- const message = this.props.intl.formatMessage(messages.personalizationTokensErrorMessage);
1586
- CapNotification.error({message, key: 'personalizationTokensError'});
1587
- return;
1588
- }
1589
- }
1590
-
1591
- const obj = this.getTransformedData(formData);
1592
- const content = getContent(obj);
1593
- const {
1594
- definition: {
1595
- mode: definitionMode,
1596
- },
1597
- } = obj || {};
1598
- const label = this.props.location.pathname.indexOf('image') >= 0 ? 'image' : 'text';
1599
- // Full mode: a template created earlier in this session is updated (same API, with its _id)
1600
- const { savedTemplateId } = this.state;
1601
- if (savedTemplateId) {
1602
- obj._id = savedTemplateId;
1603
- }
1604
- this.props.actions.createTemplate(obj, (response) => {
1605
- const timeTaken = GA.timeTracker.stopTimer(TRACK_CREATE_MPUSH, {
1606
- category: 'Creatives',
1607
- action: TRACK_CREATE_MPUSH,
1608
- label,
1609
- });
1610
- gtmPush('creativeDetails', {
1611
- id: response.templateId,
1612
- name: obj.name,
1613
- channel: MOBILE_PUSH,
1614
- timeTaken,
1615
- content,
1616
- mode: savedTemplateId ? EDIT : CREATE,
1617
- imageAdded: definitionMode === 'image',
1618
- });
1619
-
1620
- this.props.actions.clearCreateResponse();
1621
- if (this.props.isFullMode) {
1622
- // Stay open: next save updates this template.
1623
- const savedResponse = response?.templateId;
1624
- const newTemplateId = (isPlainObject(savedResponse) ? savedResponse._id : savedResponse) || savedTemplateId;
1625
- this.setState({ savedTemplateId: newTemplateId });
1626
- const message = this.props.intl.formatMessage(savedTemplateId ? editMessages['MOBILEPUSH Template Edited Successfully'] : messages.messageCreateSuccess);
1627
- CapNotification.success({message, key: 'createMpushSuccess'});
1628
- this.props.getFormLibraryData({ _id: newTemplateId, validity: true, keepSlideBoxOpen: true });
1629
- return;
1630
- }
1631
- this.discardValues();
1632
- const message = this.props.intl.formatMessage(messages.messageCreateSuccess);
1633
- CapNotification.success({message, key: 'createMpushSuccess'});
1634
- this.props.getFormLibraryData({validity: true});
1635
- });
1636
- };
1637
- deleteSecondaryCtaIos = (callback) => {
1638
- const schema = cloneDeep(this.state.schema);
1639
- const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1640
- forEach(inputFields, (inputField, fieldIndex) => {
1641
- if (inputField) {
1642
- forEach(inputField.cols, (col) => {
1643
- if (col.id === "add-sec-cta-ios") {
1644
- inputFields.splice(fieldIndex + 1, inputFields.length);
1645
- }
1646
- });
1647
- }
1648
- });
1649
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true}, callback);
1650
- this.injectEvents(schema);
1651
- };
1652
- deletePrimaryCTA = (event) => {
1653
- const id = event.currentTarget.id;
1654
- const schema = cloneDeep(this.state.schema);
1655
- // const eventsMap = cloneDeep(this.state.eventsMap);
1656
- const selectedDeeplink = this.state.formData[this.state.currentTab - 1][`${id.replace('delete', 'select')}`];
1657
- const formData = cloneDeep(this.state.formData);
1658
- const self = this;
1659
- forEach(schema.containers, (container) => {
1660
- forEach(container.panes, (pane) => {
1661
- forEach(pane.sections, (section) => {
1662
- forEach(section.childSections, (childeSection) => {
1663
- forEach(childeSection.childSections, (formChild) => {
1664
- const child = formChild;
1665
- if (child.type === 'multicols') {
1666
- forEach(child.inputFields, (inputField, fieldIndex) => {
1667
- if (inputField) {
1668
- forEach(inputField.cols, (col) => {
1669
- if (col.id === id) {
1670
- child.inputFields.splice(fieldIndex, 1);
1671
- if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-external-link") {
1672
- child.inputFields.splice(fieldIndex, 1);
1673
- }
1674
- if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-deeplink-select-section") {
1675
- const deeplinks = this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.configs && !!this.props.Templates.selectedWeChatAccount.configs.deeplink ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
1676
- const configkeys = this.props.Templates.selectedWeChatAccount ? filter(JSON.parse(deeplinks), (dl) => dl.link === selectedDeeplink) : [];
1677
- if (configkeys.length) {
1678
- const options = configkeys[0].keys;
1679
- child.inputFields = child.inputFields.slice(0, fieldIndex).concat(child.inputFields.slice( fieldIndex + options.length + 1, child.inputFields.length));
1680
- delete formData[self.state.currentTab - 1][`${id.replace('delete', 'select')}`];
1681
- delete formData[self.state.currentTab - 1][`${id.replace('-delete', '')}`];
1682
- } else {
1683
- child.inputFields.splice(fieldIndex, 1);
1684
- }
1685
- }
1686
- child.inputFields.splice(fieldIndex, 0, {
1687
- cols: [
1688
- {
1689
- id: `${this.state.currentTab === 1 ? "add-pri-cta" : "add-pri-cta-ios"}`,
1690
- metaType: "label",
1691
- value: this.props.intl.formatMessage(messages.addPrimaryCTA),
1692
- primitive: true,
1693
- dynamicTab: false,
1694
- type: "div",
1695
- style: {
1696
- backgroundColor: 'white',
1697
- textAlign: 'left',
1698
- color: '#2673D7',
1699
-
1700
- cursor: 'pointer',
1701
- },
1702
- offset: 0,
1703
- onlyDisplay: true,
1704
- colStyle: {
1705
- flex: 1,
1706
- },
1707
- submitAction: "addPrimaryCta",
1708
- supportedEvents: ["addPrimaryCta"],
1709
- },
1710
- ],
1711
- });
1712
- }
1713
- });
1714
- }
1715
- });
1716
- }
1717
- });
1718
- });
1719
- });
1720
- });
1721
- });
1722
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, formData, isSchemaChanged: true});
1723
- this.injectEvents(schema);
1724
- };
1725
-
1726
- deleteSecondaryCTA = (event) => {
1727
- const id = event.currentTarget.id;
1728
- if (id === "secondary-cta-0-delete") {
1729
- const secCta2 = document.getElementById("secondary-cta-1-delete");
1730
- if (secCta2) {
1731
- const modalContent = {title: this.props.intl.formatMessage(messages.alertMessage), body: this.props.intl.formatMessage(messages.deleteSecondCTAFirst), type: 'info', show: true, onCancel: this.onModalCancel};
1732
- this.setState({modalContent, showModal: true});
1733
- return;
1734
- }
1735
- }
1736
- const schema = cloneDeep(this.state.schema);
1737
- // const eventsMap = cloneDeep(this.state.eventsMap);
1738
- const selectedDeeplink = this.state.formData[this.state.currentTab - 1][`cta-deeplink-${id.replace('delete', 'select')}`];
1739
- const formData = cloneDeep(this.state.formData);
1740
- const device = this.state.currentTab === 1 ? 'android' : 'ios';
1741
- forEach(schema.containers, (container) => {
1742
- forEach(container.panes, (pane) => {
1743
- forEach(pane.sections, (section) => {
1744
- forEach(section.childSections, (childeSection) => {
1745
- forEach(childeSection.childSections, (formChild) => {
1746
- const child = formChild;
1747
- if (child.type === 'multicols') {
1748
- forEach(child.inputFields, (inputField, fieldIndex) => {
1749
- if (inputField) {
1750
- forEach(inputField.cols, (col) => {
1751
- if (col.id === id) {
1752
- if (device === 'ios') {
1753
- child.inputFields.splice(fieldIndex, 3);
1754
- } else {
1755
- child.inputFields.splice(fieldIndex, 2);
1756
- }
1757
- if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-external-link") {
1758
- child.inputFields.splice(fieldIndex, 1);
1759
- }
1760
- if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-deeplink-select-section") {
1761
- const ck = this.props.Templates.selectedWeChatAccount.configs ? !!this.props.Templates.selectedWeChatAccount.configs.deeplink : false;
1762
- const deeplinks = ck ? this.props.Templates.selectedWeChatAccount.configs.deeplink : '[]';
1763
- const configkeys = this.props.Templates.selectedWeChatAccount ? filter(JSON.parse(deeplinks), (dl) => dl.link === selectedDeeplink) : [];
1764
- if (configkeys.length) {
1765
- const options = configkeys[0].keys;
1766
- child.inputFields = child.inputFields.slice(0, fieldIndex).concat(child.inputFields.slice( fieldIndex + options.length + 1, child.inputFields.length));
1767
- } else {
1768
- child.inputFields.splice(fieldIndex, 1);
1769
- }
1770
- }
1771
- if (device === 'ios') {
1772
- child.inputFields[fieldIndex] = {
1773
- cols: [
1774
- {
1775
- id: "add-sec-cta-ios",
1776
- metaType: "label",
1777
- value: this.props.intl.formatMessage(messages.addSecondaryCTA),
1778
- primitive: true,
1779
- dynamicTab: false,
1780
- type: "div",
1781
- style: {
1782
- backgroundColor: 'white',
1783
- textAlign: 'left',
1784
- color: '#2673D7',
1785
-
1786
- cursor: 'pointer',
1787
- },
1788
- offset: 0,
1789
- onlyDisplay: true,
1790
- colStyle: {
1791
- flex: 1,
1792
- },
1793
- submitAction: "addSecondaryCtaIos",
1794
- supportedEvents: ["addSecondaryCtaIos"],
1795
- },
1796
- ],
1797
- };
1798
- } else {
1799
- if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].cols[0] && child.inputFields[fieldIndex].cols[0].id === "add-sec-cta") {
1800
- child.inputFields[fieldIndex] = {
1801
- cols: [
1802
- {
1803
- id: "add-sec-cta",
1804
- metaType: "label",
1805
- value: this.props.intl.formatMessage(messages.addSecondaryCTA),
1806
- primitive: true,
1807
- dynamicTab: false,
1808
- type: "div",
1809
- style: {
1810
- backgroundColor: 'white',
1811
- textAlign: 'left',
1812
- color: '#2673D7',
1813
-
1814
- cursor: 'pointer',
1815
- },
1816
- offset: 0,
1817
- onlyDisplay: true,
1818
- colStyle: {
1819
- flex: 1,
1820
- },
1821
- submitAction: "addSecondaryCta",
1822
- supportedEvents: ['addSecondaryCta'],
1823
- fieldsLimit: 2,
1824
- fieldsCount: 0,
1825
- },
1826
- ],
1827
- };
1828
- }
1829
- if (id === "secondary-cta-1-delete" || child.inputFields[fieldIndex].cols[0].id === "cta-label" || child.inputFields[fieldIndex].cols[0].id === "secondary-cta-1-space") {
1830
- let nextFieldIndex = fieldIndex;
1831
- if (id === "secondary-cta-1-delete" || child.inputFields[fieldIndex].cols[0].id === "secondary-cta-1-space") {
1832
- nextFieldIndex = child.inputFields.length;
1833
- }
1834
- child.inputFields[nextFieldIndex] = {
1835
- cols: [
1836
- {
1837
- id: "add-sec-cta",
1838
- metaType: "label",
1839
- value: this.props.intl.formatMessage(messages.addAnotherCTA),
1840
- primitive: true,
1841
- dynamicTab: false,
1842
- type: "div",
1843
- style: {
1844
- backgroundColor: 'white',
1845
- textAlign: 'left',
1846
- color: '#2673D7',
1847
-
1848
- cursor: 'pointer',
1849
- },
1850
- offset: 0,
1851
- onlyDisplay: true,
1852
- colStyle: {
1853
- flex: 1,
1854
- },
1855
- submitAction: "addSecondaryCta",
1856
- supportedEvents: ['addSecondaryCta'],
1857
- fieldsLimit: 2,
1858
- fieldsCount: 1,
1859
- },
1860
- ],
1861
- };
1862
- }
1863
- }
1864
- }
1865
- });
1866
- }
1867
- });
1868
- }
1869
- });
1870
- });
1871
- });
1872
- });
1873
- });
1874
- this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, formData, isSchemaChanged: true});
1875
- this.injectEvents(schema);
1876
- };
1877
- handleOnTagsContextChange = (data) => {
1878
- const context = (data || '').toLowerCase() === 'all' ? 'default' : (data || '').toLowerCase();
1879
- if (this.lastFetchedTagContextRef === context) {
1880
- return;
1881
- }
1882
- this.lastFetchedTagContextRef = context;
1883
- const query = {
1884
- layout: 'mobilepush',
1885
- type: 'TAG',
1886
- context,
1887
- embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
1888
- };
1889
- this.props.globalActions.fetchSchemaForEntity(query);
1890
- };
1891
- handleClose = () => {
1892
- const formData = cloneDeep(this.state.formData);
1893
- formData[this.state.currentTab - 1]['add-sec-cta-ios'] = false;
1894
- this.setState({showIosCtaTable: false, formData});
1895
- }
1896
-
1897
- // Get template content for TestAndPreviewSlidebox
1898
- // MobilePush uses formData[0] for Android and formData[1] for iOS
1899
- getTemplateContent = () => {
1900
- if (!this.state.formData || this.state.formData.length < 2) {
1901
- return {
1902
- androidContent: {},
1903
- iosContent: {},
1904
- };
1905
- }
1906
- const androidData = this.state.formData[0] || {};
1907
- const iosData = this.state.formData[1] || {};
1908
-
1909
- // Extract actions (buttons) - format similar to TemplatePreview
1910
- const getActions = (data) => {
1911
- const actions = [];
1912
- // Primary CTA
1913
- if (data['cta-deeplink-label']) {
1914
- actions.push({
1915
- label: data['cta-deeplink-label'],
1916
- url: data['cta-deeplink-select'] || data['cta-deeplink-text'] || '',
1917
- });
1918
- }
1919
- // Secondary CTA
1920
- if (data['secondary-cta-0-label']) {
1921
- actions.push({
1922
- label: data['secondary-cta-0-label'],
1923
- url: data[`cta-deeplink-secondary-cta-0-select`] || data[`cta-deeplink-secondary-cta-0-text`] || '',
1924
- });
1925
- }
1926
- if (data['secondary-cta-1-label']) {
1927
- actions.push({
1928
- label: data['secondary-cta-1-label'],
1929
- url: data[`cta-deeplink-secondary-cta-1-select`] || data[`cta-deeplink-secondary-cta-1-text`] || '',
1930
- });
1931
- }
1932
- return actions;
1933
- };
1934
-
1935
- return {
1936
- androidContent: {
1937
- header: androidData['message-title'] || '',
1938
- bodyText: androidData['message-editor'] || '',
1939
- bodyImage: androidData.image || '',
1940
- actions: getActions(androidData),
1941
- carouselData: [], // MobilePush carousel support can be added later if needed
1942
- },
1943
- iosContent: {
1944
- header: iosData['message-title2'] || '',
1945
- bodyText: iosData['message-editor2'] || '',
1946
- bodyImage: iosData['image-upload-ios'] || '',
1947
- actions: getActions(iosData),
1948
- carouselData: [], // MobilePush carousel support can be added later if needed
1949
- },
1950
- };
1951
- }
1952
-
1953
- handleTestAndPreview = () => {
1954
- if (this.props.handleTestAndPreview) {
1955
- this.props.handleTestAndPreview();
1956
- }
1957
- }
1958
- render() {
1959
- let loading = this.props.Create.createTemplateInProgress ? this.props.Create.createTemplateInProgress : false;
1960
- if (this.props.Create.assetUploading) {
1961
- loading = true;
1962
- }
1963
- let tags = this.props.metaEntities && this.props.metaEntities.tags ? this.props.metaEntities.tags.standard : [];
1964
- if (this.props.supportedTags) {
1965
- tags = this.props.supportedTags; // if get default tags is not present and supported tags is present use that inlbrary mode
1966
- }
1967
- return (
1968
- <div className="creatives-mobilepush-create">
1969
- <CapSpin spinning={loading}>
1970
- <CapRow>
1971
- <CapColumn>
1972
- <FormBuilder
1973
- channel={MOBILE_PUSH}
1974
- key={"form builder"}
1975
- showLiquidErrorInFooter={this.props.showLiquidErrorInFooter}
1976
- schema={this.state.schema}
1977
- onSubmit={this.saveFormData}
1978
- onChange={this.onFormDataChange}
1979
- currentTab={this.state.currentTab}
1980
- parent={this}
1981
- formData={cloneDeep(this.state.formData)}
1982
- location={this.props.location}
1983
- tags={tags}
1984
- injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
1985
- onFormValidityChange={this.setFormValidity}
1986
- usingTabContainer
1987
- checkValidation={this.state.checkValidation}
1988
- iosCtasData={this.state.iosCtasData}
1989
- tabKey={this.state.tabKey}
1990
- tabCount={2}
1991
- showModal={this.state.showModal}
1992
- isSchemaChanged={this.state.isSchemaChanged}
1993
- modal={this.state.modalContent}
1994
- handleCancelModal={this.handleCancelModal}
1995
- iframeParent={parent}
1996
- router={this.props.router}
1997
- onContextChange={this.handleOnTagsContextChange}
1998
- setModalContent={this.setModalContent}
1999
- startValidation={this.state.startValidation}
2000
- stopValidation={this.stopValidation}
2001
- selectedOfferDetails={this.props.selectedOfferDetails}
2002
- onPreviewContentClicked={this.props.onPreviewContentClicked}
2003
- onTestContentClicked={this.props.onTestContentClicked}
2004
- templateData={this.props.templateData}
2005
- hideTestAndPreviewBtn={this.props.hideTestAndPreviewBtn}
2006
- isFullMode={this.props.isFullMode}
2007
- eventContextTags={this.props?.eventContextTags}
2008
- waitEventContextTags={this.props?.waitEventContextTags}
2009
- messageDetails={this.props?.messageDetails}
2010
- restrictPersonalization={this.props.restrictPersonalization}
2011
- />
2012
- </CapColumn>
2013
- {this.props.iosCtasData && this.state.showIosCtaTable &&
2014
- <CapSlideBox
2015
- size="size-l"
2016
- header={<CapHeader
2017
- title={<FormattedMessage {...messages.selectActionButton} />}
2018
- prefix={
2019
- <PrefixWrapper>
2020
- <CapIcons.BackIcon onClick={this.handleClose} />
2021
- </PrefixWrapper>
2022
- }
2023
-
2024
- />}
2025
- content={<CapTable
2026
- rowSelection={{
2027
- type: 'radio',
2028
- onSelect: (record) => {
2029
- this.setState({templateCta: record, showIosCtaTable: false}, () => this.selectCtaIos(record));
2030
- },
2031
- }}
2032
- dataSource={this.props.iosCtasData} columns={[
2033
- {
2034
- title: this.props.intl.formatMessage(messages.nameAndDescription),
2035
- dataIndex: "name",
2036
- key: "name",
2037
- width: 200,
2038
- render: (text, record) => (
2039
- <div>
2040
- <div>{record.name}</div>
2041
- <div>{record.description}</div>
2042
- </div>),
2043
- },
2044
- {
2045
- title: this.props.intl.formatMessage(messages.button1),
2046
- dataIndex: "description",
2047
- key: "button1",
2048
- width: 100,
2049
- render: (text, record) => (
2050
- <div>
2051
- {record.ctaTemplateDetails[0] && record.ctaTemplateDetails[0].buttonText}
2052
- </div>),
2053
- },
2054
- {
2055
- title: this.props.intl.formatMessage(messages.button2),
2056
- dataIndex: "description",
2057
- key: "button2",
2058
- width: 100,
2059
- render: (text, record) => (
2060
- <div>
2061
- {record.ctaTemplateDetails[1] ? record.ctaTemplateDetails[1].buttonText : ''}
2062
- </div>
2063
- ),
2064
- },
2065
- ]}
2066
- />}
2067
- show={this.state.showIosCtaTable}
2068
- handleClose={this.handleClose}
2069
- />
2070
- }
2071
-
2072
- </CapRow>
2073
- </CapSpin>
2074
- <TestAndPreviewSlidebox
2075
- show={this.props.showTestAndPreviewSlidebox || false}
2076
- onClose={this.props.handleCloseTestAndPreview}
2077
- formData={this.state.formData} // Pass actual formData for payload building
2078
- content={this.getTemplateContent()} // Also pass content for preview
2079
- currentChannel={MOBILE_PUSH}
2080
- accountId={this.props.Templates?.selectedWeChatAccount?.id || null} // Pass selected account ID for test message payload
2081
- />
2082
- </div>
2083
- );
2084
- }
2085
- }
2086
-
2087
- Create.propTypes = {
2088
- actions: PropTypes.object.isRequired,
2089
- isFullMode: PropTypes.bool,
2090
- Create: PropTypes.object,
2091
- router: PropTypes.object,
2092
- location: PropTypes.object,
2093
- route: PropTypes.object,
2094
- globalActions: PropTypes.object,
2095
- metaEntities: PropTypes.object,
2096
- params: PropTypes.object,
2097
- Templates: PropTypes.object,
2098
- intl: intlShape.isRequired,
2099
- supportedTags: PropTypes.array,
2100
- getDefaultTags: PropTypes.string,
2101
- iosCtasData: PropTypes.array,
2102
- injectedTags: PropTypes.object,
2103
- defaultData: PropTypes.object,
2104
- showTemplateName: PropTypes.func,
2105
- isGetFormData: PropTypes.bool,
2106
- onValidationFail: PropTypes.func,
2107
- getFormLibraryData: PropTypes.func,
2108
- onPreviewContentClicked: PropTypes.func,
2109
- onTestContentClicked: PropTypes.func,
2110
- onContentValidityChange: PropTypes.func,
2111
- eventContextTags: PropTypes.array,
2112
- waitEventContextTags: PropTypes.object,
2113
- getLiquidTags: PropTypes.func,
2114
- showLiquidErrorInFooter: PropTypes.func,
2115
- showTestAndPreviewSlidebox: PropTypes.bool,
2116
- handleTestAndPreview: PropTypes.func,
2117
- handleCloseTestAndPreview: PropTypes.func,
2118
- restrictPersonalization: PropTypes.bool,
2119
- isAnonymousType: PropTypes.bool,
2120
- onPersonalizationTokensChange: PropTypes.func,
2121
- };
2122
-
2123
- const mapStateToProps = createStructuredSelector({
2124
- Create: makeSelectCreate(),
2125
- createResponse: makeSelectCreateResponse(),
2126
- metaEntities: makeSelectMetaEntities(),
2127
- Templates: makeSelectTemplates(),
2128
- iosCtasData: makeSelectIosCta(),
2129
- injectedTags: setInjectedTags(),
2130
- });
2131
-
2132
- function mapDispatchToProps(dispatch) {
2133
- return {
2134
- actions: bindActionCreators(actions, dispatch),
2135
- globalActions: bindActionCreators(globalActions, dispatch),
2136
- };
2137
- }
2138
-
2139
- const withReducer = injectReducer({ key: 'mobileCreate', reducer: v2MobilePushCreateReducer });
2140
- const withSaga = injectSaga({ key: 'mobilePushDuplicateTemplate', saga: v2MobilePushWatchDuplicateTemplateSaga});
2141
-
2142
- export default withCreatives({
2143
- WrappedComponent: Create,
2144
- mapStateToProps,
2145
- mapDispatchToProps,
2146
- userAuth: false,
2147
- sagas: [withSaga],
2148
- reducers: [withReducer],
2149
- });