@capillarytech/creatives-library 2.0.80 → 2.0.81

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 (82) hide show
  1. package/components/FormBuilder/index.js +2 -1
  2. package/components/FormBuilder/test +1845 -0
  3. package/containers/CallTask/_callTask.scss +5 -0
  4. package/containers/CallTask/actions.js +15 -0
  5. package/containers/CallTask/constants.js +7 -0
  6. package/containers/CallTask/index.js +141 -0
  7. package/containers/CallTask/messages.js +21 -0
  8. package/containers/CallTask/reducer.js +23 -0
  9. package/containers/CallTask/sagas.js +11 -0
  10. package/containers/CallTask/selectors.js +25 -0
  11. package/containers/CallTask/tests/actions.test.js +18 -0
  12. package/containers/CallTask/tests/index.test.js +10 -0
  13. package/containers/CallTask/tests/reducer.test.js +9 -0
  14. package/containers/CallTask/tests/sagas.test.js +15 -0
  15. package/containers/CallTask/tests/selectors.test.js +10 -0
  16. package/containers/ChannelTemplates/actions.js +20 -0
  17. package/containers/ChannelTemplates/constants.js +8 -0
  18. package/containers/ChannelTemplates/index.js +48 -0
  19. package/containers/ChannelTemplates/messages.js +13 -0
  20. package/containers/ChannelTemplates/reducer.js +34 -0
  21. package/containers/ChannelTemplates/sagas.js +32 -0
  22. package/containers/ChannelTemplates/selectors.js +25 -0
  23. package/containers/ChannelTemplates/tests/actions.test.js +18 -0
  24. package/containers/ChannelTemplates/tests/index.test.js +10 -0
  25. package/containers/ChannelTemplates/tests/reducer.test.js +9 -0
  26. package/containers/ChannelTemplates/tests/sagas.test.js +15 -0
  27. package/containers/ChannelTemplates/tests/selectors.test.js +10 -0
  28. package/containers/CreativesContainer/SlideBoxContent.js +248 -0
  29. package/containers/CreativesContainer/SlideBoxFooter.js +38 -0
  30. package/containers/CreativesContainer/SlideBoxHeader.js +65 -0
  31. package/containers/CreativesContainer/actions.js +27 -0
  32. package/containers/CreativesContainer/constants.js +13 -0
  33. package/containers/CreativesContainer/index.js +418 -0
  34. package/containers/CreativesContainer/index.scss +27 -0
  35. package/containers/CreativesContainer/messages.js +17 -0
  36. package/containers/CreativesContainer/reducer.js +29 -0
  37. package/containers/CreativesContainer/sagas.js +11 -0
  38. package/containers/CreativesContainer/selectors.js +30 -0
  39. package/containers/CreativesContainer/tests/actions.test.js +18 -0
  40. package/containers/CreativesContainer/tests/index.test.js +10 -0
  41. package/containers/CreativesContainer/tests/reducer.test.js +9 -0
  42. package/containers/CreativesContainer/tests/sagas.test.js +15 -0
  43. package/containers/CreativesContainer/tests/selectors.test.js +10 -0
  44. package/containers/EmailWrapper/actions.js +15 -0
  45. package/containers/EmailWrapper/constants.js +7 -0
  46. package/containers/EmailWrapper/index.js +238 -0
  47. package/containers/EmailWrapper/messages.js +57 -0
  48. package/containers/EmailWrapper/reducer.js +23 -0
  49. package/containers/EmailWrapper/sagas.js +11 -0
  50. package/containers/EmailWrapper/selectors.js +25 -0
  51. package/containers/EmailWrapper/tests/actions.test.js +18 -0
  52. package/containers/EmailWrapper/tests/index.test.js +10 -0
  53. package/containers/EmailWrapper/tests/reducer.test.js +9 -0
  54. package/containers/EmailWrapper/tests/sagas.test.js +15 -0
  55. package/containers/EmailWrapper/tests/selectors.test.js +10 -0
  56. package/containers/MobilePush/commonMethods.js +249 -0
  57. package/containers/MobilePush/eventsMap.js +127 -0
  58. package/containers/MobilePush/initialSchema.js +1739 -0
  59. package/containers/MobilepushWrapper/_mobilepushWrapper.scss +18 -0
  60. package/containers/MobilepushWrapper/index.js +97 -0
  61. package/containers/MobilepushWrapper/messages.js +25 -0
  62. package/containers/MobilepushWrapper/tests/index.test.js +10 -0
  63. package/containers/TemplatesV2/_templatesV2.scss +5 -0
  64. package/containers/TemplatesV2/actions.js +16 -0
  65. package/containers/TemplatesV2/constants.js +10 -0
  66. package/containers/TemplatesV2/index.js +207 -0
  67. package/containers/TemplatesV2/messages.js +29 -0
  68. package/containers/TemplatesV2/selectors.js +25 -0
  69. package/containers/TemplatesV2/tests/actions.test.js +18 -0
  70. package/containers/TemplatesV2/tests/index.test.js +10 -0
  71. package/containers/TemplatesV2/tests/reducer.test.js +9 -0
  72. package/containers/TemplatesV2/tests/sagas.test.js +15 -0
  73. package/containers/TemplatesV2/tests/selectors.test.js +10 -0
  74. package/containers/WeChat/RichmediaTemplates/Create/testschema.js +379 -0
  75. package/containers/WeChat/actions.js +6 -0
  76. package/containers/WeChat/index.js +31 -13
  77. package/package.json +1 -1
  78. package/v2Containers/MobilePush/Create/index.js +43 -9
  79. package/v2Containers/MobilePush/Create/messages.js +16 -0
  80. package/v2Containers/MobilePush/Edit/index.js +54 -22
  81. package/v2Containers/MobilePush/Edit/messages.js +17 -1
  82. package/v2Containers/MobilePush/commonMethods.js +9 -7
@@ -0,0 +1,1845 @@
1
+
2
+ /*
3
+ *
4
+ * Create
5
+ *
6
+ */
7
+
8
+ import PropTypes from 'prop-types';
9
+
10
+ import React from 'react';
11
+ import {bindActionCreators} from "redux";
12
+ import { connect } from 'react-redux';
13
+ import { Row, Col, Spin, Breadcrumb, notification } from 'antd';
14
+ import { createStructuredSelector } from 'reselect';
15
+ import { injectIntl, intlShape, FormattedMessage } from 'react-intl';
16
+ import _, {get, findIndex, set, forEach, cloneDeep} from 'lodash';
17
+ import { CapSlideBox, CapHeader, CapTable, CapLink, CapRow, CapColumn, CapIcons} from '@capillarytech/cap-ui-library';
18
+ import styled from 'styled-components';
19
+ import {makeSelectEdit, makeSelectEditResponse, makeSelectTemplateDetailsResponse, makeSelectIosCta} from "./selectors";
20
+ import {makeSelectMetaEntities} from "../../Cap/selectors";
21
+ import {getMessageObject} from "../../../utils/messageUtils";
22
+ import FormBuilder from '../../../components/FormBuilder';
23
+ import * as globalActions from "../../Cap/actions";
24
+ import * as actions from "../../MobilePush/Edit/actions";
25
+ import * as templatesActions from "../../Templates/actions";
26
+ import {makeSelectTemplates} from "../../Templates/selectors";
27
+ import messages from './messages';
28
+ import './_mobilePushCreate.scss';
29
+ import callNativeEvent from '../../../utils/callNativeEvent';
30
+ import {makeSelectCreate} from "../Create/selectors";
31
+
32
+ import getEventsMap from '../eventsMap';
33
+ import {getPrimaryCtaFields, getSecondaryCtaFields, getLinkTypeFields} from '../commonMethods';
34
+ const BreadcrumbItem = Breadcrumb.Item;
35
+
36
+ const PrefixWrapper = styled.div`
37
+ margin-right: 16px;
38
+ `;
39
+ export class Edit extends React.Component { // eslint-disable-line react/prefer-stateless-function
40
+ constructor(props) {
41
+ super(props);
42
+ const eventsMap = getEventsMap(this);
43
+ this.state = {
44
+ formData: {},
45
+ tabCount: 1,
46
+ schema: {},
47
+ currentTab: 1,
48
+ editData: {},
49
+ loading: false,
50
+ isFormValid: true,
51
+ injectedTags: {},
52
+ showModal: false,
53
+ eventsMap,
54
+ modalContent: {title: "Alert", body: this.props.intl.formatMessage(messages['template not configured,']), type: 'confirm'},
55
+ };
56
+ this.getPrimaryCtaFields = getPrimaryCtaFields.bind(this);
57
+ this.getSecondaryCtaFields = getSecondaryCtaFields.bind(this);
58
+ this.getLinkTypeFields = getLinkTypeFields.bind(this);
59
+ }
60
+ componentWillMount() {
61
+ console.log('edit mounting');
62
+ this.props.actions.getWeCrmAccounts("mobilepush");
63
+ if (!this.props.Templates.selectedWeChatAccount && this.props.location.query.type !== 'embedded') {
64
+ const type = this.props.location.query.type;
65
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
66
+ this.props.router.push({
67
+ pathname: `/mobilepush/`,
68
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
69
+ });
70
+ } else {
71
+ const query = {
72
+ layout: 'MOBILEPUSH',
73
+ type: 'LAYOUT',
74
+ version: "v2",
75
+ };
76
+ this.props.globalActions.fetchSchemaForEntity(query);
77
+ console.log(this.props.params);
78
+ }
79
+ }
80
+ componentDidMount() {
81
+ window.addEventListener("message", this.handleFrameTasks);
82
+ if (!_.isEmpty(this.state.schema)) {
83
+ this.injectEvents(this.state.schema);
84
+ }
85
+ if (this.props.location.query && (typeof this.props.location.query.module === 'undefined' || this.props.isFullMode === false)) { // when this containers is imported from creatives library
86
+ const templateId = get(this, "props.params.id");
87
+ if (templateId) {
88
+ this.props.actions.getTemplateDetails(templateId);
89
+ } else {
90
+ this.props.actions.setTemplateDetails(this.props.templateData);
91
+ }
92
+ }
93
+ }
94
+ componentWillReceiveProps(nextProps) {
95
+ if (nextProps.isGetFormData) {
96
+ nextProps.getFormLibraryData(this.getFormData());
97
+ }
98
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
99
+ if (this.props.location.query.type === 'embedded' && !nextProps.Edit.fetchingWeCrmAccounts && !_.isEqual(this.props.Edit.weCrmAccounts, nextProps.Edit.weCrmAccounts) && (!selectedWeChatAccount || _.isEmpty(selectedWeChatAccount))) {
100
+ console.log('got new accounts setting account again', nextProps.Edit.weCrmAccounts);
101
+ this.setMobilePushAccountOptions(nextProps.Edit.weCrmAccounts);
102
+ }
103
+ if (!_.isEmpty(nextProps.Edit.selectedWeChatAccount) && !_.isEqual(this.props.Edit.selectedWeChatAccount, nextProps.Edit.selectedWeChatAccount) && (this.props.location.query.type === 'embedded') && this.props.location.query.module === "loyalty") {
104
+ const params = {
105
+ name: '',
106
+ sortBy: 'Most Recent',
107
+ accountId: nextProps.Edit.selectedWeChatAccount.id,
108
+ };
109
+ this.props.actions.getMobilepushTemplatesList('mobilepush', params);
110
+ }
111
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && _.isEmpty(this.state.fullSchema)) {
112
+ this.setState({fullSchema: nextProps.metaEntities.layouts[0].definition, schema: (nextProps.location.query.module === 'loyalty') ? nextProps.metaEntities.layouts[0].definition.textSchema : {}}, () => {
113
+ const templateId = get(this, "props.params.id");
114
+ if (nextProps.location.query.module !== 'loyalty' && templateId && templateId !== 'temp') {
115
+ this.props.actions.getTemplateDetails(templateId);
116
+ }
117
+ const type = this.props.location.query.type;
118
+ if (type === 'embedded' && templateId === 'temp' && _.isEmpty(this.state.formData)) { // when his.props.params.id is temp that means mobile push template content will be passed from post message from parent with startTemplateCreation action
119
+ const response = {
120
+ action: 'startTemplateCreation',
121
+ };
122
+ parent.postMessage(JSON.stringify(response), '*');
123
+ this.getTags();
124
+ }
125
+ });
126
+ if (this.props.location.query.type === 'embedded') {
127
+ this.showNext();
128
+ }
129
+ }
130
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && nextProps.Edit.mobilepushTemplates && !_.isEqual(nextProps.Edit.mobilepushTemplates, this.props.Edit.mobilepushTemplates)) { //used inloyalty
131
+ if (nextProps.location.query.type === 'embedded' && nextProps.location.query.module === 'loyalty') {
132
+ this.setTemplateOptions(nextProps.Edit.mobilepushTemplates);
133
+ }
134
+ }
135
+ if (!_.isEmpty(nextProps.templateDetails) && _.isEmpty(this.state.editData) && !_.isEmpty(this.state.fullSchema) && selectedWeChatAccount && (this.props.location.query.type !== 'embedded' || this.props.isFullMode === false)) {
136
+ this.props = nextProps;
137
+ const mode = nextProps.templateDetails.definition ? nextProps.templateDetails.definition.mode : nextProps.templateDetails.mode;
138
+ const schema = mode === "text" ? this.state.fullSchema.textSchema : this.state.fullSchema.imageSchema;
139
+ const isAndroidSupported = get(this, "props.Templates.selectedWeChatAccount.configs.android") === '1';
140
+ const isIosSupported = get(this, "props.Templates.selectedWeChatAccount.configs.ios") === '1';
141
+ if (!isAndroidSupported) {
142
+ const androidField = get(schema, "containers[0].panes[0]");
143
+ androidField.isSupported = false;
144
+ this.setState({currentTab: 2});
145
+ set(schema, "containers[0].panes[0]", androidField);
146
+ }
147
+ if (!isIosSupported) {
148
+ const iosField = get(schema, "containers[0].panes[1]");
149
+ iosField.isSupported = false;
150
+
151
+ set(schema, "containers[0].panes[1]", iosField);
152
+ }
153
+ this.setEditState(nextProps.templateDetails, schema);
154
+ this.getTags();
155
+ }
156
+ if (nextProps.Edit.uploadedAssetData) {
157
+ const formData = _.cloneDeep(this.state.formData);
158
+ formData[this.state.currentTab - 1].image = nextProps.Edit.uploadedAssetData.metaInfo.public_url;
159
+ this.setState({formData});
160
+ this.props.actions.clearAsset();
161
+ }
162
+ if (nextProps.iosCtasData) {
163
+ this.setState({showIosCtaTable: true});
164
+ }
165
+ if (nextProps.Edit.editResponse && nextProps.Edit.editResponse.templateId) {
166
+ console.log('reseting schema');
167
+ this.resetSchema();
168
+ this.setState({
169
+ formData: {},
170
+ tabCount: 1,
171
+ currentTab: 1,
172
+ editData: {},
173
+ });
174
+ const message = getMessageObject('success', this.props.intl.formatMessage(messages['MOBILEPUSH Template Edited Successfully']), true);
175
+ this.props.globalActions.addMessageToQueue(message);
176
+ this.props.actions.clearEditResponse();
177
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
178
+ const type = this.props.location.query.type;
179
+ this.props.router.push({
180
+ pathname: `/mobilepush/`,
181
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
182
+ });
183
+ }
184
+
185
+ if (nextProps.Edit.editTemplateError && !_.isEqual(nextProps.Edit.editTemplateError, this.props.Edit.editTemplateError)) {
186
+ const message = getMessageObject('error', (nextProps.Edit.editTemplateErrorMessage && nextProps.Edit.editTemplateErrorMessage !== '') ? nextProps.Edit.editTemplateErrorMessage : this.props.intl.formatMessage(messages.somethingWentWrong), true);
187
+ this.props.globalActions.addMessageToQueue(message);
188
+ }
189
+ // if (nextProps.metaEntities && nextProps.metaEntities.tags && nextProps.metaEntities.tags.custom && this.props.metaEntities.tags !== nextProps.metaEntities.tags) {
190
+ // let injectedTags = _.cloneDeep(this.state.injectedTags);
191
+ // injectedTags = _.merge({}, injectedTags, nextProps.metaEntities.tags.custom);
192
+ // this.setState({injectedTags});
193
+ // }
194
+ if (nextProps.metaEntities && nextProps.metaEntities.tags && nextProps.metaEntities.tags.custom && !_.isEqual(this.props.metaEntities.tags, nextProps.metaEntities.tags)) {
195
+ let injectedTags = _.cloneDeep(this.state.injectedTags);
196
+ delete injectedTags["Registration custom fields"];
197
+ delete injectedTags["Store custom fields"];
198
+ delete injectedTags["Transaction custom fields"];
199
+ injectedTags = _.merge({}, injectedTags, nextProps.metaEntities.tags.custom);
200
+ console.log('new injected tags', nextProps.metaEntities.tags.custom);
201
+ if (!_.has(nextProps.metaEntities.tags.custom, "Registration custom fields")) {
202
+ delete injectedTags["Registration custom fields"];
203
+ }
204
+ if (!_.has(nextProps.metaEntities.tags.custom, "Store custom fields")) {
205
+ delete injectedTags["Store custom fields"];
206
+ }
207
+ if (!_.has(nextProps.metaEntities.tags.custom, "Transaction custom fields")) {
208
+ delete injectedTags["Transaction custom fields"];
209
+ }
210
+ this.setState({injectedTags});
211
+ }
212
+ }
213
+ componentWillUnmount() {
214
+ this.props.actions.clearData();
215
+ window.removeEventListener("message", this.handleFrameTasks);
216
+ }
217
+ onTemplateChange = (isEvent, formData) => {
218
+ _.forEach(this.props.Edit.mobilepushTemplates, (template) => {
219
+ if (template._id === formData['mobilepush-template']) {
220
+ this.setState({editData: {}, formData: {}}, () => {
221
+ this.props.actions.setSelectedTemplate(template);
222
+ });
223
+ }
224
+ });
225
+ };
226
+ onFormDataChange = (formData, tabCount, currentTab) => {
227
+ console.log('Form data changed is ', formData, tabCount, currentTab);
228
+ const newFormData = _.cloneDeep(formData);
229
+ const {templateCta} = this.state;
230
+ if (!_.isEmpty(templateCta)) {
231
+ newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-label`] = templateCta.name;
232
+ newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action`] = templateCta.ctaTemplateDetails[0].buttonText;
233
+ delete newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action2`];
234
+ if (templateCta.ctaTemplateDetails[1]) {
235
+ newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action2`] = templateCta.ctaTemplateDetails[1].buttonText;
236
+ }
237
+ }
238
+ if (newFormData["mobilepush-accounts"] !== this.state.formData["mobilepush-accounts"]) {
239
+ this.setMobilePushAccountOptions(this.props.Edit.weCrmAccounts, newFormData["mobilepush-accounts"]);
240
+ delete newFormData['mobilepush-template'];
241
+ delete newFormData['template-name'];
242
+ if (!_.isEmpty(newFormData[0])) {
243
+ delete newFormData[0];
244
+ }
245
+ if (!_.isEmpty(newFormData[1])) {
246
+ delete newFormData[1];
247
+ }
248
+ }
249
+ if (this.state.isSchemaChanged) {
250
+ this.setState({isSchemaChanged: false});
251
+ }
252
+ this.setState({formData: newFormData, tabCount});
253
+ if (currentTab) {
254
+ this.setState({currentTab});
255
+ }
256
+ };
257
+
258
+ onLinkTypeChange = (eventTriggered, formData, field, currentTab, inputSchema) => {
259
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
260
+ const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
261
+ const tabIndex = currentTab || this.state.currentTab;
262
+ const inputFields = get(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`);
263
+ const id = field.id;
264
+ const fieldIndex = findIndex(inputFields, {identifier: id});
265
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
266
+ const deepLinkOptions = _.map(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (link) => ({label: link.name, value: link.link, title: link.link }) );
267
+ // let inputId = deeplinkValue && deeplinkValue.toLowerCase() === "deeplink" ? `${id}-select` : `${id}-text`;
268
+ // if (field.id === "cta-deeplink-secondary-cta-1" && (tabIndex > 1 || this.state.currentTab > 1)) {
269
+ // inputId = `${inputId}${tabIndex || this.state.currentTab}`;
270
+ // }
271
+ const newInputFields = this.getLinkTypeFields({inputFieldsArgs: inputFields, fieldIndex, deepLinkOptions, formData, field});
272
+ set(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
273
+
274
+ if (currentTab) { // identifying where ist called from setEditData or by event handler
275
+ return schema;
276
+ }
277
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true});
278
+ this.injectEvents(schema);
279
+ return schema;
280
+ };
281
+
282
+ onTabChange = (data) => {
283
+ console.log('inside parent ontabchange', data, this.state);
284
+ this.setState({currentTab: data});
285
+ };
286
+
287
+ onTagSelect = (data, currentTab, srcComp) => {
288
+ console.log('parent data tag', data, currentTab);
289
+ const editorId = srcComp.target;
290
+ this.insertAtCursor(document.getElementById(editorId), `{{${data}}}`);
291
+ document.getElementById(editorId).focus();
292
+ };
293
+ onModalCancel = () => {
294
+ if (this.state.modalContent && this.state.modalContent.show) {
295
+ this.setState({modalContent: {...this.state.modalContent, show: false}});
296
+ }
297
+ };
298
+ getTags = () => {
299
+ const query = {
300
+ layout: 'mobilepush',
301
+ type: 'TAG',
302
+ context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
303
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
304
+ };
305
+ if (this.props.getDefaultTags) {
306
+ query.context = this.props.getDefaultTags;
307
+ }
308
+ this.props.globalActions.fetchSchemaForEntity(query);
309
+ }
310
+ setTemplateOptions = (mobilepushTemplates) => {
311
+ const templateOptions = [];
312
+ let selectedTemplate = {};
313
+ if (!_.isEmpty(mobilepushTemplates)) {
314
+ _.forEach(mobilepushTemplates, (template) => {
315
+ templateOptions.push({
316
+ key: template._id,
317
+ label: template.name,
318
+ value: template._id,
319
+ });
320
+ if (this.state.formData['mobilepush-template'] && template._id === this.state.formData['mobilepush-template']) {
321
+ selectedTemplate = template;
322
+ }
323
+ });
324
+ }
325
+ this.setState({templateOptions}, () => {
326
+ if (!_.isEmpty(selectedTemplate)) {
327
+ this.props.actions.setSelectedTemplate(selectedTemplate);
328
+ }
329
+ if (!_.isEmpty(this.state.schema)) {
330
+ this.injectEvents(this.state.schema);
331
+ }
332
+ });
333
+ };
334
+ setMobilePushAccountOptions = (accounts, newAccountId) => {
335
+ let accId = newAccountId || this.props.location.query.account_id;
336
+ if (this.props.location.query.module !== "loyalty" && this.props.location.query.module !== "dvs") {
337
+ accId = Number(accId);
338
+ }
339
+ const formData = _.cloneDeep(this.state.formData);
340
+ let selectedAccount = {};
341
+ if (accId) {
342
+ _.forEach(accounts, (account) => {
343
+ let acccountId = account.id;
344
+ if ((this.props.location.query.module === "loyalty" || this.props.location.query.module === "dvs") && typeof accId === 'string') {
345
+ acccountId = account.sourceAccountIdentifier;
346
+ }
347
+ if (acccountId === accId) {
348
+ this.props.templatesActions.setWeChatAccount(account);
349
+ selectedAccount = account;
350
+ formData['mobilepush-accounts'] = account.id;
351
+ if (this.props.location.query.account_id) {
352
+ formData['mobilepush-template'] = this.props.params.id;
353
+ }
354
+ }
355
+ });
356
+ } else {
357
+ selectedAccount = accounts[0];
358
+ formData['mobilepush-accounts'] = accounts[0].id;
359
+ }
360
+ this.props.actions.setWeChatAccount(selectedAccount);
361
+ this.setState({formData, accountsOptions: accounts.map((acc) => ({key: acc.id, label: acc.name, value: acc.id}))});
362
+ };
363
+
364
+ getTransformedData = (formData) => {
365
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
366
+ const obj = _.cloneDeep(this.state.editData);
367
+ obj.versions = {
368
+ base: {},
369
+ };
370
+ obj.type = 'MOBILEPUSH';
371
+ obj.name = formData['template-name'];
372
+ obj.definition = {
373
+ accountId: selectedWeChatAccount.id,
374
+ licenseCode: selectedWeChatAccount.sourceAccountIdentifier,
375
+ };
376
+ if (this.props.location.query && this.props.location.query.module !== 'dvs') {
377
+ obj.definition.mode = this.props.Edit.templateDetails.mode || get(this, 'props.Edit.templateDetails.definition.mode');
378
+ }
379
+ const android = {};
380
+ Object.keys(formData[0]).forEach((data) => {
381
+ if (!!formData[0][data] && data !== "tabKey") {
382
+ android[data] = formData[0][data];
383
+ }
384
+ });
385
+ const ios = {};
386
+ Object.keys(formData[1]).forEach((data) => {
387
+ if (!!formData[1][data] && data !== "tabKey") {
388
+ ios[data] = formData[1][data];
389
+ }
390
+ });
391
+ obj.versions.base = {};
392
+ delete android.base;
393
+ if (!_.isEmpty(android)) {
394
+ obj.versions.base.ANDROID = {
395
+ luid: "{{luid}}",
396
+ cuid: "{{cuid}}",
397
+ communicationId: "{{communicationId}}",
398
+ title: android['message-title'],
399
+ message: android['message-editor'],
400
+ expandableDetails: {
401
+ style: "BIG_TEXT",
402
+ message: android['message-editor'],
403
+ },
404
+ custom: _.map(android, (field, key) => {
405
+ if (key.indexOf('custom-value') > -1) {
406
+ 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;
407
+ }
408
+ return undefined;
409
+ }).filter((custom) => custom),
410
+ };
411
+ }
412
+ if (android['cta-deeplink'] && android['cta-deeplink'] !== "") {
413
+ obj.versions.base.ANDROID.cta = {
414
+ type: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
415
+ actionLink: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? android['cta-deeplink-select'] : android['cta-deeplink-text'],
416
+ deepLinkName: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? this.getLinkName(android['cta-deeplink-select']) : undefined,
417
+ };
418
+ if (this.props.location.query.type === 'embedded') {
419
+ delete obj.versions.base.ANDROID.cta.deepLinkName;
420
+ }
421
+ }
422
+ if (!_.isEmpty(ios)) {
423
+ obj.versions.base.IOS = {
424
+ luid: "{{luid}}",
425
+ cuid: "{{cuid}}",
426
+ communicationId: "{{communicationId}}",
427
+ title: ios['message-title2'],
428
+ message: ios['message-editor2'],
429
+ expandableDetails: {
430
+ style: "BIG_TEXT",
431
+ message: ios['message-title2'],
432
+ ctas: [
433
+
434
+ ],
435
+ categoryId: ios['secondary-cta-1-table'] ? ios['secondary-cta-1-table'].id : undefined,
436
+ },
437
+ custom: _.map(ios, (field, key) => {
438
+ if (key.indexOf('custom-value') > -1) {
439
+ 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;
440
+ }
441
+ return undefined;
442
+ }).filter((custom) => custom),
443
+ };
444
+ }
445
+ if (ios['cta-deeplink2'] && ios['cta-deeplink2'] !== "") {
446
+ obj.versions.base.IOS.cta = {
447
+ type: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
448
+ actionLink: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? ios['cta-deeplink2-select'] : ios['cta-deeplink2-text'],
449
+ deepLinkName: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? this.getLinkName(ios['cta-deeplink2-select']) : undefined,
450
+ };
451
+ if (this.props.location.query.type === 'embedded') {
452
+ delete obj.versions.base.IOS.cta.deepLinkName;
453
+ }
454
+ }
455
+ const imageLink = android.image;
456
+ if (imageLink) {
457
+ obj.versions.base.ANDROID.expandableDetails.image = imageLink;
458
+ obj.versions.base.ANDROID.expandableDetails.style = "BIG_PICTURE";
459
+ }
460
+ if (obj.versions.base.ANDROID && obj.versions.base.ANDROID.cta) {
461
+ if (obj.versions.base.ANDROID.cta.type === "DEEP_LINK") {
462
+ const params = _.map(android, (field, key) => {
463
+ let actionLink;
464
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-select') > -1) {
465
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-select', '');
466
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
467
+ }
468
+ return actionLink;
469
+ }).filter((actionLink) => actionLink);
470
+ if (params.length) {
471
+ obj.versions.base.ANDROID.cta.actionLink = `${obj.versions.base.ANDROID.cta.actionLink}?${params.join('&')}`;
472
+ }
473
+ }
474
+ }
475
+ const secondaryCta1 = !!android["cta-deeplink-secondary-cta-0-select"] || !!android['secondary-cta-0-label'];
476
+ const secondaryCta2 = !!android['cta-deeplink-secondary-cta-1-select'] || !!android['secondary-cta-1-label'];
477
+ if (secondaryCta1 || secondaryCta2 ) {
478
+ obj.versions.base.ANDROID.expandableDetails.ctas = [];
479
+ if (secondaryCta1) {
480
+ const cta = {
481
+ actionText: android['secondary-cta-0-label'],
482
+ type: android['cta-deeplink-secondary-cta-0'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
483
+ actionLink: android['cta-deeplink-secondary-cta-0'].toLowerCase() === "deeplink" ? android['cta-deeplink-secondary-cta-0-select'] : android['cta-deeplink-secondary-cta-0-text'],
484
+ seccdeepLinkName: this.getLinkName(android['cta-deeplink-secondary-cta-0-select']),
485
+ };
486
+ if (this.props.location.query.type === 'embedded') {
487
+ delete cta.seccdeepLinkName;
488
+ }
489
+ obj.versions.base.ANDROID.expandableDetails.ctas.push(cta);
490
+ if (obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
491
+ const params = _.map(android, (field, key) => {
492
+ let actionLink;
493
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-0-select') > -1) {
494
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-0-select', '');
495
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
496
+ }
497
+ return actionLink;
498
+ }).filter((actionLink) => actionLink);
499
+ if (params.length) {
500
+ 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('&')}`;
501
+ }
502
+ }
503
+ }
504
+ if (secondaryCta2) {
505
+ obj.versions.base.ANDROID.expandableDetails.ctas.push({
506
+ actionText: android['secondary-cta-1-label'],
507
+ type: android['cta-deeplink-secondary-cta-1'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
508
+ actionLink: android['cta-deeplink-secondary-cta-1'].toLowerCase() === "deeplink" ? android['cta-deeplink-secondary-cta-1-select'] : android['cta-deeplink-secondary-cta-1-text'],
509
+ seccdeepLinkName: this.getLinkName(android['cta-deeplink-secondary-cta-1-select']),
510
+ });
511
+ if (obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
512
+ const params = _.map(android, (field, key) => {
513
+ let actionLink;
514
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-1-select') > -1) {
515
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-1-select', '');
516
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
517
+ }
518
+ return actionLink;
519
+ }).filter((actionLink) => actionLink);
520
+ if (params.length) {
521
+ 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('&')}`;
522
+ }
523
+ }
524
+ }
525
+ }
526
+ const imageLinkIos = ios.image;
527
+ if (imageLinkIos) {
528
+ obj.versions.base.IOS.expandableDetails.image = imageLinkIos;
529
+ obj.versions.base.IOS.expandableDetails.style = "BIG_PICTURE";
530
+ }
531
+ if (obj.versions.base.IOS && obj.versions.base.IOS.cta) {
532
+ if (obj.versions.base.IOS.cta.type === "DEEP_LINK") {
533
+ const params = _.map(ios, (field, key) => {
534
+ let actionLink;
535
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink2-select') > -1) {
536
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink2-select', '');
537
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
538
+ }
539
+ return actionLink;
540
+ }).filter((actionLink) => actionLink);
541
+ if (params.length) {
542
+ obj.versions.base.IOS.cta.actionLink = `${obj.versions.base.IOS.cta.actionLink}?${params.join('&')}`;
543
+ }
544
+ }
545
+ }
546
+ const secondaryCtaIos = !!ios['cta-deeplink-secondary-cta-1-select'] || !!ios['secondary-cta-1-label'];
547
+
548
+ if (secondaryCtaIos) {
549
+ obj.versions.base.IOS.expandableDetails.ctas = [];
550
+ const templateCtaId = get(this.state, "templateCta.ctaTemplateDetails[0].id");
551
+
552
+ const cta = {
553
+ actionText: ios['secondary-cta-1-label'],
554
+ actionLabel: ios['secondary-cta-1-action'],
555
+ actionLabel2: ios['secondary-cta-1-action2'],
556
+ type: ios['cta-deeplink-secondary-cta-1'] && (ios['cta-deeplink-secondary-cta-1'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL"),
557
+ 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-text2']),
558
+ ioscdeepLinkName: this.getLinkName(ios['cta-deeplink-secondary-cta-1-select']),
559
+ templateCtaId,
560
+ };
561
+ if (this.props.location.query.type === 'embedded') {
562
+ delete cta.ioscdeepLinkName;
563
+ }
564
+ obj.versions.base.IOS.expandableDetails.ctas.push(cta);
565
+ if (obj.versions.base.IOS.expandableDetails.ctas[obj.versions.base.IOS.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
566
+ const params = _.map(ios, (field, key) => {
567
+ let actionLink;
568
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-1-select') > -1) {
569
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-1-select2', '');
570
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
571
+ }
572
+ return actionLink;
573
+ }).filter((actionLink) => actionLink);
574
+ if (params.length) {
575
+ 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('&')}`;
576
+ }
577
+ }
578
+ }
579
+ return obj;
580
+ };
581
+
582
+ getLinkName = (link) => {
583
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
584
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
585
+ const deepLinkOptions = _.filter(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (l) => l.link === link);
586
+ if (deepLinkOptions[0]) {
587
+ return deepLinkOptions[0].name;
588
+ }
589
+ return undefined;
590
+ };
591
+
592
+ setFormValidity = (isFormValid) => {
593
+ this.setState({isFormValid});
594
+ };
595
+
596
+ getMappedEvent = (id, event) => {
597
+ const map = this.state.eventsMap;
598
+ if (!map[id] || !map[id][event]) {
599
+ console.log(`error map[id] ${map[id]} ${id} ${event}` );
600
+ }
601
+ return map[id][event];
602
+ };
603
+
604
+ getCurrentWindow = (e) => {
605
+ console.log('in sms create', e);
606
+ const response = {
607
+ action: e.action,
608
+ value: 'edit',
609
+ direction: e.value,
610
+ };
611
+ parent.postMessage(JSON.stringify(response), '*');
612
+ };
613
+
614
+ getFormData = (e) => {
615
+ console.log('posting final result', this.state.formData);
616
+ const response = {
617
+ action: "getFormData",
618
+ value: this.getTransformedData(this.state.formData),
619
+ validity: this.state.isFormValid,
620
+ };
621
+ console.log('GetForm Data ', response);
622
+ this.setState({checkValidation: true});
623
+ if (e) {
624
+ e.source.postMessage(JSON.stringify(response), e.origin);
625
+ }
626
+ return response;
627
+ };
628
+
629
+
630
+ setEditState(data, schema) {
631
+ console.log('Test 1234', data, schema);
632
+ const tabCount = Object.keys(data.versions.base).length;
633
+ const formData = {};
634
+ if (this.props.location.query.type === 'embedded' && this.props.location.query.module === "loyalty") {
635
+ formData["mobilepush-accounts"] = this.state.formData["mobilepush-accounts"];
636
+ formData['mobilepush-template'] = this.state.formData['mobilepush-template'];
637
+ }
638
+ formData['template-name'] = data.name;
639
+ const androidData = data.versions.base.ANDROID;
640
+ const iosData = data.versions.base.IOS;
641
+ const android = {};
642
+ android[`message-title`] = androidData ? androidData.title : '';
643
+ android['message-editor'] = androidData ? androidData.message : '';
644
+ if (data.mode === "image") {
645
+ android.image = "";
646
+ }
647
+ if (androidData) {
648
+ if (androidData.cta) {
649
+ android['cta-deeplink'] = androidData.cta.type === "DEEP_LINK" ? "Deeplink" : "External Link";
650
+ if ( androidData.cta.type === "DEEP_LINK") {
651
+ android['cta-deeplink-select'] = androidData ? androidData.cta.actionLink : '';
652
+ } else {
653
+ android['cta-deeplink-text'] = androidData ? androidData.cta.actionLink : '';
654
+ }
655
+ if (androidData.cta.type === "DEEP_LINK" ) {
656
+ const link = android['cta-deeplink-select'].split('?')[0];
657
+ const params = android['cta-deeplink-select'].split('?')[1] && android['cta-deeplink-select'].split('?')[1].split('&');
658
+ android['cta-deeplink-select'] = link;
659
+ _.forEach(params, (param) => {
660
+ android[`custom-value-${param.split('=')[0]}-cta-deeplink-select`] = param.split('=')[1];
661
+ });
662
+ }
663
+ }
664
+ if (androidData.expandableDetails && androidData.expandableDetails.image) {
665
+ android.image = androidData.expandableDetails.image;
666
+ }
667
+ if (androidData.expandableDetails && androidData.expandableDetails.ctas && androidData.expandableDetails.ctas.length) {
668
+ android['cta-deeplink-secondary-cta-0'] = androidData.expandableDetails.ctas[0].type === "DEEP_LINK" ? "Deeplink" : "External Link";
669
+ if ( androidData.expandableDetails.ctas[0].type === "DEEP_LINK") {
670
+ android['cta-deeplink-secondary-cta-0-select'] = androidData.expandableDetails.ctas[0].actionLink;
671
+ } else {
672
+ android['cta-deeplink-secondary-cta-0-text'] = androidData.expandableDetails.ctas[0].actionLink;
673
+ }
674
+ android['secondary-cta-0-label'] = androidData.expandableDetails.ctas[0].actionText;
675
+ if (androidData.expandableDetails.ctas[0].type === "DEEP_LINK") {
676
+ const link = android['cta-deeplink-secondary-cta-0-select'].split('?')[0];
677
+ const params = android['cta-deeplink-secondary-cta-0-select'].split('?')[1] && android['cta-deeplink-secondary-cta-0-select'].split('?')[1].split('&');
678
+ android['cta-deeplink-secondary-cta-0-select'] = link;
679
+ _.forEach(params, (param) => {
680
+ android[`custom-value-${param.split('=')[0]}-cta-deeplink-secondary-cta-0-select`] = param.split('=')[1];
681
+ });
682
+ }
683
+ }
684
+ if (androidData.expandableDetails && androidData.expandableDetails.ctas && androidData.expandableDetails.ctas.length > 1) {
685
+ android['cta-deeplink-secondary-cta-1'] = androidData.expandableDetails.ctas[1].type === "DEEP_LINK" ? "Deeplink" : "External Link";
686
+ if (androidData.expandableDetails.ctas[1].type === "DEEP_LINK") {
687
+ android['cta-deeplink-secondary-cta-1-select'] = androidData.expandableDetails.ctas[1].actionLink;
688
+ } else {
689
+ android['cta-deeplink-secondary-cta-1-text'] = androidData.expandableDetails.ctas[1].actionLink;
690
+ }
691
+ android['secondary-cta-1-label'] = androidData.expandableDetails.ctas[1].actionText;
692
+ if (androidData.expandableDetails.ctas[1].type === "DEEP_LINK" && android['cta-deeplink-secondary-cta-1-select']) {
693
+ const link = android['cta-deeplink-secondary-cta-1-select'].split('?')[0];
694
+ const params = android['cta-deeplink-secondary-cta-1-select'].split('?')[1] && android['cta-deeplink-secondary-cta-1-select'].split('?')[1].split('&');
695
+ android['cta-deeplink-secondary-cta-1-select'] = link;
696
+ _.forEach(params, (param) => {
697
+ android[`custom-value-${param.split('=')[0]}-cta-deeplink-secondary-cta-1-select`] = param.split('=')[1];
698
+ });
699
+ }
700
+ }
701
+ }
702
+ formData[0] = android;
703
+ const ios = {};
704
+ const templateCta = {};
705
+ ios[`message-title2`] = iosData ? iosData.title : '';
706
+ ios['message-editor2'] = iosData ? iosData.message : '';
707
+ if (data.mode === "image") {
708
+ ios.image = "";
709
+ }
710
+ if (iosData) {
711
+ if (iosData.cta) {
712
+ ios['cta-deeplink2'] = iosData.cta.type === "DEEP_LINK" ? "Deeplink" : "External Link";
713
+ if (iosData.cta.type === "DEEP_LINK") {
714
+ ios['cta-deeplink2-select'] = iosData ? iosData.cta.actionLink : '';
715
+ } else {
716
+ ios['cta-deeplink2-text'] = iosData ? iosData.cta.actionLink : '';
717
+ }
718
+ if (iosData.cta.type === "DEEP_LINK") {
719
+ const link = ios['cta-deeplink2-select'].split('?')[0];
720
+ let params = ios['cta-deeplink2-select'].split('?');
721
+ if (params[1]) {
722
+ params = params[1].split('&');
723
+ _.forEach(params, (param) => {
724
+ ios[`custom-value-${param.split('=')[0]}-cta-deeplink2-select`] = param.split('=')[1];
725
+ });
726
+ }
727
+ ios['cta-deeplink2-select'] = link;
728
+ }
729
+ }
730
+ if (iosData.expandableDetails && iosData.expandableDetails.image) {
731
+ ios.image = iosData.expandableDetails.image;
732
+ }
733
+ if (iosData.expandableDetails && iosData.expandableDetails.ctas && iosData.expandableDetails.ctas.length) {
734
+ if (iosData.expandableDetails.ctas[0].type) {
735
+ ios['cta-deeplink-secondary-cta-1'] = iosData.expandableDetails.ctas[0].type === "DEEP_LINK" ? "Deeplink" : "External Link";
736
+ }
737
+ if (iosData.expandableDetails.ctas[0].type === "DEEP_LINK") {
738
+ ios['cta-deeplink-secondary-cta-1-select2'] = iosData.expandableDetails.ctas[0].actionLink;
739
+ } else {
740
+ ios['cta-deeplink-secondary-cta-1-text2'] = iosData.expandableDetails.ctas[0].actionLink;
741
+ }
742
+ ios['secondary-cta-1-label'] = iosData.expandableDetails.ctas[0].actionText;
743
+ if (iosData.expandableDetails.ctas[0].type === "DEEP_LINK" && ios['cta-deeplink-secondary-cta-1-select2']) {
744
+ const link = ios['cta-deeplink-secondary-cta-1-select2'].split('?')[0];
745
+ const paramsIos = ios['cta-deeplink-secondary-cta-1-select2'].split('?')[1] && ios['cta-deeplink-secondary-cta-1-select2'].split('?')[1].split('&');
746
+ ios['cta-deeplink-secondary-cta-1-select2'] = link;
747
+ _.forEach(paramsIos, (param) => {
748
+ ios[`custom-value-${param.split('=')[0]}-cta-deeplink-secondary-cta-1-select2`] = param.split('=')[1];
749
+ });
750
+ }
751
+ set(templateCta, "ctaTemplateDetails[0].buttonText", iosData.expandableDetails.ctas[0].actionLabel);
752
+ set(templateCta, "name", iosData.expandableDetails.ctas[0].actionText);
753
+ set(templateCta, "ctaTemplateDetails[0].id", iosData.expandableDetails.ctas[0].templateCtaId);
754
+ ios['secondary-cta-1-action'] = iosData.expandableDetails.ctas[0].actionLabel;
755
+ if (iosData.expandableDetails.ctas[0].actionLabel2) {
756
+ set(templateCta, "ctaTemplateDetails[1].buttonText", iosData.expandableDetails.ctas[0].actionLabel2);
757
+ ios['secondary-cta-1-action2'] = iosData.expandableDetails.ctas[0].actionLabel2;
758
+ }
759
+ }
760
+ }
761
+ formData[1] = ios;
762
+ formData.base = formData[0];
763
+ formData[0].base = true;
764
+ // formData[0].tabKey = '1';
765
+ // formData[1].tabKey = '2';
766
+ console.log('form data after discarding ', formData);
767
+ this.setState({templateCta}, () => {
768
+ this.getSchemaForFormData(formData, schema);
769
+ this.setState({tabCount, formData, editData: data, currentTab: 1});
770
+ });
771
+ }
772
+
773
+ getSchemaForFormData = (formdata, inputSchema) => {
774
+ let schema = inputSchema;
775
+ const formData = _.cloneDeep(formdata);
776
+ if (!_.isEmpty(formData[0])) {
777
+ if (formData[0]['cta-deeplink']) {
778
+ formData[0]['add-pri-cta'] = true;
779
+ schema = this.addPrimaryCta(null, formData, {id: 'add-pri-cta'}, schema, 1);
780
+ schema = this.onLinkTypeChange(true, formData, {id: 'cta-deeplink'}, 1, schema);
781
+ schema = this.showCtaKeys(true, formData, {id: 'cta-deeplink-select'}, 1, schema);
782
+ }
783
+ if (formData[0]['cta-deeplink-secondary-cta-0']) {
784
+ formData[0]['add-sec-cta'] = true;
785
+ schema = this.addSecondoryCta(null, formData, {id: 'add-sec-cta'}, schema, 1);
786
+ schema = this.onLinkTypeChange(true, formData, {id: 'cta-deeplink-secondary-cta-0'}, 1, schema);
787
+ schema = this.showCtaKeys(true, formData, {id: 'cta-deeplink-secondary-cta-0-select'}, 1, schema);
788
+ }
789
+ if (formData[0]['cta-deeplink-secondary-cta-1']) {
790
+ formData[0]['add-sec-cta-2'] = true;
791
+ schema = this.addSecondoryCta(null, formData, {id: 'add-sec-cta-2'}, schema, 1);
792
+ schema = this.onLinkTypeChange(true, formData, {id: 'cta-deeplink-secondary-cta-1'}, 1, schema);
793
+ schema = this.showCtaKeys(true, formData, {id: 'cta-deeplink-secondary-cta-1-select'}, 1, schema);
794
+ }
795
+ }
796
+ if (!_.isEmpty(formData[1])) {
797
+ if (formData[1]['cta-deeplink2']) {
798
+ formData[1]['add-pri-cta-ios'] = true;
799
+ schema = this.addPrimaryCta(null, formData, {id: 'add-pri-cta-ios'}, schema, 2);
800
+ schema = this.onLinkTypeChange(true, formData, {id: 'cta-deeplink2'}, 2, schema);
801
+ schema = this.showCtaKeys(true, formData, {id: 'cta-deeplink2-select'}, 2, schema);
802
+ }
803
+ if (formData[1]['secondary-cta-1-action']) {
804
+ formData[1]['add-sec-cta-ios'] = true;
805
+
806
+ schema = this.showSelectedIosCta(schema, {id: 'add-sec-cta-ios'}, 2, undefined, formData[1]['cta-deeplink-secondary-cta-1']);
807
+ schema = this.onLinkTypeChange(true, formData, {id: 'cta-deeplink-secondary-cta-1'}, 2, schema);
808
+ schema = this.showCtaKeys(true, formData, {id: 'cta-deeplink-secondary-cta-1-select2'}, 2, schema);
809
+ }
810
+ }
811
+ this.setState({schema, isSchemaChanged: true, formData});
812
+ this.injectEvents(schema);
813
+ };
814
+
815
+ setModalContent = (type) => {
816
+ if (type === 'ios') {
817
+ const modalContent = {
818
+ title: "Alert",
819
+ body: "Android template is not configured. Save without Android template",
820
+ type: 'confirm',
821
+ id: 'ios',
822
+ };
823
+ this.setState({modalContent, showModal: true});
824
+ } else if (type === 'android') {
825
+ const modalContent = {
826
+ title: "Alert",
827
+ body: "IOS template is not configured, Save without IOS template",
828
+ type: 'confirm',
829
+ id: 'android',
830
+ };
831
+ this.setState({modalContent, showModal: true});
832
+ }
833
+ }
834
+
835
+ openNotificationWithIcon = (type, message) => {
836
+ const dur = (type === 'error' || type === 'warning') ? null : 5;
837
+ notification[type]({
838
+ message: (`${type.toUpperCase()} ! ! ! `),
839
+ description: message, //'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
840
+ duration: dur,
841
+ });
842
+ }
843
+
844
+ handleCancelModal = () => {
845
+ this.setState({showModal: false});
846
+ };
847
+
848
+ insertAtCursor = (field, myValue) => {
849
+ //IE support
850
+ const myField = field;
851
+ if (document.selection) {
852
+ myField.focus();
853
+ const sel = document.selection.createRange();
854
+ sel.text = myValue;
855
+ } else if (myField.selectionStart || myField.selectionStart === '0') { //MOZILLA and others
856
+ const startPos = myField.selectionStart;
857
+ const endPos = myField.selectionEnd;
858
+ myField.value = myField.value.substring(0, startPos)
859
+ + myValue
860
+ + myField.value.substring(endPos, myField.value.length);
861
+ myField.selectionStart = startPos + myValue.length;
862
+ myField.selectionEnd = startPos + myValue.length;
863
+ } else {
864
+ myField.value += myValue;
865
+ }
866
+ const event = new Event('input', { bubbles: true });
867
+ callNativeEvent({field, value: myField.value, event});
868
+ };
869
+
870
+ selectCtaIos = (selectedConfig) => {
871
+ this.showSelectedIosCta(null, null, null, selectedConfig);
872
+ };
873
+
874
+ uploadImage = (data) => {
875
+ if (data.fileParams.error) {
876
+ const message = getMessageObject('error', this.props.intl.formatMessage(messages['File size cannot be more than 5mb']), true);
877
+ this.props.globalActions.addMessageToQueue(message);
878
+ } else {
879
+ const name = data.file.name.split('.');
880
+ const blob = data.file.slice(0, -1, 'image');
881
+ const newFile = new File([blob], `${name[0]}${Date.now()}.${name[1]}`, {type: 'image'});
882
+ this.props.actions.uploadAsset(newFile, data.type, data.fileParams);
883
+ }
884
+ };
885
+
886
+ copyIphoneContent = () => {
887
+ const formData = _.cloneDeep(this.state.formData);
888
+ if (!!formData[1]['message-title2'] && !!formData[1]['message-editor2']) {
889
+ formData[0]['message-title'] = formData[1]['message-title2'];
890
+ formData[0]['message-editor'] = formData[1]['message-editor2'];
891
+ this.setState({formData});
892
+ } else {
893
+ this.openNotificationWithIcon('warning', "Cannot copy empty field values.");
894
+ }
895
+ };
896
+ copyAndroidContent = () => {
897
+ const formData = _.cloneDeep(this.state.formData);
898
+ if (!!formData[0]['message-title'] && formData[0]['message-editor']) {
899
+ formData[1]['message-title2'] = formData[0]['message-title'];
900
+ formData[1]['message-editor2'] = formData[0]['message-editor'];
901
+ this.setState({formData});
902
+ } else {
903
+ this.openNotificationWithIcon('warning', "Cannot copy empty field values.");
904
+ }
905
+ };
906
+
907
+ showSelectedIosCta = (inputSchema, field, tab, selectedConfig) => {
908
+ const currentTab = tab || this.state.currentTab;
909
+ const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
910
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
911
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
912
+ const deepLinkOptions = _.map(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (link) => ({label: link.name, value: link.link, title: link.link }) );
913
+
914
+ const inputFields = get(schema, `containers[0].panes[${currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
915
+ forEach(inputFields, (inputField, fieldIndex) => {
916
+ forEach(inputField.cols, (col) => {
917
+ if (col.id === "add-sec-cta-ios") {
918
+ const inputId = `secondary-cta-${currentTab - 1}`;
919
+ inputFields.splice(fieldIndex + 1, 0, {
920
+ rowClassName: 'mobile-push-row',
921
+ cols: [
922
+ {
923
+ id: `${inputId}-action-display`,
924
+ metaType: "label",
925
+ value: <CapRow>
926
+ <CapColumn span={18}>
927
+ <CapHeader
928
+ title={this.state.templateCta.name}
929
+ description={get(this.state, "templateCta.ctaTemplateDetails[0].buttonText")}
930
+ size={"label"}/>
931
+ </CapColumn>
932
+ <CapColumn span={6}>
933
+ <CapLink title="change" onClick={() => this.addSecondoryCtaIos(true, this.state.formData, {id: "add-sec-cta-ios"})}/>
934
+ </CapColumn>
935
+ </CapRow>,
936
+ primitive: true,
937
+ dynamicTab: false,
938
+ type: "div",
939
+ width: 18,
940
+ offset: 1,
941
+ },
942
+ {
943
+ id: `${inputId}-action`,
944
+ metaType: "label",
945
+ value: "",
946
+ primitive: true,
947
+ dynamicTab: false,
948
+ type: "div",
949
+ width: 8,
950
+ offset: 0,
951
+ style: {
952
+ display: 'none',
953
+ },
954
+ },
955
+ {
956
+ id: `${inputId}-action2`,
957
+ metaType: "label",
958
+ value: "",
959
+ primitive: true,
960
+ dynamicTab: false,
961
+ type: "div",
962
+ width: 8,
963
+ offset: 0,
964
+ style: {display: 'none'},
965
+ },
966
+
967
+ ],
968
+ });
969
+ if (selectedConfig && (selectedConfig.id !== "16589g0g" && selectedConfig.id !== "17543720" && selectedConfig.id !== "1a491g56")) {
970
+ inputFields.splice(fieldIndex + 2, 0, {
971
+ rowClassName: "mobile-push-row",
972
+ identifier: `cta-deeplink-${inputId}`,
973
+ cols: [
974
+
975
+ {
976
+ id: `cta-deeplink-${inputId}`,
977
+ type: "radioGroup", //Resembles component to be used
978
+ metaType: "text",
979
+ datatype: "string",
980
+ options: ["Deeplink", "External Link"],
981
+ inductiveText: ["A page within mobile app", "An external web page"],
982
+ value: "Deeplink",
983
+ required: true,
984
+ width: 18,
985
+ offset: 1,
986
+ errorMessage: "Please select link type",
987
+ fluid: true,
988
+
989
+ styling: "semantic",
990
+ order: 1,
991
+ supportedEvents: ["onChange"],
992
+ customComponent: false,
993
+ },
994
+ ],
995
+ });
996
+ inputFields.splice(fieldIndex + 3, 0, {
997
+ rowClassName: 'mobile-push-row',
998
+ id: 'cta-deeplink-select-section',
999
+ identifier: `cta-deeplink-${inputId}-select2`,
1000
+ cols: [
1001
+
1002
+ {
1003
+ id: `cta-deeplink-${inputId}-select2`,
1004
+ placeholder: "Select DeepLink",
1005
+ type: "select", //Resembles component to be used
1006
+ options: deepLinkOptions,
1007
+ metaType: "text",
1008
+ datatype: "string",
1009
+ errorMessage: "Select a deeplink",
1010
+ required: true,
1011
+ fluid: true,
1012
+ width: 18,
1013
+ offset: 1,
1014
+ style: {
1015
+ width: '100%',
1016
+ marginBottom: '16px',
1017
+ },
1018
+ styling: "semantic",
1019
+ order: 1,
1020
+ customComponent: false,
1021
+ supportedEvents: [
1022
+ 'onSelect',
1023
+ ],
1024
+ },
1025
+ ],
1026
+ });
1027
+ }
1028
+ }
1029
+ });
1030
+ });
1031
+ if (!inputSchema) {
1032
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true});
1033
+ this.injectEvents(schema);
1034
+ }
1035
+ return schema;
1036
+ };
1037
+
1038
+ deletePrimaryCTA = (event) => {
1039
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1040
+ const id = event.currentTarget.id;
1041
+ const schema = _.cloneDeep(this.state.schema);
1042
+ // const eventsMap = _.cloneDeep(this.state.eventsMap);
1043
+ const selectedDeeplink = this.state.formData[this.state.currentTab - 1][`${id.replace('delete', 'select')}`];
1044
+ const formData = _.cloneDeep(this.state.formData);
1045
+ const self = this;
1046
+ _.forEach(schema.containers, (container) => {
1047
+ _.forEach(container.panes, (pane) => {
1048
+ _.forEach(pane.sections, (section) => {
1049
+ _.forEach(section.childSections, (childeSection) => {
1050
+ _.forEach(childeSection.childSections, (formChild) => {
1051
+ const child = formChild;
1052
+ if (child.type === 'multicols') {
1053
+ _.forEach(child.inputFields, (inputField, fieldIndex) => {
1054
+ if (inputField) {
1055
+ _.forEach(inputField.cols, (col) => {
1056
+ if (col.id === id) {
1057
+ child.inputFields.splice(fieldIndex, 1);
1058
+ if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-external-link") {
1059
+ child.inputFields.splice(fieldIndex, 1);
1060
+ delete formData[self.state.currentTab - 1][`${id.replace('delete', 'text')}`];
1061
+ delete formData[self.state.currentTab - 1][`${id.replace('-delete', '')}`];
1062
+ }
1063
+ if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-deeplink-select-section") {
1064
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
1065
+ const configkeys = selectedWeChatAccount ? _.filter(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (dl) => dl.link === selectedDeeplink) : [];
1066
+ if (configkeys.length) {
1067
+ const options = configkeys[0].keys;
1068
+ _.forEach(options, (opt) => {
1069
+ delete formData[this.state.currentTab - 1][`custom-value-${opt}-${id.replace('delete', 'select')}`];
1070
+ });
1071
+ child.inputFields = child.inputFields.slice(0, fieldIndex).concat(child.inputFields.slice( fieldIndex + options.length + 1, child.inputFields.length));
1072
+ delete formData[self.state.currentTab - 1][`${id.replace('delete', 'select')}`];
1073
+ delete formData[self.state.currentTab - 1][`${id.replace('-delete', '')}`];
1074
+ } else {
1075
+ child.inputFields.splice(fieldIndex, 1);
1076
+ }
1077
+ }
1078
+ child.inputFields.splice(fieldIndex, 0, {
1079
+ cols: [
1080
+ {
1081
+ id: `${this.state.currentTab === 1 ? "add-pri-cta" : "add-pri-cta-ios"}`,
1082
+ metaType: "label",
1083
+ value: "Add Primary CTA",
1084
+ primitive: true,
1085
+ dynamicTab: false,
1086
+ type: "div",
1087
+ style: {
1088
+ backgroundColor: 'white',
1089
+ textAlign: 'left',
1090
+ color: '#2673D7',
1091
+ lineHeight: '24px',
1092
+ fontSize: '14px',
1093
+ fontWeight: '600',
1094
+ fontFamily: 'open-sans',
1095
+ fontStyle: 'normal',
1096
+ cursor: 'pointer',
1097
+ },
1098
+ offset: 0,
1099
+ onlyDisplay: true,
1100
+ colStyle: {
1101
+ flex: 1,
1102
+ },
1103
+ submitAction: "addPrimaryCta",
1104
+ supportedEvents: ["addPrimaryCta"],
1105
+ },
1106
+ ],
1107
+ });
1108
+ }
1109
+ });
1110
+ }
1111
+ });
1112
+ }
1113
+ });
1114
+ });
1115
+ });
1116
+ });
1117
+ });
1118
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, formData, isSchemaChanged: true});
1119
+ this.injectEvents(schema);
1120
+ };
1121
+
1122
+ deleteSecondaryCtaIos = (callback) => {
1123
+ const schema = cloneDeep(this.state.schema);
1124
+ const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1125
+ forEach(inputFields, (inputField, fieldIndex) => {
1126
+ if (inputField) {
1127
+ forEach(inputField.cols, (col) => {
1128
+ if (col.id === "add-sec-cta-ios") {
1129
+ inputFields.splice(fieldIndex + 1, inputFields.length);
1130
+ }
1131
+ });
1132
+ }
1133
+ });
1134
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true}, callback);
1135
+ this.injectEvents(schema);
1136
+ };
1137
+
1138
+ deleteSecondaryCTA = (event) => {
1139
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1140
+ const id = event.currentTarget.id;
1141
+ if (id === "secondary-cta-0-delete") {
1142
+ const secCta2 = document.getElementById("secondary-cta-1-delete");
1143
+ if (secCta2) {
1144
+ const modalContent = {title: "Alert", body: "Please delete second Secondary cta First", type: 'info', show: true, onCancel: this.onModalCancel};
1145
+ this.setState({modalContent, showModal: true});
1146
+ return;
1147
+ }
1148
+ }
1149
+ const schema = _.cloneDeep(this.state.schema);
1150
+ // const eventsMap = _.cloneDeep(this.state.eventsMap);
1151
+ const selectedDeeplink = this.state.formData[this.state.currentTab - 1][`cta-deeplink-${id.replace('delete', 'select')}`];
1152
+ const formData = _.cloneDeep(this.state.formData);
1153
+ const self = this;
1154
+ const device = this.state.currentTab === 1 ? 'android' : 'ios';
1155
+ _.forEach(schema.containers, (container) => {
1156
+ _.forEach(container.panes, (pane) => {
1157
+ _.forEach(pane.sections, (section) => {
1158
+ _.forEach(section.childSections, (childeSection) => {
1159
+ _.forEach(childeSection.childSections, (formChild) => {
1160
+ const child = formChild;
1161
+ if (child.type === 'multicols') {
1162
+ _.forEach(child.inputFields, (inputField, fieldIndex) => {
1163
+ if (inputField) {
1164
+ _.forEach(inputField.cols, (col) => {
1165
+ if (col.id === id) {
1166
+ if (device === 'ios') {
1167
+ child.inputFields.splice(fieldIndex, 3);
1168
+ } else {
1169
+ child.inputFields.splice(fieldIndex, 2);
1170
+ }
1171
+ if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-external-link") {
1172
+ child.inputFields.splice(fieldIndex, 1);
1173
+ delete formData[self.state.currentTab - 1][`cta-deeplink-${id.replace('delete', 'text')}`];
1174
+ }
1175
+ if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].id === "cta-deeplink-select-section") {
1176
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
1177
+ const configkeys = selectedWeChatAccount ? _.filter(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (dl) => dl.link === selectedDeeplink) : [];
1178
+
1179
+ if (configkeys.length) {
1180
+ const options = configkeys[0].keys;
1181
+ _.forEach(options, (opt) => {
1182
+ delete formData[this.state.currentTab - 1][`custom-value-${opt}-cta-deeplink-${id.replace('delete', 'select')}`];
1183
+ });
1184
+ child.inputFields = child.inputFields.slice(0, fieldIndex).concat(child.inputFields.slice( fieldIndex + options.length + 1, child.inputFields.length));
1185
+ delete formData[this.state.currentTab - 1][`cta-deeplink-${id.replace('delete', 'select')}`];
1186
+ } else {
1187
+ child.inputFields.splice(fieldIndex, 1);
1188
+ }
1189
+ }
1190
+ delete formData[this.state.currentTab - 1][`${id.replace('delete', 'label')}`];
1191
+ delete formData[this.state.currentTab - 1][`cta-deeplink-${id.replace('-delete', '')}`];
1192
+ if (device === 'ios') {
1193
+ child.inputFields[fieldIndex] = {
1194
+ cols: [
1195
+ {
1196
+ id: "add-sec-cta-ios",
1197
+ metaType: "label",
1198
+ value: "Add Secondary CTA",
1199
+ primitive: true,
1200
+ dynamicTab: false,
1201
+ type: "div",
1202
+ style: {
1203
+ backgroundColor: 'white',
1204
+ textAlign: 'left',
1205
+ color: '#2673D7',
1206
+ lineHeight: '24px',
1207
+ fontSize: '14px',
1208
+ marginTop: '16px',
1209
+ fontWeight: '600',
1210
+ fontFamily: 'open-sans',
1211
+ fontStyle: 'normal',
1212
+ cursor: 'pointer',
1213
+ },
1214
+ offset: 0,
1215
+ onlyDisplay: true,
1216
+ colStyle: {
1217
+ flex: 1,
1218
+ },
1219
+ submitAction: "addSecondaryCtaIos",
1220
+ supportedEvents: ["addSecondaryCtaIos"],
1221
+ },
1222
+ ],
1223
+ };
1224
+ } else {
1225
+ if (child.inputFields[fieldIndex] && child.inputFields[fieldIndex].cols[0] && child.inputFields[fieldIndex].cols[0].id === "add-sec-cta") {
1226
+ child.inputFields[fieldIndex] = {
1227
+ cols: [
1228
+ {
1229
+ id: "add-sec-cta",
1230
+ metaType: "label",
1231
+ value: "Add Secondary CTA",
1232
+ primitive: true,
1233
+ dynamicTab: false,
1234
+ type: "div",
1235
+ style: {
1236
+ backgroundColor: 'white',
1237
+ textAlign: 'left',
1238
+ color: '#2673D7',
1239
+ lineHeight: '24px',
1240
+ fontSize: '14px',
1241
+ marginTop: '16px',
1242
+ fontWeight: '600',
1243
+ fontFamily: 'open-sans',
1244
+ fontStyle: 'normal',
1245
+ cursor: 'pointer',
1246
+ },
1247
+ offset: 0,
1248
+ onlyDisplay: true,
1249
+ colStyle: {
1250
+ flex: 1,
1251
+ },
1252
+ submitAction: "addSecondaryCta",
1253
+ supportedEvents: ['addSecondaryCta'],
1254
+ fieldsLimit: 2,
1255
+ fieldsCount: 0,
1256
+ },
1257
+ ],
1258
+ };
1259
+ }
1260
+ if (id === "secondary-cta-1-delete" || child.inputFields[fieldIndex].cols[0].id === "cta-label" || child.inputFields[fieldIndex].cols[0].id === "secondary-cta-1-space") {
1261
+ let nextFieldIndex = fieldIndex;
1262
+ if (id === "secondary-cta-1-delete" || child.inputFields[fieldIndex].cols[0].id === "secondary-cta-1-space") {
1263
+ nextFieldIndex = child.inputFields.length;
1264
+ }
1265
+ child.inputFields[nextFieldIndex] = {
1266
+ cols: [
1267
+ {
1268
+ id: "add-sec-cta",
1269
+ metaType: "label",
1270
+ value: "Add Another CTA",
1271
+ primitive: true,
1272
+ dynamicTab: false,
1273
+ type: "div",
1274
+ style: {
1275
+ backgroundColor: 'white',
1276
+ textAlign: 'left',
1277
+ color: '#2673D7',
1278
+ lineHeight: '24px',
1279
+ fontSize: '14px',
1280
+ fontWeight: '600',
1281
+ fontFamily: 'open-sans',
1282
+ fontStyle: 'normal',
1283
+ cursor: 'pointer',
1284
+ },
1285
+ offset: 0,
1286
+ onlyDisplay: true,
1287
+ colStyle: {
1288
+ flex: 1,
1289
+ },
1290
+ submitAction: "addSecondaryCta",
1291
+ supportedEvents: ['addSecondaryCta'],
1292
+ fieldsLimit: 2,
1293
+ fieldsCount: 1,
1294
+ },
1295
+ ],
1296
+ };
1297
+ }
1298
+ }
1299
+ }
1300
+ });
1301
+ }
1302
+ });
1303
+ }
1304
+ });
1305
+ });
1306
+ });
1307
+ });
1308
+ });
1309
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, formData, isSchemaChanged: true});
1310
+ this.injectEvents(schema);
1311
+ };
1312
+
1313
+
1314
+ startTemplateCreation = (data) => {
1315
+ console.log('startTemplateCreation', data);
1316
+ if (!this.state.isContentEditLoaded && this.state.fullSchema && this.props.Edit.weCrmAccounts) {
1317
+ const schema = JSON.stringify(data).indexOf("BIG_PICTURE") > -1 ? this.state.fullSchema.imageSchema : this.state.fullSchema.textSchema;
1318
+ this.setMobilePushAccountOptions(this.props.Edit.weCrmAccounts, data.content.accId);
1319
+ this.setState({schema, isContentEditLoaded: true, loadingContentEdit: true}, () => {
1320
+ this.injectEvents(this.state.schema);
1321
+ let editData = data.content;
1322
+ editData = editData.versions && editData.versions.base ? editData : {versions: {base: editData}};
1323
+ this.setEditState(editData, this.state.schema);
1324
+ });
1325
+ }
1326
+ };
1327
+ discardValues = () => {
1328
+ console.log('discarding', this.props.Edit);
1329
+ this.resetSchema();
1330
+ this.setState({
1331
+ formData: {},
1332
+ tabCount: 1,
1333
+ currentTab: 1,
1334
+ editData: {},
1335
+ }, () => {
1336
+ const schema = this.props.Edit.templateDetails.mode === "image" ? this.state.fullSchema.imageSchema : this.state.fullSchema.textSchema;
1337
+ this.setEditState(this.props.Edit.templateDetails, schema);
1338
+ });
1339
+ };
1340
+ resetSchema = () => {
1341
+ this.setState({ schema: this.state.initialState ? this.state.initialState : this.state.schema});
1342
+ };
1343
+ showNext = () => {
1344
+ const response = {
1345
+ action: "showNext",
1346
+ value: true,
1347
+ };
1348
+ parent.postMessage(JSON.stringify(response), '*');
1349
+ };
1350
+ copyContent = () => {
1351
+
1352
+ };
1353
+ moveToTemplates = () => {
1354
+ console.log('in move to Templates');
1355
+ const modalContent = {
1356
+ title: "Alert",
1357
+ body: "Do you really want to go back? All your temporary changes will be lost!",
1358
+ type: 'confirm',
1359
+ id: 'template-back-confirm-modal',
1360
+ show: true,
1361
+ };
1362
+ this.setState({modalContent, showModal: true});
1363
+ };
1364
+ injectSections = (sections) => {
1365
+ _.forEach(sections, (section) => {
1366
+ let temp = section;
1367
+ if (temp.type === 'col-label') {
1368
+ temp = this.injectColLabelSection(temp);
1369
+ } else if (section.type === 'multicols') {
1370
+ temp = this.injectMultiColSection(temp);
1371
+ } else if (section.type === 'parent') {
1372
+ temp = this.injectSections(temp.childSections);
1373
+ }
1374
+ });
1375
+ return sections;
1376
+ };
1377
+ injectMultiColSection = (section) => {
1378
+ _.forEach(section.inputFields, (inputField) => {
1379
+ _.forEach(inputField.cols, (col) => {
1380
+ const temp = col;
1381
+ if (temp.type === 'popover') {
1382
+ temp.content.sections = this.injectSections(temp.content.sections);
1383
+ temp.value.sections = this.injectSections(temp.value.sections);
1384
+ return true;
1385
+ }
1386
+ temp.injectedEvents = {};
1387
+ temp.className = temp.className ? temp.className : '';
1388
+ if (this.props.location.query.type === 'embedded' && ((temp.type === "tag-list" || temp.type === "div" || temp.type === "icon") && this.props.location.query.module !== "dvs") && (temp.supportedEvents)) {
1389
+ temp.className = `${temp.className} hide`;
1390
+ }
1391
+ // if (this.props.location.query.type === 'embedded' && (temp.type === "input" || temp.type === "textarea" || temp.type === "radioGroup") && this.props.location.query.module !== "dvs") {
1392
+ // temp.className = `${temp.className} disabled`;
1393
+ // temp.disabled = true;
1394
+ // }
1395
+ if (this.props.location.query.type === 'embedded' && temp.id === "mobilepush-template" ) {
1396
+ temp.options = this.state.templateOptions ? this.state.templateOptions : [];
1397
+ }
1398
+ if (this.props.location.query.type === 'embedded' && temp.id === "mobilepush-accounts" ) {
1399
+ temp.options = this.state.templateOptions ? this.state.accountsOptions : [];
1400
+ }
1401
+ if (temp.id === "mobile-push-preview" && this.props.Templates.selectedWeChatAccount && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
1402
+ temp.content.appName = this.props.Templates.selectedWeChatAccount.name;
1403
+ }
1404
+ _.forEach(col.supportedEvents, (event) => {
1405
+ console.log('injected event for ', col, event, this.getMappedEvent(col.id, event));
1406
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
1407
+ });
1408
+ return true;
1409
+ });
1410
+ });
1411
+ _.forEach(section.actionFields, (actionField) => {
1412
+ _.forEach(actionField.cols, (col) => {
1413
+ const temp = col;
1414
+ // temp.disabled = this.props.location.query.type === 'embedded' && this.props.location.query.module !== "dvs";
1415
+ if (temp.type === 'popover') {
1416
+ temp.content.sections = this.injectSections(temp.content.sections);
1417
+ temp.value.sections = this.injectSections(temp.value.sections);
1418
+ return true;
1419
+ }
1420
+ temp.injectedEvents = {};
1421
+ _.forEach(col.supportedEvents, (event) => {
1422
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
1423
+ });
1424
+ return true;
1425
+ });
1426
+ });
1427
+ return section;
1428
+ };
1429
+
1430
+ saveFormData = (formData) => {
1431
+ console.log('Saving form data', formData, this.state.tabCount);
1432
+ const obj = this.getTransformedData(formData);
1433
+ console.log('obj', obj);
1434
+ this.props.actions.editTemplate(obj);
1435
+ };
1436
+ handleFrameTasks = (e) => {
1437
+ // console.log('data listened to is', e.data);
1438
+ const type = e.data;
1439
+ console.log('data type', typeof type);
1440
+ if (typeof type === 'object') {
1441
+ // console.log('received something', type);
1442
+ const action = type.action;
1443
+ switch (action) {
1444
+ case "startTemplateCreation":
1445
+ this.startTemplateCreation(type.value);
1446
+ break;
1447
+ case "startLoading":
1448
+ this.startLoading(type.edit);
1449
+ break;
1450
+ case "getCurrentWindow":
1451
+ this.getCurrentWindow(type);
1452
+ break;
1453
+ default:
1454
+ break;
1455
+ }
1456
+ } else {
1457
+ switch (type) {
1458
+ case "getFormData":
1459
+ this.getFormData(e);
1460
+ break;
1461
+ case "startTemplateCreation":
1462
+ console.log('Starting to create template');
1463
+ //this.getFormData(e);
1464
+ break;
1465
+ case "moveToTemplates":
1466
+ console.log('moving to templates');
1467
+ this.moveToTemplates();
1468
+ break;
1469
+ case "validateContent":
1470
+ console.log('validating Content');
1471
+ this.validateContent(e);
1472
+ break;
1473
+ default:
1474
+ break;
1475
+ }
1476
+ }
1477
+ };
1478
+
1479
+ cancelTemplate = () => {
1480
+ const type = this.props.location.query.type;
1481
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
1482
+ this.props.router.push({
1483
+ pathname: `/mobilepush/`,
1484
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
1485
+ });
1486
+ };
1487
+
1488
+ showCtaKeys = (eventTriggered, formData, field, tabIndex, schemaInput) => {
1489
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1490
+ const currentTab = tabIndex || this.state.currentTab;
1491
+ const schema = _.cloneDeep(schemaInput || this.state.schema);
1492
+ const eventsMap = _.cloneDeep(this.state.eventsMap);
1493
+ let inputFields = get(schema, `containers[0].panes[${currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1494
+ const {id} = field;
1495
+ const fieldIndex = findIndex(inputFields, {identifier: id});
1496
+ const formDataKey = id.replace("-show-keys", "");
1497
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
1498
+ let keys = selectedWeChatAccount ? _.filter(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (dl) => dl.link === formData[currentTab - 1][formDataKey]) : [];
1499
+ if (keys[0]) {
1500
+ keys = keys[0].keys;
1501
+ }
1502
+ _.map(keys, (key, index) => {
1503
+ const row = {
1504
+ rowClassName: 'mobile-push-row',
1505
+ id: 'cta-deeplink-keys',
1506
+ cols: [
1507
+ {
1508
+ id: `custom-value-${key}-${id}`,
1509
+ label: key.replace('_', " "),
1510
+ type: "input", //Resembles component to be used
1511
+ metaType: "text",
1512
+ datatype: "string",
1513
+ required: true,
1514
+ width: 18,
1515
+ offset: 1,
1516
+ placeholder: `Please input ${key.replace('_', " ")}.`,
1517
+ fluid: true,
1518
+ styling: "semantic",
1519
+ order: 1,
1520
+ customComponent: false,
1521
+ errorMessage: "value cannot be empty.",
1522
+ },
1523
+ ],
1524
+ };
1525
+ inputFields.splice(fieldIndex + index + 1, 0, row);
1526
+ });
1527
+ if (!tabIndex) { // removes the existing selected options keys so that newly selected options keys can be added.
1528
+ const configkeys = _.filter(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (dl) => dl.link === this.state.formData[currentTab - 1][field.id]);
1529
+ if (configkeys.length) {
1530
+ const options = configkeys[0].keys;
1531
+ inputFields = inputFields.slice(0, fieldIndex + 1).concat(inputFields.slice(fieldIndex + options.length + 1, inputFields.length));
1532
+ // delete formData[self.state.currentTab - 1][`cta-deeplink-${id.replace('delete', 'select')}`];
1533
+ // delete formData[self.state.currentTab - 1][`cta-deeplink-${id.replace('-delete', '')}`];
1534
+ }
1535
+ }
1536
+ if (tabIndex) {
1537
+ return schema;
1538
+ }
1539
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, eventsMap, isSchemaChanged: true});
1540
+ this.injectEvents(schema);
1541
+ return schema;
1542
+ };
1543
+ addPrimaryCta = (flag, formData, field, inputSchema, currentTab) => {
1544
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1545
+ const id = field.id;
1546
+ const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
1547
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
1548
+ const deepLinkOptions = selectedWeChatAccount ? _.map(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
1549
+ // const eventsMap = _.cloneDeep(this.state.eventsMap);
1550
+ const tabIndex = currentTab || this.state.currentTab;
1551
+ const inputFields = get(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1552
+ const fieldIndex = findIndex(inputFields, {identifier: id});
1553
+ let newInputFields;
1554
+ if (formData[tabIndex - 1][id]) {
1555
+ newInputFields = this.getPrimaryCtaFields({inputFields, fieldIndex, deepLinkOptions});
1556
+ } else {
1557
+ const identifier = (tabIndex - 1) ? 'add-sec-cta-ios' : 'add-sec-cta';
1558
+ const indexOfNextField = findIndex(inputFields, {identifier});
1559
+ const deleteCount = indexOfNextField - fieldIndex;
1560
+ newInputFields = [...inputFields.slice(0, fieldIndex + 1), ...inputFields.slice(fieldIndex + deleteCount, inputFields.length)];
1561
+ }
1562
+ set(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
1563
+ if (inputSchema) {
1564
+ return schema;
1565
+ }
1566
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true});
1567
+ this.injectEvents(schema);
1568
+ return schema;
1569
+ };
1570
+
1571
+ addSecondoryCta = (flag, formData, field, inputSchema, currentTab) => {
1572
+ const id = field.id;
1573
+ const tabIndex = currentTab || this.state.currentTab;
1574
+ const schema = inputSchema ? _.cloneDeep(inputSchema) : _.cloneDeep(this.state.schema);
1575
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
1576
+ const ck = selectedWeChatAccount.configs ? !!selectedWeChatAccount.configs.deeplink : false;
1577
+ const deepLinkOptions = selectedWeChatAccount ? _.map(JSON.parse(ck ? selectedWeChatAccount.configs.deeplink : '[]'), (link) => ({label: link.name, value: link.link, title: link.link }) ) : [];
1578
+ const inputFields = get(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1579
+ const fieldIndex = findIndex(inputFields, {identifier: id});
1580
+ let newInputFields;
1581
+ if (formData[tabIndex - 1][id]) {
1582
+ newInputFields = this.getSecondaryCtaFields({inputFields, fieldIndex, deepLinkOptions});
1583
+ } else {
1584
+ const identifier = id === "add-sec-cta" ? 'add-sec-cta-2' : null;
1585
+ const indexOfNextField = identifier ? findIndex(inputFields, {identifier}) : inputFields.length;
1586
+ const deleteCount = indexOfNextField - fieldIndex;
1587
+ newInputFields = [...inputFields.slice(0, fieldIndex + 1), ...inputFields.slice(fieldIndex + deleteCount, inputFields.length)];
1588
+ }
1589
+ set(schema, `containers[0].panes[${tabIndex - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
1590
+ if (inputSchema) {
1591
+ return schema;
1592
+ }
1593
+ this.setState({schema, initialState: this.state.initialState ? this.state.initialState : this.state.schema, isSchemaChanged: true});
1594
+ this.injectEvents(schema);
1595
+ return schema;
1596
+ };
1597
+
1598
+ addSecondoryCtaIos = (flag, formData, schemaField) => {
1599
+ const id = schemaField.id;
1600
+ if (formData[this.state.currentTab - 1][id]) {
1601
+ const actionText = formData[this.state.currentTab - 1]['secondary-cta-1-action'];
1602
+ if (!this.props.iosCtasData) {
1603
+ if (!_.isEmpty(actionText)) {
1604
+ this.deleteSecondaryCtaIos();
1605
+ }
1606
+ this.props.actions.getIosCtas(this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier);//TODO: need to get license code of accoutn and send as arg
1607
+ } else {
1608
+ this.deleteSecondaryCtaIos(() => { // oncick of change
1609
+ this.setState({showIosCtaTable: true});
1610
+ });
1611
+ }
1612
+ } else {
1613
+ const schema = cloneDeep(this.state.schema);
1614
+ const inputFields = get(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`);
1615
+ forEach(inputFields, (inputField, fieldIndex) => {
1616
+ forEach(inputField.cols, (col) => {
1617
+ if (col.id === id) {
1618
+ const indexOfNextField = inputFields.length;
1619
+ const deleteCount = indexOfNextField - fieldIndex;
1620
+ const newInputFields = [...inputFields.slice(0, fieldIndex + 1), ...inputFields.slice(fieldIndex + deleteCount, inputField.length)];
1621
+ set(schema, `containers[0].panes[${this.state.currentTab - 1}].sections[0].childSections[0].childSections[0].inputFields`, newInputFields);
1622
+ this.setState({schema});
1623
+ }
1624
+ });
1625
+ });
1626
+ }
1627
+ };
1628
+ handleClose = () => {
1629
+ const formData = cloneDeep(this.state.formData);
1630
+ formData[this.state.currentTab - 1]['add-sec-cta-ios'] = false;
1631
+ this.setState({showIosCtaTable: false, formData});
1632
+ }
1633
+ injectContainer = (container) => {
1634
+ const temp = container;
1635
+ if (temp.type === 'tabs') {
1636
+ temp.injectedEvents = {};
1637
+ _.forEach(temp.supportedEvents, (event) => {
1638
+ temp.injectedEvents[event] = this.getMappedEvent(temp.id, event);
1639
+ });
1640
+ _.forEach(temp.panes, (pane) => {
1641
+ const tempPane = pane;
1642
+ tempPane.sectionsHeaders = this.injectSections(tempPane.sectionsHeaders);
1643
+ tempPane.sections = this.injectSections(tempPane.sections);
1644
+ });
1645
+ }
1646
+ return temp;
1647
+ };
1648
+
1649
+ injectEvents = (schema) => {
1650
+ const temp = schema;
1651
+ if (this.injectSections && temp.standalone) {
1652
+ temp.standalone.sections = this.injectSections(temp.standalone.sections);
1653
+ }
1654
+ _.forEach(temp.containers, (container) => {
1655
+ let tempContainer = container;
1656
+ tempContainer = this.injectContainer(tempContainer);
1657
+ return tempContainer;
1658
+ });
1659
+ console.log('final injected schema', schema);
1660
+ this.setState({schema, loadingContentEdit: false}, () => {
1661
+ this.removeStandAlone();
1662
+ });
1663
+ return schema;
1664
+ };
1665
+ removeStandAlone = () => {
1666
+ const schema = _.cloneDeep(this.state.schema);
1667
+ if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty') {
1668
+ if (schema.standalone.sections.length === 2) {
1669
+ schema.standalone.sections.splice(0, 1);
1670
+ }
1671
+ } else if (this.props.location.query.type === 'embedded' && typeof this.props.location.query.module !== 'undefined') {
1672
+ delete schema.standalone;
1673
+ } else {
1674
+ schema.standalone.sections.splice(1, 1);
1675
+ }
1676
+ this.setState({ schema });
1677
+ };
1678
+ handleOnTagsContextChange = (data) => {
1679
+ console.log('parent tags context', data);
1680
+ const query = {
1681
+ layout: 'mobilepush',
1682
+ type: 'TAG',
1683
+ context: data.toLowerCase() === 'all' ? 'default' : data.toLowerCase(),
1684
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
1685
+ };
1686
+ this.props.globalActions.fetchSchemaForEntity(query);
1687
+ };
1688
+
1689
+ render() {
1690
+ const schema = this.state.schema;
1691
+ let tipText = this.props.Edit && ("getTemplateDetailsInProgress" in this.props.Edit && this.props.Edit.getTemplateDetailsInProgress) ? 'Getting template details...' : '';
1692
+ tipText = this.props.Edit && ("editTemplateInProgress" in this.props.Edit && this.props.Edit.editTemplateInProgress) ? 'Saving Template...' : '';
1693
+ const loadingContentEdit = this.state.loadingContentEdit || (this.props.location.query.module === 'dvs' && _.isEmpty(this.state.schema));
1694
+ const spinning = loadingContentEdit || this.props.Edit.fetchingDefaultTemplates || this.props.Edit.assetUploading || this.state.loading || (this.props.Edit && (("getTemplateDetailsInProgress" in this.props.Edit && this.props.Edit.getTemplateDetailsInProgress) || ("editTemplateInProgress" in this.props.Edit && this.props.Edit.editTemplateInProgress)));
1695
+ let tags = this.props.metaEntities && this.props.metaEntities.tags ? this.props.metaEntities.tags.standard : [];
1696
+ if (this.props.supportedTags) {
1697
+ tags = this.props.supportedTags;
1698
+ }
1699
+ return (
1700
+ <div>
1701
+ <Spin tip={tipText} spinning={spinning}>
1702
+ {<Row style={{marginBottom: '16px', marginLeft: '-40px'}}>
1703
+ <Col offset={1}>
1704
+ { this.props.location.query.type !== "embedded" &&
1705
+ <Breadcrumb>
1706
+ <BreadcrumbItem>Campaigns</BreadcrumbItem>
1707
+ <BreadcrumbItem>Creatives</BreadcrumbItem>
1708
+ <BreadcrumbItem>Mobile Push</BreadcrumbItem>
1709
+ </Breadcrumb>
1710
+ }
1711
+ </Col>
1712
+ </Row>}
1713
+ <Row>
1714
+ <Col>
1715
+ <FormBuilder
1716
+ schema={schema}
1717
+ onSubmit={this.saveFormData}
1718
+ onChange={this.onFormDataChange}
1719
+ formData={_.cloneDeep(this.state.formData)}
1720
+ currentTab={this.state.currentTab}
1721
+ parent={this}
1722
+ location={this.props.location}
1723
+ isEdit
1724
+ tabCount={2}
1725
+ iosCtasData={this.state.iosCtasData}
1726
+ tags={tags}
1727
+ injectedTags={this.state.injectedTags ? this.state.injectedTags : {}}
1728
+ onFormValidityChange={this.setFormValidity}
1729
+ usingTabContainer
1730
+ checkValidation={this.state.checkValidation}
1731
+ onContextChange={this.handleOnTagsContextChange}
1732
+ showModal={this.state.showModal}
1733
+ iframeParent={parent}
1734
+ router={this.props.router}
1735
+ isSchemaChanged={this.state.isSchemaChanged}
1736
+ handleCancelModal={this.handleCancelModal}
1737
+ modal={this.state.modalContent}
1738
+ setModalContent={this.setModalContent}
1739
+ />
1740
+ </Col>
1741
+ {this.props.iosCtasData && this.state.showIosCtaTable &&
1742
+ <CapSlideBox
1743
+ size="size-l"
1744
+ header={<CapHeader
1745
+ title={<FormattedMessage {...messages.selectActionButton} />}
1746
+ prefix={
1747
+ <PrefixWrapper>
1748
+ <CapIcons.backIcon onClick={this.handleClose} />
1749
+ </PrefixWrapper>
1750
+ }
1751
+
1752
+ />}
1753
+ content={<CapTable
1754
+ rowSelection={{
1755
+ type: 'radio',
1756
+ onSelect: (record) => {
1757
+ this.setState({templateCta: record, showIosCtaTable: false}, () => this.selectCtaIos(record));
1758
+ },
1759
+ }}
1760
+ dataSource={this.props.iosCtasData} columns={[
1761
+ {
1762
+ title: "Name and Description",
1763
+ dataIndex: "name",
1764
+ key: "name",
1765
+ width: 200,
1766
+ render: (text, record) => (
1767
+ <div>
1768
+ <div>{record.name}</div>
1769
+ <div>{record.description}</div>
1770
+ </div>),
1771
+ },
1772
+ {
1773
+ title: "Button 1",
1774
+ dataIndex: "description",
1775
+ key: "button1",
1776
+ width: 100,
1777
+ render: (text, record) => (
1778
+ <div>
1779
+ {record.ctaTemplateDetails[0] && record.ctaTemplateDetails[0].buttonText}
1780
+ </div>),
1781
+ },
1782
+ {
1783
+ title: "Button 2",
1784
+ dataIndex: "description",
1785
+ key: "button2",
1786
+ width: 100,
1787
+ render: (text, record) => (
1788
+ <div>
1789
+ {record.ctaTemplateDetails[1] ? record.ctaTemplateDetails[1].buttonText : ''}
1790
+ </div>
1791
+ ),
1792
+ },
1793
+ ]}
1794
+ />}
1795
+ show={this.state.showIosCtaTable}
1796
+ handleClose={this.handleClose}
1797
+ />
1798
+ }
1799
+ </Row>
1800
+ </Spin>
1801
+ </div>
1802
+ );
1803
+ }
1804
+ }
1805
+
1806
+ Edit.propTypes = {
1807
+ actions: PropTypes.object.isRequired,
1808
+ Edit: PropTypes.object,
1809
+ params: PropTypes.object,
1810
+ router: PropTypes.object,
1811
+ location: PropTypes.object,
1812
+ globalActions: PropTypes.object,
1813
+ templatesActions: PropTypes.object,
1814
+ Templates: PropTypes.object,
1815
+ metaEntities: PropTypes.object,
1816
+ templateDetails: PropTypes.object,
1817
+ intl: intlShape.isRequired,
1818
+ supportedTags: PropTypes.array,
1819
+ getDefaultTags: PropTypes.string,
1820
+ templateData: PropTypes.object,
1821
+ isFullMode: PropTypes.bool,
1822
+ iosCtasData: PropTypes.array,
1823
+
1824
+ };
1825
+
1826
+ const mapStateToProps = createStructuredSelector({
1827
+ Edit: makeSelectEdit(),
1828
+ Create: makeSelectCreate(),
1829
+ editResponse: makeSelectEditResponse(),
1830
+ templateDetails: makeSelectTemplateDetailsResponse(),
1831
+ metaEntities: makeSelectMetaEntities(),
1832
+ Templates: makeSelectTemplates(),
1833
+ iosCtasData: makeSelectIosCta(),
1834
+
1835
+ });
1836
+
1837
+ function mapDispatchToProps(dispatch) {
1838
+ return {
1839
+ actions: bindActionCreators(actions, dispatch),
1840
+ globalActions: bindActionCreators(globalActions, dispatch),
1841
+ templatesActions: bindActionCreators(templatesActions, dispatch),
1842
+ };
1843
+ }
1844
+
1845
+ export default connect(mapStateToProps, mapDispatchToProps)(injectIntl(Edit));