@capillarytech/creatives-library 7.7.0 → 7.7.1

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 (49) hide show
  1. package/app.js +5 -0
  2. package/index.html +2 -2
  3. package/package.json +4 -2
  4. package/services/api.js +2 -0
  5. package/utils/gtmTrackers/gtmEvents/creativeDetails.js +41 -0
  6. package/utils/gtmTrackers/index.js +17 -0
  7. package/v2Components/TemplatePreview/assets/images/mobile.svg +24 -0
  8. package/v2Containers/App/constants.js +11 -0
  9. package/v2Containers/Cap/index.js +23 -29
  10. package/v2Containers/Email/index.js +14 -3
  11. package/v2Containers/EmailWrapper/index.js +10 -3
  12. package/v2Containers/Facebook/Advertisement/index.js +9 -2
  13. package/v2Containers/Line/Container/index.js +32 -4
  14. package/v2Containers/Line/Create/_lineCreate.scss +64 -0
  15. package/v2Containers/Line/Create/actions.js +94 -0
  16. package/v2Containers/Line/Create/constants.js +43 -0
  17. package/v2Containers/Line/Create/index.js +1132 -0
  18. package/v2Containers/Line/Create/initialSchema.js +378 -0
  19. package/v2Containers/Line/Create/messages.js +229 -0
  20. package/v2Containers/Line/Create/reducer.js +99 -0
  21. package/v2Containers/Line/Create/sagas.js +113 -0
  22. package/v2Containers/Line/Create/selectors.js +30 -0
  23. package/v2Containers/Line/CreateWrapper/constants.js +2 -0
  24. package/v2Containers/Line/CreateWrapper/index.js +117 -0
  25. package/v2Containers/Line/CreateWrapper/messages.js +55 -0
  26. package/v2Containers/Line/Edit/_lineEdit.scss +23 -0
  27. package/v2Containers/Line/Edit/actions.js +79 -0
  28. package/v2Containers/Line/Edit/constants.js +27 -0
  29. package/v2Containers/Line/Edit/index.js +1051 -0
  30. package/v2Containers/Line/Edit/messages.js +173 -0
  31. package/v2Containers/Line/Edit/reducer.js +83 -0
  32. package/v2Containers/Line/Edit/sagas.js +81 -0
  33. package/v2Containers/Line/Edit/selectors.js +29 -0
  34. package/v2Containers/Line/Edit/tests/actions.test.js +18 -0
  35. package/v2Containers/Line/Edit/tests/index.test.js +10 -0
  36. package/v2Containers/Line/Edit/tests/reducer.test.js +9 -0
  37. package/v2Containers/Line/Edit/tests/sagas.test.js +15 -0
  38. package/v2Containers/Line/Edit/tests/selectors.test.js +10 -0
  39. package/v2Containers/MobilePush/Create/index.js +25 -4
  40. package/v2Containers/MobilePush/Edit/index.js +27 -5
  41. package/v2Containers/MobilePush/Edit/sagas.js +1 -1
  42. package/v2Containers/MobilePush/commonMethods.js +19 -1
  43. package/v2Containers/Sms/Create/index.js +14 -2
  44. package/v2Containers/Sms/Edit/index.js +15 -2
  45. package/v2Containers/Templates/index.js +7 -7
  46. package/v2Containers/Templates/reducer.js +3 -1
  47. package/v2Containers/Viber/index.js +19 -3
  48. package/v2Containers/WeChat/MapTemplates/index.js +12 -3
  49. package/v2Containers/WeChat/RichmediaTemplates/Create/index.js +11 -2
@@ -0,0 +1,1051 @@
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 { Row, Col, Spin, Breadcrumb, notification } from 'antd';
13
+ import { createStructuredSelector } from 'reselect';
14
+ import { intlShape } from 'react-intl';
15
+ import _ from 'lodash';
16
+ import {makeSelectEdit, makeSelectEditResponse, makeSelectTemplateDetailsResponse} from "../../MobilePush/Edit/selectors";
17
+ import {makeSelectMetaEntities, setInjectedTags} from "../../Cap/selectors";
18
+ import {getMessageObject} from "../../../utils/messageUtils";
19
+ import FormBuilder from '../../../v2Components/FormBuilder';
20
+ import * as actions from "../../MobilePush/Edit/actions";
21
+ import * as templatesActions from "../../Templates/actions";
22
+ import {makeSelectTemplates} from "../../Templates/selectors";
23
+ import messages from './messages';
24
+ import './_lineEdit.scss';
25
+ import withCreatives from '../../../hoc/withCreatives';
26
+
27
+ const BreadcrumbItem = Breadcrumb.Item;
28
+
29
+ export class Edit extends React.Component { // eslint-disable-line react/prefer-stateless-function
30
+ constructor(props) {
31
+ super(props);
32
+ const map = {
33
+ "template-name": {
34
+ onChange: this.onTemplateNameChange,
35
+ },
36
+ "discard-button": {
37
+ discardValues: this.discardValues,
38
+ },
39
+ "cancel-button": {
40
+ cancelTemplate: this.cancelTemplate,
41
+ },
42
+ "save-button": {
43
+ saveFormData: this.saveFormData,
44
+ },
45
+ "message-editor": {
46
+ onChange: this.onTemplateContentChange,
47
+ },
48
+ "message-editor2": {
49
+ onChange: this.onTemplateContentChange,
50
+ },
51
+ "message-tagList": {
52
+ onTagSelect: this.onTagSelect,
53
+ },
54
+ "message-tagList2": {
55
+ onTagSelect: this.onTagSelect,
56
+ },
57
+ "title-tagList": {
58
+ onTagSelect: this.onTagSelect,
59
+ },
60
+ "title-tagList2": {
61
+ onTagSelect: this.onTagSelect,
62
+ },
63
+ "pane": {
64
+ onTabChange: this.onTabChange,
65
+ },
66
+ "image-upload": {
67
+ onUpload: this.uploadImage,
68
+ },
69
+ "line-template": {
70
+ onSelect: this.onTemplateChange,
71
+ },
72
+ };
73
+ this.state = {
74
+ formData: {},
75
+ tabCount: 1,
76
+ schema: {},
77
+ currentTab: 1,
78
+ editData: {},
79
+ loading: false,
80
+ isFormValid: true,
81
+ injectedTags: {},
82
+ showModal: false,
83
+ eventsMap: map,
84
+ modalContent: {title: this.props.intl.formatMessage(messages.alertMessage), body: this.props.intl.formatMessage(messages.templateNotConfigured), type: 'confirm'},
85
+ };
86
+ }
87
+ componentWillMount() {
88
+ console.log('edit mounting line');
89
+ if (this.props.location.query.type !== 'embedded') {
90
+ const type = this.props.location.query.type;
91
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
92
+ this.props.router.push({
93
+ pathname: `/line/`,
94
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
95
+ });
96
+ } else {
97
+ const query = {
98
+ layout: 'LINE',
99
+ type: 'LAYOUT',
100
+ };
101
+ this.props.globalActions.fetchSchemaForEntity(query);
102
+ }
103
+ }
104
+
105
+ componentDidMount() {
106
+ window.addEventListener("message", this.handleFrameTasks);
107
+ const type = this.props.location.query.type;
108
+ if (type === 'embedded') {
109
+ const response = {
110
+ action: 'startTemplateCreation',
111
+ };
112
+ parent.postMessage(JSON.stringify(response), '*');
113
+ }
114
+ if (!_.isEmpty(this.state.schema)) {
115
+ this.injectEvents(this.state.schema);
116
+ }
117
+ if (this.props.location.query && typeof this.props.location.query.module === 'undefined') { // when this containers is imported from creatives library
118
+ if (this.props.params.id) {
119
+ this.props.actions.getTemplateDetails(this.props.params.id);
120
+ } else {
121
+ this.props.actions.setTemplateDetails(this.props.templateData);
122
+ }
123
+ }
124
+ }
125
+
126
+ componentWillReceiveProps(nextProps) {
127
+ if (nextProps.isGetFormData) {
128
+ nextProps.getFormLibraryData(this.getFormData());
129
+ }
130
+ const params = {
131
+ name: '',
132
+ sortBy: 'Most Recent',
133
+ };
134
+ this.props.actions.getLineTemplatesList('line', params);
135
+
136
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && _.isEmpty(this.state.fullSchema)) {
137
+ this.setState({fullSchema: nextProps.metaEntities.layouts[0].definition, schema: nextProps.location.query.module === 'loyalty' ? nextProps.metaEntities.layouts[0].definition.textSchema : {}}, () => {
138
+ if (nextProps.location.query.module !== 'loyalty') {
139
+ this.props.actions.getTemplateDetails(this.props.params.id);
140
+ }
141
+ });
142
+ if (this.props.location.query.type === 'embedded') {
143
+ this.showNext();
144
+ }
145
+ }
146
+
147
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && nextProps.Edit.lineTemplates && !_.isEqual(nextProps.Edit.lineTemplates, this.props.Edit.lineTemplates)) { //used inloyalty
148
+ if (nextProps.location.query.type === 'embedded' && nextProps.location.query.module === 'loyalty') {
149
+ this.setTemplateOptions(nextProps.Edit.lineTemplates);
150
+ }
151
+ }
152
+ if (nextProps.templateDetails && nextProps.templateDetails.name && _.isEmpty(this.state.editData) && (this.props.location.query.type !== 'embedded' || (!_.isEmpty(this.state.fullSchema)))) {
153
+ this.props = nextProps;
154
+ const mode = nextProps.templateDetails.definition ? nextProps.templateDetails.definition.mode : nextProps.templateDetails.mode;
155
+ const schema = mode === "text" ? this.state.fullSchema.textSchema : this.state.fullSchema.imageSchema;
156
+ this.setEditState(nextProps.templateDetails, schema);
157
+ const query = {
158
+ layout: 'line',
159
+ type: 'TAG',
160
+ context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
161
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
162
+ };
163
+ if (this.props.getDefaultTags) {
164
+ query.context = this.props.getDefaultTags;
165
+ }
166
+ this.props.globalActions.fetchSchemaForEntity(query);
167
+ }
168
+ if (nextProps.Edit.uploadedAssetData) {
169
+ const formData = _.cloneDeep(this.state.formData);
170
+ formData[this.state.currentTab - 1].image = nextProps.Edit.uploadedAssetData.metaInfo.public_url;
171
+ this.setState({formData});
172
+ this.props.actions.clearAsset();
173
+ }
174
+ if (nextProps.Edit.iosCtasData) {
175
+ this.setState({iosCtasData: nextProps.Edit.iosCtasData});
176
+ }
177
+ if (nextProps.Edit.editResponse && nextProps.Edit.editResponse.templateId) {
178
+ console.log('reseting schema');
179
+ this.resetSchema();
180
+ this.setState({
181
+ formData: {},
182
+ tabCount: 1,
183
+ currentTab: 1,
184
+ editData: {},
185
+ });
186
+ const message = getMessageObject('success', this.props.intl.formatMessage(messages['MOBILEPUSH Template Edited Successfully']), true);
187
+ this.props.globalActions.addMessageToQueue(message);
188
+ this.props.actions.clearEditResponse();
189
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
190
+ const type = this.props.location.query.type;
191
+ this.props.router.push({
192
+ pathname: `/line/`,
193
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
194
+ });
195
+ }
196
+
197
+ if (nextProps.Edit.editTemplateError && !_.isEqual(nextProps.Edit.editTemplateError, this.props.Edit.editTemplateError)) {
198
+ const message = getMessageObject('error', (nextProps.Edit.editTemplateErrorMessage && nextProps.Edit.editTemplateErrorMessage !== '') ? nextProps.Edit.editTemplateErrorMessage : this.props.intl.formatMessage(messages.somethingWentWrong), true);
199
+ this.props.globalActions.addMessageToQueue(message);
200
+ }
201
+ }
202
+
203
+ componentWillUnmount() {
204
+ this.props.actions.clearData();
205
+ window.removeEventListener("message", this.handleFrameTasks);
206
+ }
207
+
208
+ onTemplateChange = (isEvent, formData) => {
209
+ _.forEach(this.props.Edit.lineTemplates, (template) => {
210
+ if (template._id === formData['line-template']) {
211
+ this.setState({editData: {}, formData: {}}, () => {
212
+ this.props.actions.setSelectedTemplate(template);
213
+ });
214
+ }
215
+ });
216
+ };
217
+
218
+ onFormDataChange = (formData, tabCount, currentTab) => {
219
+ console.log('Form data changed is ', formData, tabCount, currentTab);
220
+ const newFormData = _.cloneDeep(formData);
221
+ if (newFormData[this.state.currentTab - 1] && newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-table`]) {
222
+ newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-label`] = newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-table`].name;
223
+ newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action`] = newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-table`].ctaTemplateDetails[0].buttonText;
224
+ delete newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action2`];
225
+ if (newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-table`].ctaTemplateDetails[1]) {
226
+ newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-action2`] = newFormData[this.state.currentTab - 1][`secondary-cta-${this.state.currentTab - 1}-table`].ctaTemplateDetails[1].buttonText;
227
+ }
228
+ }
229
+ if (newFormData["line-accounts"] !== this.state.formData["line-accounts"]) {
230
+ this.setMobilePushAccountOptions(this.props.Edit.weCrmAccounts, newFormData["line-accounts"]);
231
+ delete newFormData['line-template'];
232
+ delete newFormData['template-name'];
233
+ if (!_.isEmpty(newFormData[0])) {
234
+ delete newFormData[0];
235
+ }
236
+ if (!_.isEmpty(newFormData[1])) {
237
+ delete newFormData[1];
238
+ }
239
+ }
240
+ if (this.state.isSchemaChanged) {
241
+ this.setState({isSchemaChanged: false});
242
+ }
243
+ this.setState({formData: newFormData, tabCount});
244
+ if (currentTab) {
245
+ this.setState({currentTab});
246
+ }
247
+ };
248
+
249
+ onTabChange = (data) => {
250
+ console.log('inside parent ontabchange', data, this.state);
251
+ this.setState({currentTab: data});
252
+ };
253
+
254
+ onTagSelect = (data, currentTab, srcComp) => {
255
+ console.log('parent data tag', data, currentTab);
256
+ const editorId = srcComp.target;
257
+ this.insertAtCursor(document.getElementById(editorId), `{{${data}}}`, currentTab);
258
+ document.getElementById(editorId).focus();
259
+ };
260
+ onModalCancel = () => {
261
+ if (this.state.modalContent && this.state.modalContent.show) {
262
+ this.setState({modalContent: {...this.state.modalContent, show: false}});
263
+ }
264
+ };
265
+ setTemplateOptions = (lineTemplates) => {
266
+ const templateOptions = [];
267
+ let selectedTemplate = {};
268
+ if (!_.isEmpty(lineTemplates)) {
269
+ _.forEach(lineTemplates, (template) => {
270
+ templateOptions.push({
271
+ key: template._id,
272
+ label: template.name,
273
+ value: template._id,
274
+ });
275
+ if (this.state.formData['line-template'] && template._id === this.state.formData['line-template']) {
276
+ selectedTemplate = template;
277
+ }
278
+ });
279
+ }
280
+ this.setState({templateOptions}, () => {
281
+ if (!_.isEmpty(selectedTemplate)) {
282
+ this.props.actions.setSelectedTemplate(selectedTemplate);
283
+ }
284
+ if (!_.isEmpty(this.state.schema)) {
285
+ this.injectEvents(this.state.schema);
286
+ }
287
+ });
288
+ };
289
+ setMobilePushAccountOptions = (accounts, newAccountId) => {
290
+ let accId = newAccountId || this.props.location.query.account_id;
291
+ if (this.props.location.query.module !== "loyalty") {
292
+ accId = Number(accId);
293
+ }
294
+ const formData = _.cloneDeep(this.state.formData);
295
+ let selectedAccount = {};
296
+ if (accId) {
297
+ _.forEach(accounts, (account) => {
298
+ let acccountId = account.id;
299
+ if (this.props.location.query.module === "loyalty" && typeof accId === 'string') {
300
+ acccountId = account.sourceAccountIdentifier;
301
+ }
302
+ if (acccountId === accId) {
303
+ this.props.templatesActions.setWeChatAccount(account);
304
+ selectedAccount = account;
305
+ formData['line-accounts'] = account.id;
306
+ if (this.props.location.query.account_id) {
307
+ formData['line-template'] = this.props.params.id;
308
+ }
309
+ }
310
+ });
311
+ } else {
312
+ selectedAccount = accounts[0];
313
+ formData['line-accounts'] = accounts[0].id;
314
+ }
315
+ this.props.actions.setWeChatAccount(selectedAccount);
316
+ this.setState({formData, accountsOptions: accounts.map((acc) => ({key: acc.id, label: acc.name, value: acc.id}))});
317
+ };
318
+
319
+ getTransformedData = (formData) => {
320
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.Edit.selectedWeChatAccount);
321
+ const obj = _.cloneDeep(this.state.editData);
322
+ obj.versions = {
323
+ base: {},
324
+ };
325
+ obj.name = formData['template-name'];
326
+ obj.definition = {
327
+ accountId: selectedWeChatAccount.id,
328
+ licenseCode: selectedWeChatAccount.sourceAccountIdentifier,
329
+ mode: this.props.Edit.templateDetails.mode,
330
+ };
331
+ const android = {};
332
+ Object.keys(formData[0]).forEach((data) => {
333
+ if (!!formData[0][data] && data !== "tabKey") {
334
+ android[data] = formData[0][data];
335
+ }
336
+ });
337
+ const ios = {};
338
+ Object.keys(formData[1]).forEach((data) => {
339
+ if (!!formData[1][data] && data !== "tabKey") {
340
+ ios[data] = formData[1][data];
341
+ }
342
+ });
343
+ obj.versions.base = {};
344
+ delete android.base;
345
+ if (!_.isEmpty(android)) {
346
+ obj.versions.base.ANDROID = {
347
+ luid: "{{luid}}",
348
+ cuid: "{{cuid}}",
349
+ communicationId: "{{communicationId}}",
350
+ title: android['message-title'],
351
+ message: android['message-editor'],
352
+ expandableDetails: {
353
+ style: "BIG_TEXT",
354
+ message: android['message-editor'],
355
+ },
356
+ custom: _.map(android, (field, key) => {
357
+ if (key.indexOf('custom-value') > -1) {
358
+ 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;
359
+ }
360
+ return undefined;
361
+ }).filter((custom) => custom),
362
+ };
363
+ }
364
+ if (android['cta-deeplink'] && android['cta-deeplink'] !== "") {
365
+ obj.versions.base.ANDROID.cta = {
366
+ type: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
367
+ actionLink: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? android['cta-deeplink-select'] : android['cta-deeplink-text'],
368
+ deepLinkName: android['cta-deeplink'] && android['cta-deeplink'].toLowerCase() === "deeplink" ? this.getLinkName(android['cta-deeplink-select']) : undefined,
369
+ };
370
+ if (this.props.location.query.type === 'embedded') {
371
+ delete obj.versions.base.ANDROID.cta.deepLinkName;
372
+ }
373
+ }
374
+ if (!_.isEmpty(ios)) {
375
+ obj.versions.base.IOS = {
376
+ luid: "{{luid}}",
377
+ cuid: "{{cuid}}",
378
+ communicationId: "{{communicationId}}",
379
+ title: ios['message-title2'],
380
+ message: ios['message-editor2'],
381
+ expandableDetails: {
382
+ style: "BIG_TEXT",
383
+ message: ios['message-title2'],
384
+ ctas: [
385
+
386
+ ],
387
+ categoryId: ios['secondary-cta-1-table'] ? ios['secondary-cta-1-table'].id : undefined,
388
+ },
389
+ custom: _.map(ios, (field, key) => {
390
+ if (key.indexOf('custom-value') > -1) {
391
+ 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;
392
+ }
393
+ return undefined;
394
+ }).filter((custom) => custom),
395
+ };
396
+ }
397
+ if (ios['cta-deeplink2'] && ios['cta-deeplink2'] !== "") {
398
+ obj.versions.base.IOS.cta = {
399
+ type: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
400
+ actionLink: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? ios['cta-deeplink2-select'] : ios['cta-deeplink2-text'],
401
+ deepLinkName: ios['cta-deeplink2'] && ios['cta-deeplink2'].toLowerCase() === "deeplink" ? this.getLinkName(ios['cta-deeplink2-select']) : undefined,
402
+ };
403
+ if (this.props.location.query.type === 'embedded') {
404
+ delete obj.versions.base.IOS.cta.deepLinkName;
405
+ }
406
+ }
407
+ const imageLink = android.image;
408
+ if (imageLink) {
409
+ obj.versions.base.ANDROID.expandableDetails.image = imageLink;
410
+ obj.versions.base.ANDROID.expandableDetails.style = "BIG_PICTURE";
411
+ }
412
+ if (obj.versions.base.ANDROID && obj.versions.base.ANDROID.cta) {
413
+ if (obj.versions.base.ANDROID.cta.type === "DEEP_LINK") {
414
+ const params = _.map(android, (field, key) => {
415
+ let actionLink;
416
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-select') > -1) {
417
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-select', '');
418
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
419
+ }
420
+ return actionLink;
421
+ }).filter((actionLink) => actionLink);
422
+ if (params.length) {
423
+ obj.versions.base.ANDROID.cta.actionLink = `${obj.versions.base.ANDROID.cta.actionLink}?${params.join('&')}`;
424
+ }
425
+ }
426
+ }
427
+ const secondaryCta1 = !!android["cta-deeplink-secondary-cta-0-select"] || !!android['secondary-cta-0-label'];
428
+ const secondaryCta2 = !!android['cta-deeplink-secondary-cta-1-select'] || !!android['secondary-cta-1-label'];
429
+ if (secondaryCta1 || secondaryCta2 ) {
430
+ obj.versions.base.ANDROID.expandableDetails.ctas = [];
431
+ if (secondaryCta1) {
432
+ const cta = {
433
+ actionText: android['secondary-cta-0-label'],
434
+ type: (android['cta-deeplink-secondary-cta-0'] || '').toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
435
+ actionLink: (android['cta-deeplink-secondary-cta-0'] || '').toLowerCase() === "deeplink" ? android['cta-deeplink-secondary-cta-0-select'] : android['cta-deeplink-secondary-cta-0-text'],
436
+ seccdeepLinkName: this.getLinkName(android['cta-deeplink-secondary-cta-0-select']),
437
+ };
438
+ if (this.props.location.query.type === 'embedded') {
439
+ delete cta.seccdeepLinkName;
440
+ }
441
+ obj.versions.base.ANDROID.expandableDetails.ctas.push(cta);
442
+ if (obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
443
+ const params = _.map(android, (field, key) => {
444
+ let actionLink;
445
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-0-select') > -1) {
446
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-0-select', '');
447
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
448
+ }
449
+ return actionLink;
450
+ }).filter((actionLink) => actionLink);
451
+ if (params.length) {
452
+ 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('&')}`;
453
+ }
454
+ }
455
+ }
456
+ if (secondaryCta2) {
457
+ obj.versions.base.ANDROID.expandableDetails.ctas.push({
458
+ actionText: android['secondary-cta-1-label'],
459
+ type: (android['cta-deeplink-secondary-cta-1'] || '').toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL",
460
+ actionLink: (android['cta-deeplink-secondary-cta-1'] || '').toLowerCase() === "deeplink" ? android['cta-deeplink-secondary-cta-1-select'] : android['cta-deeplink-secondary-cta-1-text'],
461
+ seccdeepLinkName: this.getLinkName(android['cta-deeplink-secondary-cta-1-select']),
462
+ });
463
+ if (obj.versions.base.ANDROID.expandableDetails.ctas[obj.versions.base.ANDROID.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
464
+ const params = _.map(android, (field, key) => {
465
+ let actionLink;
466
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-1-select') > -1) {
467
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-1-select', '');
468
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
469
+ }
470
+ return actionLink;
471
+ }).filter((actionLink) => actionLink);
472
+ if (params.length) {
473
+ 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('&')}`;
474
+ }
475
+ }
476
+ }
477
+ }
478
+ const imageLinkIos = ios.image;
479
+ if (imageLinkIos) {
480
+ obj.versions.base.IOS.expandableDetails.image = imageLinkIos;
481
+ obj.versions.base.IOS.expandableDetails.style = "BIG_PICTURE";
482
+ }
483
+ if (obj.versions.base.IOS && obj.versions.base.IOS.cta) {
484
+ if (obj.versions.base.IOS.cta.type === "DEEP_LINK") {
485
+ const params = _.map(ios, (field, key) => {
486
+ let actionLink;
487
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink2-select') > -1) {
488
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink2-select', '');
489
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
490
+ }
491
+ return actionLink;
492
+ }).filter((actionLink) => actionLink);
493
+ if (params.length) {
494
+ obj.versions.base.IOS.cta.actionLink = `${obj.versions.base.IOS.cta.actionLink}?${params.join('&')}`;
495
+ }
496
+ }
497
+ }
498
+ const secondaryCtaIos = !!ios['cta-deeplink-secondary-cta-1-select'] || !!ios['secondary-cta-1-label'];
499
+
500
+ if (secondaryCtaIos) {
501
+ obj.versions.base.IOS.expandableDetails.ctas = [];
502
+ const cta = {
503
+ actionText: ios['secondary-cta-1-label'],
504
+ actionLabel: ios['secondary-cta-1-action'],
505
+ actionLabel2: ios['secondary-cta-1-action2'],
506
+ type: ios['cta-deeplink-secondary-cta-1'] && (ios['cta-deeplink-secondary-cta-1'].toLowerCase() === "deeplink" ? "DEEP_LINK" : "EXTERNAL_URL"),
507
+ 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']),
508
+ ioscdeepLinkName: this.getLinkName(ios['cta-deeplink-secondary-cta-1-select']),
509
+ templateCtaId: ios['secondary-cta-1-table'] ? ios['secondary-cta-1-table'].ctaTemplateDetails[0].id : undefined,
510
+ };
511
+ if (this.props.location.query.type === 'embedded') {
512
+ delete cta.ioscdeepLinkName;
513
+ }
514
+ obj.versions.base.IOS.expandableDetails.ctas.push(cta);
515
+ if (obj.versions.base.IOS.expandableDetails.ctas[obj.versions.base.IOS.expandableDetails.ctas.length - 1].type === "DEEP_LINK") {
516
+ const params = _.map(ios, (field, key) => {
517
+ let actionLink;
518
+ if (key.indexOf('custom-value') > -1 && key.indexOf('cta-deeplink-secondary-cta-1-select') > -1) {
519
+ const param = key.replace('custom-value-', "").replace('-cta-deeplink-secondary-cta-1-select2', '');
520
+ actionLink = field !== "" ? `${param}=${field}` : undefined;
521
+ }
522
+ return actionLink;
523
+ }).filter((actionLink) => actionLink);
524
+ if (params.length) {
525
+ 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('&')}`;
526
+ }
527
+ }
528
+ }
529
+ return obj;
530
+ };
531
+
532
+ setFormValidity = (isFormValid) => {
533
+ this.setState({isFormValid});
534
+ };
535
+
536
+ getMappedEvent = (id, event) => {
537
+ const map = this.state.eventsMap;
538
+ if (!map[id] || !map[id][event]) {
539
+ console.log(`error map[id] ${map[id]}` );
540
+ }
541
+ return map[id][event];
542
+ };
543
+
544
+ getCurrentWindow = (e) => {
545
+ console.log('in line create', e);
546
+ const response = {
547
+ action: e.action,
548
+ value: 'edit',
549
+ direction: e.value,
550
+ };
551
+ parent.postMessage(JSON.stringify(response), '*');
552
+ };
553
+
554
+ getFormData = (e) => {
555
+ console.log('posting final result', this.state.formData);
556
+ const response = {
557
+ action: "getFormData",
558
+ value: this.getTransformedData(this.state.formData),
559
+ validity: this.state.isFormValid,
560
+ };
561
+ console.log('GetForm Data ', response);
562
+ this.setState({checkValidation: true});
563
+ if (e) {
564
+ e.source.postMessage(JSON.stringify(response), e.origin);
565
+ }
566
+ return response;
567
+ };
568
+
569
+
570
+ setEditState(data, schema) {
571
+ console.log('Test 1234', data, schema);
572
+ const tabCount = Object.keys(data.versions.base).length;
573
+ const formData = {};
574
+ if (this.props.location.query.type === 'embedded' && this.props.location.query.module === "loyalty") {
575
+ formData["line-accounts"] = this.state.formData["line-accounts"];
576
+ formData['line-template'] = this.state.formData['line-template'];
577
+ }
578
+ formData['template-name'] = data.name;
579
+ const androidData = data.versions.base.ANDROID;
580
+ const iosData = data.versions.base.IOS;
581
+ const android = {};
582
+ android[`message-title`] = androidData ? androidData.title : '';
583
+ android['message-editor'] = androidData ? androidData.message : '';
584
+ if (data.mode === "image") {
585
+ android.image = "";
586
+ }
587
+ formData[0] = android;
588
+ const ios = {};
589
+ ios[`message-title2`] = iosData ? iosData.title : '';
590
+ ios['message-editor2'] = iosData ? iosData.message : '';
591
+ if (data.mode === "image") {
592
+ ios.image = "";
593
+ }
594
+ if (iosData) {
595
+ if (iosData.cta) {
596
+ ios['cta-deeplink2'] = iosData.cta.type === "DEEP_LINK" ? "Deeplink" : "External Link";
597
+ if (iosData.cta.type === "DEEP_LINK") {
598
+ ios['cta-deeplink2-select'] = iosData ? iosData.cta.actionLink : '';
599
+ } else {
600
+ ios['cta-deeplink2-text'] = iosData ? iosData.cta.actionLink : '';
601
+ }
602
+ if (iosData.cta.type === "DEEP_LINK") {
603
+ const link = ios['cta-deeplink2-select'].split('?')[0];
604
+ let params = ios['cta-deeplink2-select'].split('?');
605
+ if (params[1]) {
606
+ params = params[1].split('&');
607
+ _.forEach(params, (param) => {
608
+ ios[`custom-value-${param.split('=')[0]}-cta-deeplink2-select`] = param.split('=')[1];
609
+ });
610
+ }
611
+ ios['cta-deeplink2-select'] = link;
612
+ }
613
+ }
614
+ if (iosData.expandableDetails && iosData.expandableDetails.image) {
615
+ ios.image = iosData.expandableDetails.image;
616
+ }
617
+ if (iosData.expandableDetails && iosData.expandableDetails.ctas && iosData.expandableDetails.ctas.length) {
618
+ if (iosData.expandableDetails.ctas[0].type) {
619
+ ios['cta-deeplink-secondary-cta-1'] = iosData.expandableDetails.ctas[0].type === "DEEP_LINK" ? "Deeplink" : "External Link";
620
+ }
621
+ if (iosData.expandableDetails.ctas[0].type === "DEEP_LINK") {
622
+ ios['cta-deeplink-secondary-cta-1-select2'] = iosData.expandableDetails.ctas[0].actionLink;
623
+ } else {
624
+ ios['cta-deeplink-secondary-cta-1-text2'] = iosData.expandableDetails.ctas[0].actionLink;
625
+ }
626
+ ios['secondary-cta-1-label'] = iosData.expandableDetails.ctas[0].actionText;
627
+ if (iosData.expandableDetails.ctas[0].type === "DEEP_LINK" && ios['cta-deeplink-secondary-cta-1-select2']) {
628
+ const link = ios['cta-deeplink-secondary-cta-1-select2'].split('?')[0];
629
+ const paramsIos = ios['cta-deeplink-secondary-cta-1-select2'].split('?')[1] && ios['cta-deeplink-secondary-cta-1-select2'].split('?')[1].split('&');
630
+ ios['cta-deeplink-secondary-cta-1-select2'] = link;
631
+ _.forEach(paramsIos, (param) => {
632
+ ios[`custom-value-${param.split('=')[0]}-cta-deeplink-secondary-cta-1-select2`] = param.split('=')[1];
633
+ });
634
+ }
635
+ ios['secondary-cta-1-action'] = iosData.expandableDetails.ctas[0].actionLabel;
636
+ if (iosData.expandableDetails.ctas[0].actionLabel2) {
637
+ ios['secondary-cta-1-action2'] = iosData.expandableDetails.ctas[0].actionLabel2;
638
+ }
639
+ }
640
+ }
641
+ formData[1] = ios;
642
+ formData.base = formData[0];
643
+ formData[0].base = true;
644
+ console.log('form data after discarding ', formData);
645
+ this.getSchemaForFormData(formData, schema);
646
+ this.setState({tabCount, formData, editData: data, currentTab: 1});
647
+ }
648
+
649
+ getSchemaForFormData = (formData, inputSchema) => {
650
+ const schema = inputSchema;
651
+ this.setState({schema, isSchemaChanged: true});
652
+ this.injectEvents(schema);
653
+ };
654
+
655
+ setModalContent = (type) => {
656
+ if (type === 'ios') {
657
+ const modalContent = {
658
+ title: this.props.intl.formatMessage(messages.alertMessage),
659
+ body: this.props.intl.formatMessage(messages.androidNotConfigured),
660
+ type: 'confirm',
661
+ id: 'ios',
662
+ };
663
+ this.setState({modalContent, showModal: true});
664
+ } else if (type === 'android') {
665
+ const modalContent = {
666
+ title: this.props.intl.formatMessage(messages.alertMessage),
667
+ body: this.props.intl.formatMessage(messages.iosNotConfigured),
668
+ type: 'confirm',
669
+ id: 'android',
670
+ };
671
+ this.setState({modalContent, showModal: true});
672
+ }
673
+ };
674
+
675
+ openNotificationWithIcon = (type, message) => {
676
+ const dur = (type === 'error' || type === 'warning') ? null : 5;
677
+ notification[type]({
678
+ message: (`${type.toUpperCase()} ! ! ! `),
679
+ description: message, //'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
680
+ duration: dur,
681
+ });
682
+ };
683
+
684
+ handleCancelModal = () => {
685
+ this.setState({showModal: false});
686
+ };
687
+
688
+ insertAtCursor = (field, myValue, currentTab) => {
689
+ //IE support
690
+ const myField = field;
691
+ if (document.selection) {
692
+ myField.focus();
693
+ const sel = document.selection.createRange();
694
+ sel.text = myValue;
695
+ } else if (myField.selectionStart || myField.selectionStart === '0') { //MOZILLA and others
696
+ const startPos = myField.selectionStart;
697
+ const endPos = myField.selectionEnd;
698
+ myField.value = myField.value.substring(0, startPos)
699
+ + myValue
700
+ + myField.value.substring(endPos, myField.value.length);
701
+ myField.selectionStart = startPos + myValue.length;
702
+ myField.selectionEnd = startPos + myValue.length;
703
+ } else {
704
+ myField.value += myValue;
705
+ }
706
+ const formData = _.cloneDeep(this.state.formData);
707
+ formData[currentTab - 1][field.id] = myField.value;
708
+ this.setState({formData});
709
+ };
710
+
711
+ selectCtaIos = (selectedConfig) => {
712
+ this.showSelectedIosCta(null, null, null, selectedConfig);
713
+ };
714
+
715
+ uploadImage = (data) => {
716
+ if (data.fileParams.error) {
717
+ const message = getMessageObject('error', this.props.intl.formatMessage(messages['File size cannot be more than 5mb']), true);
718
+ this.props.globalActions.addMessageToQueue(message);
719
+ } else {
720
+ const name = data.file.name.split('.');
721
+ const blob = data.file.slice(0, -1, 'image');
722
+ const newFile = new File([blob], `${name[0]}${Date.now()}.${name[1]}`, {type: 'image'});
723
+ this.props.actions.uploadAsset(newFile, data.type, data.fileParams);
724
+ }
725
+ };
726
+
727
+ startTemplateCreation = (data) => {
728
+ console.log('startTemplateCreation', data);
729
+ if (!data.edit) {
730
+ this.setState({injectedTags: data.tags});
731
+ this.props.globalActions.setInjectedTags(data.tags);
732
+ }
733
+ };
734
+
735
+ discardValues = () => {
736
+ console.log('discarding', this.props.Edit);
737
+ this.resetSchema();
738
+ this.setState({
739
+ formData: {},
740
+ tabCount: 1,
741
+ currentTab: 1,
742
+ editData: {},
743
+ }, () => {
744
+ const schema = this.props.Edit.templateDetails.mode === "image" ? this.state.fullSchema.imageSchema : this.state.fullSchema.textSchema;
745
+ this.setEditState(this.props.Edit.templateDetails, schema);
746
+ });
747
+ };
748
+
749
+ resetSchema = () => {
750
+ this.setState({ schema: this.state.initialState ? this.state.initialState : this.state.schema});
751
+ };
752
+
753
+ showNext = () => {
754
+ const response = {
755
+ action: "showNext",
756
+ value: true,
757
+ };
758
+ parent.postMessage(JSON.stringify(response), '*');
759
+ };
760
+
761
+ moveToTemplates = () => {
762
+ console.log('in move to Templates');
763
+ const modalContent = {
764
+ title: this.props.intl.formatMessage(messages.alertMessage),
765
+ body: this.props.intl.formatMessage(messages.goBackTemporaryChangesLost),
766
+ type: 'confirm',
767
+ id: 'template-back-confirm-modal',
768
+ show: true,
769
+ };
770
+ this.setState({modalContent, showModal: true});
771
+ };
772
+
773
+ injectSections = (sections) => {
774
+ _.forEach(sections, (section) => {
775
+ let temp = section;
776
+ if (temp.type === 'col-label') {
777
+ temp = this.injectColLabelSection(temp);
778
+ } else if (section.type === 'multicols') {
779
+ temp = this.injectMultiColSection(temp);
780
+ } else if (section.type === 'parent') {
781
+ temp = this.injectSections(temp.childSections);
782
+ }
783
+ });
784
+ return sections;
785
+ };
786
+ injectMultiColSection = (section) => {
787
+ _.forEach(section.inputFields, (inputField) => {
788
+ _.forEach(inputField.cols, (col) => {
789
+ const temp = col;
790
+ if (temp.type === 'popover') {
791
+ temp.content.sections = this.injectSections(temp.content.sections);
792
+ temp.value.sections = this.injectSections(temp.value.sections);
793
+ return true;
794
+ }
795
+ temp.injectedEvents = {};
796
+ temp.className = temp.className ? temp.className : '';
797
+ if (this.props.location.query.type === 'embedded' && (temp.type === "div" || temp.type === "icon" || temp.type === "tag-list") && (temp.supportedEvents)) {
798
+ temp.className = `${temp.className} hide`;
799
+ }
800
+ if (this.props.location.query.type === 'embedded' && (temp.type === "input" || temp.type === "textarea" || temp.type === "radioGroup")) {
801
+ temp.className = `${temp.className} disabled`;
802
+ temp.disabled = true;
803
+ }
804
+ if (this.props.location.query.type === 'embedded' && temp.id === "line-template" ) {
805
+ temp.options = this.state.templateOptions ? this.state.templateOptions : [];
806
+ }
807
+ if (this.props.location.query.type === 'embedded' && temp.id === "line-accounts" ) {
808
+ temp.options = this.state.templateOptions ? this.state.accountsOptions : [];
809
+ }
810
+ if (temp.id === "mobile-push-preview" && this.props.Templates.selectedWeChatAccount && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
811
+ temp.content.appName = this.props.Templates.selectedWeChatAccount.name;
812
+ }
813
+ _.forEach(col.supportedEvents, (event) => {
814
+ console.log('injected event for ', col, event, this.getMappedEvent(col.id, event));
815
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
816
+ });
817
+ return true;
818
+ });
819
+ });
820
+ _.forEach(section.actionFields, (actionField) => {
821
+ _.forEach(actionField.cols, (col) => {
822
+ const temp = col;
823
+ temp.disabled = this.props.location.query.type === 'embedded';
824
+ if (temp.type === 'popover') {
825
+ temp.content.sections = this.injectSections(temp.content.sections);
826
+ temp.value.sections = this.injectSections(temp.value.sections);
827
+ return true;
828
+ }
829
+ temp.injectedEvents = {};
830
+ _.forEach(col.supportedEvents, (event) => {
831
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
832
+ });
833
+ return true;
834
+ });
835
+ });
836
+ return section;
837
+ };
838
+
839
+ saveFormData = (formData) => {
840
+ console.log('Saving form data', formData, this.state.tabCount);
841
+ const obj = this.getTransformedData(formData);
842
+ console.log('obj', obj);
843
+ this.props.actions.editTemplate(obj);
844
+ };
845
+
846
+ handleFrameTasks = (e) => {
847
+ // console.log('data listened to is', e.data);
848
+ const type = e.data;
849
+ console.log('data type', typeof type);
850
+ if (typeof type === 'object') {
851
+ // console.log('received something', type);
852
+ const action = type.action;
853
+ switch (action) {
854
+ case "startTemplateCreation":
855
+ this.startTemplateCreation(type.value);
856
+ break;
857
+ case "startLoading":
858
+ this.startLoading(type.edit);
859
+ break;
860
+ case "getCurrentWindow":
861
+ this.getCurrentWindow(type);
862
+ break;
863
+ default:
864
+ break;
865
+ }
866
+ } else {
867
+ switch (type) {
868
+ case "getFormData":
869
+ this.getFormData(e);
870
+ break;
871
+ case "startTemplateCreation":
872
+ console.log('Starting to create template');
873
+ //this.getFormData(e);
874
+ break;
875
+ case "moveToTemplates":
876
+ console.log('moving to templates');
877
+ this.moveToTemplates();
878
+ break;
879
+ case "validateContent":
880
+ console.log('validating Content');
881
+ this.validateContent(e);
882
+ break;
883
+ default:
884
+ break;
885
+ }
886
+ }
887
+ };
888
+
889
+ cancelTemplate = () => {
890
+ const type = this.props.location.query.type;
891
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
892
+ this.props.router.push({
893
+ pathname: `/line/`,
894
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
895
+ });
896
+ };
897
+
898
+ injectContainer = (container) => {
899
+ const temp = container;
900
+ if (temp.type === 'tabs') {
901
+ temp.injectedEvents = {};
902
+ _.forEach(temp.supportedEvents, (event) => {
903
+ temp.injectedEvents[event] = this.getMappedEvent(temp.id, event);
904
+ });
905
+ _.forEach(temp.panes, (pane) => {
906
+ const tempPane = pane;
907
+ tempPane.sectionsHeaders = this.injectSections(tempPane.sectionsHeaders);
908
+ tempPane.sections = this.injectSections(tempPane.sections);
909
+ });
910
+ }
911
+ return temp;
912
+ };
913
+
914
+ injectEvents = (schema) => {
915
+ const temp = schema;
916
+ if (this.injectSections) {
917
+ temp.standalone.sections = this.injectSections(temp.standalone.sections);
918
+ }
919
+ _.forEach(temp.containers, (container) => {
920
+ let tempContainer = container;
921
+ tempContainer = this.injectContainer(tempContainer);
922
+ return tempContainer;
923
+ });
924
+ console.log('final injected schema', schema);
925
+ this.setState({schema}, () => {
926
+ this.removeStandAlone();
927
+ });
928
+ return schema;
929
+ };
930
+
931
+ removeStandAlone = () => {
932
+ const schema = _.cloneDeep(this.state.schema);
933
+ if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty') {
934
+ if (schema.standalone.sections.length === 2) {
935
+ schema.standalone.sections.splice(0, 1);
936
+ }
937
+ } else if (this.props.location.query.type === 'embedded' && typeof this.props.location.query.module !== 'undefined') {
938
+ delete schema.standalone;
939
+ } else {
940
+ schema.standalone.sections.splice(1, 1);
941
+ }
942
+ this.setState({ schema });
943
+ };
944
+
945
+ handleOnTagsContextChange = (data) => {
946
+ console.log('parent tags context', data);
947
+ const query = {
948
+ layout: 'line',
949
+ type: 'TAG',
950
+ context: (data || '').toLowerCase() === 'all' ? 'default' : (data || '').toLowerCase(),
951
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
952
+ };
953
+ this.props.globalActions.fetchSchemaForEntity(query);
954
+ };
955
+
956
+ render() {
957
+ const schema = this.state.schema;
958
+ const spinning = 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)));
959
+ let tags = this.props.metaEntities && this.props.metaEntities.tags ? this.props.metaEntities.tags.standard : [];
960
+ if (this.props.supportedTags) {
961
+ tags = this.props.supportedTags;
962
+ }
963
+ return (
964
+ <div className="line-edit">
965
+ <Spin spinning={spinning}>
966
+ {<Row style={{marginBottom: '16px', marginLeft: '-40px'}}>
967
+ <Col offset={1}>
968
+ {this.props.location.query.type !== "embedded" &&
969
+ <Breadcrumb>
970
+ <BreadcrumbItem>{this.props.intl.formatMessage(messages.Campaigns)}</BreadcrumbItem>
971
+ <BreadcrumbItem>{this.props.intl.formatMessage(messages.Creatives)}</BreadcrumbItem>
972
+ <BreadcrumbItem>{this.props.intl.formatMessage(messages.mobilePush)}</BreadcrumbItem>
973
+ </Breadcrumb>
974
+ }
975
+ </Col>
976
+ </Row>}
977
+ <Row>
978
+ <Col>
979
+ <FormBuilder
980
+ schema={schema}
981
+ onSubmit={this.saveFormData}
982
+ onChange={this.onFormDataChange}
983
+ formData={_.cloneDeep(this.state.formData)}
984
+ currentTab={this.state.currentTab}
985
+ parent={this}
986
+ location={this.props.location}
987
+ isEdit
988
+ tabCount={2}
989
+ iosCtasData={this.state.iosCtasData}
990
+ tags={tags}
991
+ injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
992
+ onFormValidityChange={this.setFormValidity}
993
+ usingTabContainer
994
+ checkValidation={this.state.checkValidation}
995
+ onContextChange={this.handleOnTagsContextChange}
996
+ showModal={this.state.showModal}
997
+ iframeParent={parent}
998
+ router={this.props.router}
999
+ isSchemaChanged={this.state.isSchemaChanged}
1000
+ handleCancelModal={this.handleCancelModal}
1001
+ modal={this.state.modalContent}
1002
+ setModalContent={this.setModalContent}
1003
+ />
1004
+ </Col>
1005
+ </Row>
1006
+ </Spin>
1007
+ </div>
1008
+ );
1009
+ }
1010
+ }
1011
+
1012
+ Edit.propTypes = {
1013
+ actions: PropTypes.object.isRequired,
1014
+ Edit: PropTypes.object,
1015
+ params: PropTypes.object,
1016
+ router: PropTypes.object,
1017
+ location: PropTypes.object,
1018
+ globalActions: PropTypes.object,
1019
+ templatesActions: PropTypes.object,
1020
+ Templates: PropTypes.object,
1021
+ metaEntities: PropTypes.object,
1022
+ templateDetails: PropTypes.object,
1023
+ intl: intlShape.isRequired,
1024
+ templateData: PropTypes.object,
1025
+ getDefaultTags: PropTypes.string,
1026
+ supportedTags: PropTypes.array,
1027
+ injectedTags: PropTypes.object,
1028
+ };
1029
+
1030
+ const mapStateToProps = createStructuredSelector({
1031
+ Edit: makeSelectEdit(),
1032
+ editResponse: makeSelectEditResponse(),
1033
+ templateDetails: makeSelectTemplateDetailsResponse(),
1034
+ metaEntities: makeSelectMetaEntities(),
1035
+ Templates: makeSelectTemplates(),
1036
+ injectedTags: setInjectedTags(),
1037
+ });
1038
+
1039
+ function mapDispatchToProps(dispatch) {
1040
+ return {
1041
+ actions: bindActionCreators(actions, dispatch),
1042
+ templatesActions: bindActionCreators(templatesActions, dispatch),
1043
+ };
1044
+ }
1045
+
1046
+ export default withCreatives({
1047
+ WrappedComponent: Edit,
1048
+ mapStateToProps,
1049
+ mapDispatchToProps,
1050
+ userAuth: false,
1051
+ });