@capillarytech/creatives-library 2.0.77 → 2.0.78

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 (99) hide show
  1. package/components/EmailPreview/assets/images/iPad.svg +10 -0
  2. package/components/EmailPreview/assets/images/mobile.png +0 -0
  3. package/components/FormBuilder/test +1845 -0
  4. package/containers/CallTask/_callTask.scss +5 -0
  5. package/containers/CallTask/actions.js +15 -0
  6. package/containers/CallTask/constants.js +7 -0
  7. package/containers/CallTask/index.js +141 -0
  8. package/containers/CallTask/messages.js +21 -0
  9. package/containers/CallTask/reducer.js +23 -0
  10. package/containers/CallTask/sagas.js +11 -0
  11. package/containers/CallTask/selectors.js +25 -0
  12. package/containers/CallTask/tests/actions.test.js +18 -0
  13. package/containers/CallTask/tests/index.test.js +10 -0
  14. package/containers/CallTask/tests/reducer.test.js +9 -0
  15. package/containers/CallTask/tests/sagas.test.js +15 -0
  16. package/containers/CallTask/tests/selectors.test.js +10 -0
  17. package/containers/ChannelTemplates/actions.js +20 -0
  18. package/containers/ChannelTemplates/constants.js +8 -0
  19. package/containers/ChannelTemplates/index.js +48 -0
  20. package/containers/ChannelTemplates/messages.js +13 -0
  21. package/containers/ChannelTemplates/reducer.js +34 -0
  22. package/containers/ChannelTemplates/sagas.js +32 -0
  23. package/containers/ChannelTemplates/selectors.js +25 -0
  24. package/containers/ChannelTemplates/tests/actions.test.js +18 -0
  25. package/containers/ChannelTemplates/tests/index.test.js +10 -0
  26. package/containers/ChannelTemplates/tests/reducer.test.js +9 -0
  27. package/containers/ChannelTemplates/tests/sagas.test.js +15 -0
  28. package/containers/ChannelTemplates/tests/selectors.test.js +10 -0
  29. package/containers/CreativesContainer/SlideBoxContent.js +248 -0
  30. package/containers/CreativesContainer/SlideBoxFooter.js +38 -0
  31. package/containers/CreativesContainer/SlideBoxHeader.js +65 -0
  32. package/containers/CreativesContainer/actions.js +27 -0
  33. package/containers/CreativesContainer/constants.js +13 -0
  34. package/containers/CreativesContainer/index.js +418 -0
  35. package/containers/CreativesContainer/index.scss +27 -0
  36. package/containers/CreativesContainer/messages.js +17 -0
  37. package/containers/CreativesContainer/reducer.js +29 -0
  38. package/containers/CreativesContainer/sagas.js +11 -0
  39. package/containers/CreativesContainer/selectors.js +30 -0
  40. package/containers/CreativesContainer/tests/actions.test.js +18 -0
  41. package/containers/CreativesContainer/tests/index.test.js +10 -0
  42. package/containers/CreativesContainer/tests/reducer.test.js +9 -0
  43. package/containers/CreativesContainer/tests/sagas.test.js +15 -0
  44. package/containers/CreativesContainer/tests/selectors.test.js +10 -0
  45. package/containers/EmailWrapper/actions.js +15 -0
  46. package/containers/EmailWrapper/constants.js +7 -0
  47. package/containers/EmailWrapper/index.js +238 -0
  48. package/containers/EmailWrapper/messages.js +57 -0
  49. package/containers/EmailWrapper/reducer.js +23 -0
  50. package/containers/EmailWrapper/sagas.js +11 -0
  51. package/containers/EmailWrapper/selectors.js +25 -0
  52. package/containers/EmailWrapper/tests/actions.test.js +18 -0
  53. package/containers/EmailWrapper/tests/index.test.js +10 -0
  54. package/containers/EmailWrapper/tests/reducer.test.js +9 -0
  55. package/containers/EmailWrapper/tests/sagas.test.js +15 -0
  56. package/containers/EmailWrapper/tests/selectors.test.js +10 -0
  57. package/containers/MobilePush/commonMethods.js +249 -0
  58. package/containers/MobilePush/eventsMap.js +127 -0
  59. package/containers/MobilePush/initialSchema.js +1739 -0
  60. package/containers/MobilepushWrapper/_mobilepushWrapper.scss +18 -0
  61. package/containers/MobilepushWrapper/index.js +97 -0
  62. package/containers/MobilepushWrapper/messages.js +25 -0
  63. package/containers/MobilepushWrapper/tests/index.test.js +10 -0
  64. package/containers/TemplatesV2/_templatesV2.scss +5 -0
  65. package/containers/TemplatesV2/actions.js +16 -0
  66. package/containers/TemplatesV2/constants.js +10 -0
  67. package/containers/TemplatesV2/index.js +207 -0
  68. package/containers/TemplatesV2/messages.js +29 -0
  69. package/containers/TemplatesV2/selectors.js +25 -0
  70. package/containers/TemplatesV2/tests/actions.test.js +18 -0
  71. package/containers/TemplatesV2/tests/index.test.js +10 -0
  72. package/containers/TemplatesV2/tests/reducer.test.js +9 -0
  73. package/containers/TemplatesV2/tests/sagas.test.js +15 -0
  74. package/containers/TemplatesV2/tests/selectors.test.js +10 -0
  75. package/containers/WeChat/RichmediaTemplates/Create/testschema.js +379 -0
  76. package/containers/WeChat/_wechat.scss +8 -0
  77. package/containers/WeChat/actions.js +52 -0
  78. package/containers/WeChat/constants.js +28 -0
  79. package/containers/WeChat/index.js +1635 -0
  80. package/containers/WeChat/messages.js +73 -0
  81. package/containers/WeChat/reducer.js +74 -0
  82. package/containers/WeChat/sagas.js +86 -0
  83. package/containers/WeChat/selectors.js +25 -0
  84. package/containers/WeChat/tests/actions.test.js +18 -0
  85. package/{components/SmsPreviewV2 → containers/WeChat}/tests/index.test.js +2 -2
  86. package/containers/WeChat/tests/reducer.test.js +9 -0
  87. package/containers/WeChat/tests/sagas.test.js +15 -0
  88. package/containers/WeChat/tests/selectors.test.js +10 -0
  89. package/package.json +1 -1
  90. package/v2Containers/CreativesContainer/SlideBoxContent.js +1 -0
  91. package/v2Containers/CreativesContainer/SlideBoxHeader.js +11 -2
  92. package/v2Containers/CreativesContainer/index.js +4 -0
  93. package/v2Containers/CreativesContainer/messages.js +1 -1
  94. package/v2Containers/MobilePush/Edit/index.js +1 -3
  95. package/v2Containers/MobilepushWrapper/index.js +3 -1
  96. package/assets/android-message-gui-2.svg +0 -55
  97. package/components/SmsPreviewV2/_smsPreviewV2.scss +0 -353
  98. package/components/SmsPreviewV2/index.js +0 -69
  99. package/components/SmsPreviewV2/messages.js +0 -13
@@ -0,0 +1,1635 @@
1
+ /*
2
+ *
3
+ * WeChat
4
+ *
5
+ */
6
+
7
+ import PropTypes from 'prop-types';
8
+
9
+ import React from 'react';
10
+ import { connect } from 'react-redux';
11
+ import { bindActionCreators } from 'redux';
12
+ import Helmet from 'react-helmet';
13
+ import { injectIntl, intlShape } from 'react-intl';
14
+ import { createStructuredSelector } from 'reselect';
15
+ import { Row, Col, Spin } from 'antd';
16
+ import _ from 'lodash';
17
+ import { makeSelectTemplates } from '../Templates/selectors';
18
+ import { makeSelectMetaEntities } from '../Cap/selectors';
19
+ import makeSelectWeChat from './selectors';
20
+ import messages from './messages';
21
+ import * as actions from './actions';
22
+ import FormBuilder from '../../components/FormBuilder';
23
+ import { UserIsAuthenticated } from '../../utils/authWrapper';
24
+ import * as globalActions from '../../containers/Cap/actions';
25
+ import * as templateActions from '../../containers/Templates/actions';
26
+ import {getMessageObject} from '../../utils/messageUtils';
27
+ // import SlideBox from '../../components/SlideBox';
28
+ // import PageHeader from '../../components/PageHeader';
29
+ import './_wechat.scss';
30
+ import callNativeEvent from '../../utils/callNativeEvent';
31
+
32
+ // const Option = Select.Option;
33
+
34
+ export class WeChat extends React.Component { // eslint-disable-line react/prefer-stateless-function
35
+ constructor(props) {
36
+ super(props);
37
+ this.state = {
38
+ schema: {},
39
+ // schema:
40
+ // {
41
+ // standalone: {
42
+ // sections: [
43
+ // {
44
+ // type: "parent",
45
+ // width: 24,
46
+ // rowStyle: {
47
+ // height: '100%',
48
+ // },
49
+ // childSections: [
50
+ // {
51
+ // type: "multicols",
52
+ // inputFields: [
53
+ // {
54
+ // cols: [
55
+ // {
56
+ // id: "template-header",
57
+ // metaType: "label",
58
+ // value: 'Template mapping',
59
+ // primitive: true,
60
+ // type: "div",
61
+ // width: 9,
62
+ // offset: 0,
63
+ // onlyDisplay: true,
64
+ // colStyle: {
65
+ // flex: 1,
66
+ // color: '#323B4E',
67
+ // fontFamily: 'proxima-nova',
68
+ // fontWeight: '600',
69
+ // lineHeight: '32px',
70
+ // fontSize: '24px',
71
+ // display: (this.props.location.query.type === 'embedded' ? 'none' : 'block'),
72
+ // },
73
+ // },
74
+ // {
75
+ // id: "discard-button",
76
+ // width: 3,
77
+ // offset: 8,
78
+ // metaType: "submit-button",
79
+ // colStyle: {
80
+ // // marginLeft: '47.833%',
81
+ // textAlign: 'right',
82
+ // paddingRight: '12px',
83
+ // display: (this.props.location.query.type === 'embedded' ? 'none' : 'block'),
84
+ // },
85
+ // type: "button",
86
+ // buttonType: "cancel",
87
+ // value: 'Discard',
88
+ // customComponent: false,
89
+ // standalone: true,
90
+ // styling: "semantic",
91
+ // order: 3,
92
+ // fluid: false,
93
+ // submitAction: "discardValues",
94
+ // supportedEvents: [
95
+ // 'discardValues',
96
+ // ],
97
+ // },
98
+ // {
99
+ // id: "cancel-button",
100
+ // width: 2,
101
+ // // offset: 11,
102
+ // metaType: "submit-button",
103
+ // colStyle: {
104
+ // textAlign: 'center',
105
+ // width: '9%',
106
+ // display: (this.props.location.query.type === 'embedded' ? 'none' : 'block'),
107
+ // },
108
+ // type: "button",
109
+ // buttonType: "cancel",
110
+ // value: 'Cancel',
111
+ // customComponent: false,
112
+ // standalone: true,
113
+ // styling: "semantic",
114
+ // order: 3,
115
+ // fluid: false,
116
+ // submitAction: "cancelTemplate",
117
+ // supportedEvents: [
118
+ // 'cancelTemplate',
119
+ // ],
120
+ // },
121
+ // {
122
+ // id: "save-button",
123
+ // width: 2,
124
+ // metaType: "submit-button",
125
+ // colStyle: {
126
+ // textAlign: 'right',
127
+ // width: '7%',
128
+ // display: (this.props.location.query.type === 'embedded' ? 'none' : 'block'),
129
+ // },
130
+ // type: "button",
131
+ // buttonType: "primary",
132
+ // value: 'Save',
133
+ // customComponent: false,
134
+ // styling: "semantic",
135
+ // order: 3,
136
+ // fluid: false,
137
+ // standalone: true,
138
+ // submitAction: "saveFormData",
139
+ // supportedEvents: [
140
+ // 'saveFormData',
141
+ // ],
142
+ // },
143
+ // ],
144
+ // },
145
+ // ],
146
+ // },
147
+ // {
148
+ // width: 24,
149
+ // type: 'parent',
150
+ // rowStyle: {
151
+ // height: '100%',
152
+ // border: '1px solid #d9d9d9',
153
+ // marginTop: '16px',
154
+ // },
155
+ // childSections: [
156
+ // {
157
+ // colStyle: {
158
+ // paddingTop: '16px',
159
+ // borderRight: '1px solid #d9d9d9',
160
+ // height: '100%',
161
+ // // overflowY: 'auto',
162
+ // },
163
+ // width: 15,
164
+ // type: 'parent',
165
+ // childSections: [
166
+ // {
167
+ // type: "col-label",
168
+ // inputFields: [
169
+ // {
170
+ // id: "wechat-accounts",
171
+ // label: 'Account Id',
172
+ // labelStyle: {
173
+ // backgroundColor: 'white',
174
+ // textAlign: 'left',
175
+ // color: '#333333',
176
+ // lineHeight: '24px',
177
+ // fontSize: '14px',
178
+ // fontWeight: '400',
179
+ // fontFamily: 'open-sans',
180
+ // fontStyle: 'normal',
181
+ // padding: '.5em .833em',
182
+ // display: (this.props.location.query.module === 'loyalty' ? 'block' : 'none'),
183
+ // },
184
+ // placeholder: 'Select Wechat Account',
185
+ // type: "select", //Resembles component to be used
186
+ // options: [],
187
+ // metaType: "text",
188
+ // datatype: "string",
189
+ // required: true,
190
+ // fluid: true,
191
+ // style: {
192
+ // fontSize: '14px',
193
+ // fontFamily: 'open-sans',
194
+ // fontStyle: 'normal',
195
+ // // fontWeight: 600,
196
+ // marginBottom: '16px',
197
+ // display: (this.props.location.query.module === 'loyalty' ? 'block' : 'none'),
198
+ // },
199
+ // styling: "semantic",
200
+ // order: 1,
201
+ // width: 15,
202
+ // offSet: 6,
203
+ // customComponent: false,
204
+ // standalone: true,
205
+ // supportedEvents: [
206
+ // 'onSelect',
207
+ // ],
208
+ // },
209
+ // {
210
+ // id: "wechat-template",
211
+ // label: 'Template',
212
+ // labelStyle: {
213
+ // backgroundColor: 'white',
214
+ // textAlign: 'left',
215
+ // color: '#333333',
216
+ // lineHeight: '24px',
217
+ // fontSize: '14px',
218
+ // fontWeight: '400',
219
+ // fontFamily: 'open-sans',
220
+ // fontStyle: 'normal',
221
+ // padding: '.5em .833em',
222
+ // },
223
+ // placeholder: 'Select Wechat Template',
224
+ // type: "select", //Resembles component to be used
225
+ // options: [],
226
+ // metaType: "text",
227
+ // datatype: "string",
228
+ // required: true,
229
+ // fluid: true,
230
+ // disabled: (this.props.params.id && this.props.location.query.module !== 'loyalty'),
231
+ // style: {
232
+ // fontSize: '14px',
233
+ // fontFamily: 'open-sans',
234
+ // fontStyle: 'normal',
235
+ // // fontWeight: 600,
236
+ // marginBottom: '16px',
237
+ // },
238
+ // styling: "semantic",
239
+ // order: 1,
240
+ // width: 15,
241
+ // offSet: 6,
242
+ // customComponent: false,
243
+ // standalone: true,
244
+ // supportedEvents: [
245
+ // 'onSelect',
246
+ // ],
247
+ // },
248
+ // ],
249
+ // actionFields: [],
250
+ // },
251
+ // {
252
+ // type: "multicols",
253
+ // inputFields: [
254
+ // {
255
+ // cols: [],
256
+ // },
257
+ // ],
258
+ // },
259
+ // ],
260
+ // },
261
+ // {
262
+ // width: 8,
263
+ // type: 'multicols',
264
+ // colStyle: {
265
+ // paddingTop: '16px',
266
+ // height: '100%',
267
+ // },
268
+ // inputFields: [
269
+ // {
270
+ // cols: [
271
+ // {
272
+ // id: "sms-preview",
273
+ // type: "sms-preview", //Resembles component to be used
274
+ // customComponent: true,
275
+ // charCounterEnabled: false,
276
+ // customStyling: { padding: '0', overflowX: 'hidden' },
277
+ // style: {
278
+ // overflowX: 'hidden',
279
+ // },
280
+ // content: '',
281
+ // metaType: "preview",
282
+ // required: true,
283
+ // fluid: true,
284
+ // styling: "semantic",
285
+ // order: 1,
286
+ // width: 5,
287
+ // onlyDisplay: true,
288
+ // offset: 7,
289
+ // channel: 'WECHAT',
290
+ // },
291
+ // ],
292
+ // },
293
+ // ],
294
+ // },
295
+ // ],
296
+ // },
297
+ // ],
298
+ // },
299
+ // ],
300
+ // },
301
+ // containers: [],
302
+ // channel: "WECHAT",
303
+ // module: "Campaigns",
304
+ // },
305
+ baseSchema: {},
306
+ formData: {},
307
+ map: {
308
+ "discard-button": {
309
+ discardValues: this.discardValues,
310
+ },
311
+ "cancel-button": {
312
+ cancelTemplate: this.cancelTemplate,
313
+ },
314
+ "save-button": {
315
+ saveFormData: this.saveFormData,
316
+ },
317
+ "wechat-template": {
318
+ onSelect: this.selectWechatTemplate,
319
+ },
320
+ "wechat-accounts": {
321
+ onSelect: this.selectWechatAccount,
322
+ },
323
+ "template-link": {
324
+ onChange: this.setContent,
325
+ },
326
+ "is-internal-url": {
327
+ onChange: this.internalUrlChecked,
328
+ },
329
+ },
330
+ selectedTemplateTags: [],
331
+ isEdit: false,
332
+ editTemplateData: {},
333
+ isFormValid: true,
334
+ checkValidation: false,
335
+ injectedTags: {},
336
+ isLoading: true,
337
+ showModal: false,
338
+ modalContent: {
339
+ title: "Alert",
340
+ body: "Do you really want to go back? All your temporary changes will be lost!",
341
+ type: 'confirm',
342
+ id: 'template-back-confirm-modal',
343
+ },
344
+ };
345
+
346
+ this.saveFormData = this.saveFormData.bind(this);
347
+ this.onFormDataChange = this.onFormDataChange.bind(this);
348
+ this.setTemplateOptions = this.setTemplateOptions.bind(this);
349
+ this.cancelTemplate = this.cancelTemplate.bind(this);
350
+ this.setSelectedTemplateData = this.setSelectedTemplateData.bind(this);
351
+ this.discardValues = this.discardValues.bind(this);
352
+ this.internalUrlChecked = this.internalUrlChecked.bind(this);
353
+ this.getTagsFromContent = this.getTagsFromContent.bind(this);
354
+ this.onTagSelect = this.onTagSelect.bind(this);
355
+ this.insertAtCursor = this.insertAtCursor.bind(this);
356
+ this.setFormValidity = this.setFormValidity.bind(this);
357
+ this.setContent = this.setContent.bind(this);
358
+ this.prepareWeChatPreviewData = this.prepareWeChatPreviewData.bind(this);
359
+ this.setEditData = this.setEditData.bind(this);
360
+ this.maskTemplateUrl = this.maskTemplateUrl.bind(this);
361
+ this.unMaskTemplateUrl = this.unMaskTemplateUrl.bind(this);
362
+ this.resetState = this.resetState.bind(this);
363
+ this.resetSchema = this.resetSchema.bind(this);
364
+ this.handleFrameTasks = this.handleFrameTasks.bind(this);
365
+ this.getCurrentWindow = this.getCurrentWindow.bind(this);
366
+ this.startLoading = this.startLoading.bind(this);
367
+ this.startTemplateCreation = this.startTemplateCreation.bind(this);
368
+ this.selectWechatTemplate = this.selectWechatTemplate.bind(this);
369
+ this.removeActionButtons = this.removeActionButtons.bind(this);
370
+ this.setWechatAccountOptions = this.setWechatAccountOptions.bind(this);
371
+ this.selectWechatAccount = this.selectWechatAccount.bind(this);
372
+ this.moveToTemplates = this.moveToTemplates.bind(this);
373
+ this.injectMessages = this.injectMessages.bind(this);
374
+ this.hideSchemaElementsByModule = this.hideSchemaElementsByModule.bind(this);
375
+
376
+ this.injectEvents = this.injectEvents.bind(this);
377
+ this.injectSections = this.injectSections.bind(this);
378
+ this.injectContainer = this.injectContainer.bind(this);
379
+ this.injectParentSection = this.injectParentSection.bind(this);
380
+ this.injectColLabelSection = this.injectColLabelSection.bind(this);
381
+ this.injectMultiColSection = this.injectMultiColSection.bind(this);
382
+ this.getMappedEvent = this.getMappedEvent.bind(this);
383
+ this.showNext = this.showNext.bind(this);
384
+ this.updateSchema = false;
385
+ }
386
+
387
+ componentWillMount() {
388
+ const query = {
389
+ layout: 'WECHAT',
390
+ type: 'LAYOUT',
391
+ context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
392
+ };
393
+ this.props.globalActions.fetchSchemaForEntity(query);
394
+ this.props.actions.getWeCrmAccounts();
395
+ if (this.props.params.id) {
396
+ this.props.actions.getTemplateDetails(this.props.params.id);
397
+ this.setState({isEdit: true});
398
+ }
399
+ console.log("Mount Params ", this.props.Templates.selectedWeChatAccount, this.props.location.query.type);
400
+ if (this.props.Templates.selectedWeChatAccount || (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty')) {
401
+ if (this.props.Templates.selectedWeChatAccount) {
402
+ const params = {
403
+ name: '',
404
+ sortBy: 'Most Recent',
405
+ wecrmId: this.props.Templates.selectedWeChatAccount.configs.wecrm_app_id,
406
+ wecrmToken: this.props.Templates.selectedWeChatAccount.configs.wecrm_token,
407
+ originalId: this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier,
408
+ };
409
+ this.props.actions.getDefaultWeChatTemplates('wechat', params);
410
+ } else {
411
+ this.setWechatAccountOptions(this.props.WeChat.weCrmAccounts);
412
+ }
413
+ window.addEventListener("message", this.handleFrameTasks);
414
+ } else if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'outbound') {
415
+ console.log('Inside embedded Outbound');
416
+ } else {
417
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
418
+ const type = this.props.location.query.type;
419
+ this.props.router.push({
420
+ pathname: `/wechat`,
421
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
422
+ });
423
+ }
424
+ }
425
+
426
+ componentDidMount() {
427
+ console.log('added listener create,', this.props);
428
+ const query = {
429
+ layout: 'WECHAT',
430
+ type: 'LAYOUT',
431
+ context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
432
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
433
+ };
434
+ this.props.globalActions.fetchSchemaForEntity(query);
435
+
436
+ window.addEventListener("message", this.handleFrameTasks);
437
+ }
438
+
439
+ componentWillReceiveProps(nextProps) {
440
+ if (nextProps.isGetFormData) {
441
+ this.getFormData();
442
+ }
443
+ console.log('MetaEntity nextprops ', nextProps.metaEntities);
444
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && _.isEmpty(this.state.schema)) {
445
+ this.injectEvents(nextProps.metaEntities.layouts[0].definition);
446
+ const query = {
447
+ layout: 'WECHAT',
448
+ type: 'TAG',
449
+ context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
450
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
451
+ };
452
+ if (this.props.getDefaultTags) { // handling dynamic tags in library mode, but handling static and synamic tags in email and sms.
453
+ query.context = this.props.getDefaultTags;
454
+ }
455
+ this.props.globalActions.fetchSchemaForEntity(query);
456
+ }
457
+
458
+ if (nextProps.metaEntities && nextProps.metaEntities.layouts && nextProps.metaEntities.layouts.length > 0 && !_.isEmpty(this.state.schema)) {
459
+ if (nextProps.WeChat.weChatDefaultTemplate && !_.isEqual(nextProps.WeChat.weChatDefaultTemplate, this.props.WeChat.weChatDefaultTemplate)) {
460
+ this.injectEvents(this.state.schema);
461
+ if (nextProps.location.query.type === 'embedded' && nextProps.location.query.module === 'loyalty') {
462
+ this.setTemplateOptions(nextProps.WeChat.weChatTemplates);
463
+ } else {
464
+ this.setTemplateOptions(nextProps.WeChat.weChatDefaultTemplate);
465
+ }
466
+ }
467
+ if ((this.props.location.query.type === 'embedded' && (this.props.location.query.module === 'loyalty' || this.props.location.query.module === 'outbound')) && !_.isEmpty(nextProps.WeChat.templateDetails) && !_.isEqual(nextProps.WeChat.templateDetails, this.props.WeChat.templateDetails)) {
468
+ this.setState({editTemplateData: nextProps.WeChat.templateDetails}, () => {
469
+ if ( !_.isEmpty(this.state.baseSchema)) {
470
+ this.setEditData();
471
+ } else {
472
+ this.setState({baseSchema: _.cloneDeep(this.state.schema)}, () => {
473
+ this.setEditData();
474
+ });
475
+ }
476
+ });
477
+ }
478
+ // has to be un commented when wechat edit is implemented in embedded mode.
479
+ // if (nextProps.location.query.type === "embedded" && nextProps.location.query.module === "library" && nextProps.templateData && nextProps.templateData.versions) { // Edit of already added message in library mode
480
+ // this.setState({editTemplateData: nextProps.templateData}, () => {
481
+ // this.setEditData();
482
+ // });
483
+ // }
484
+ if (nextProps.params.id && !_.isEqual(nextProps.params.id, this.props.params.id)) {
485
+ this.setState({isEdit: true});
486
+ }
487
+ if (this.state.isEdit && _.isEmpty(this.state.editTemplateData) && !_.isEmpty(nextProps.WeChat.weChatTemplates)) {
488
+ const templateIndex = _.findIndex(nextProps.WeChat.weChatTemplates, {_id: nextProps.params.id});
489
+ this.setState({editTemplateData: nextProps.WeChat.weChatTemplates[templateIndex]}, () => {
490
+ if (_.isEmpty(this.state.baseSchema)) {
491
+ this.setState({ baseSchema: _.cloneDeep(this.state.schema)}, () => {
492
+ this.setEditData();
493
+ });
494
+ } else {
495
+ this.setEditData();
496
+ }
497
+ });
498
+ }
499
+ if (nextProps.location.query.type === 'embedded') {
500
+ this.removeActionButtons();
501
+ }
502
+
503
+ if (nextProps.WeChat.createResponse && nextProps.WeChat.createResponse.templateId) {
504
+ // this.resetSchema();
505
+ let message;
506
+ if (this.state.isEdit) {
507
+ message = getMessageObject('success', this.props.intl.formatMessage(messages.wechatEditSuccess), true);
508
+ } else {
509
+ message = getMessageObject('success', this.props.intl.formatMessage(messages.wechatCreateSuccess), true);
510
+ }
511
+ this.props.globalActions.addMessageToQueue(message);
512
+ this.props.actions.clearCreateResponse();
513
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
514
+ const type = this.props.location.query.type;
515
+ this.props.router.push({
516
+ pathname: `/wechat`,
517
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
518
+ });
519
+ }
520
+ if (nextProps.WeChat.createTemplateError && !_.isEqual(nextProps.WeChat.createTemplateError, this.props.WeChat.createTemplateError)) {
521
+ const message = getMessageObject('error', this.props.intl.formatMessage(messages.somethingWentWrong), true);
522
+ this.props.globalActions.addMessageToQueue(message);
523
+ }
524
+
525
+ // console.log('All Dont Hail ', query);
526
+ // this.injectEvents(nextProps.metaEntities.layouts[0].definition);
527
+ // const query = {
528
+ // layout: 'WECHAT',
529
+ // type: 'TAG',
530
+ // context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
531
+ // };
532
+ // this.props.globalActions.fetchSchemaForEntity(query);
533
+ if (this.props.location.query.type === 'embedded') {
534
+ this.showNext();
535
+ }
536
+
537
+ if (!_.isEqual(this.props.WeChat.weCrmAccounts, nextProps.WeChat.weCrmAccounts) && (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty')) {
538
+ this.injectEvents(this.state.schema);
539
+ this.setWechatAccountOptions(nextProps.WeChat.weCrmAccounts);
540
+ }
541
+
542
+ if (!_.isEmpty(nextProps.WeChat.selectedWeChatAccount) && !_.isEqual(this.props.WeChat.selectedWeChatAccount, nextProps.WeChat.selectedWeChatAccount) && (this.props.location.query.type === 'embedded')) {
543
+ const params = {
544
+ name: '',
545
+ sortBy: 'Most Recent',
546
+ wecrmId: nextProps.WeChat.selectedWeChatAccount.configs.wecrm_app_id,
547
+ wecrmToken: nextProps.WeChat.selectedWeChatAccount.configs.wecrm_token,
548
+ originalId: nextProps.WeChat.selectedWeChatAccount.sourceAccountIdentifier,
549
+ };
550
+ this.props.actions.getDefaultWeChatTemplates('wechat', params);
551
+ }
552
+
553
+ if (_.isEmpty(nextProps.WeChat.selectedWeChatAccount) && (this.props.location.query.type === 'embedded')) {
554
+ let selectedAccount = {};
555
+ _.forEach(nextProps.WeChat.weCrmAccounts, (account) => {
556
+ if (account.configs && account.configs.is_wecrm_enabled) {
557
+ if (account.sourceAccountIdentifier === this.props.location.query.source_account_id) {
558
+ selectedAccount = account;
559
+ }
560
+ }
561
+ });
562
+ if (!_.isEmpty(selectedAccount)) {
563
+ this.props.actions.setWeChatAccount(selectedAccount);
564
+ }
565
+ }
566
+
567
+ if (nextProps.metaEntities && nextProps.metaEntities.tags && nextProps.metaEntities.tags.custom && this.props.metaEntities.tags !== nextProps.metaEntities.tags) {
568
+ let injectedTags = _.cloneDeep(this.state.injectedTags);
569
+ delete injectedTags["Registration custom fields"];
570
+ delete injectedTags["Store custom fields"];
571
+ delete injectedTags["Transaction custom fields"];
572
+ injectedTags = _.merge({}, injectedTags, nextProps.metaEntities.tags.custom);
573
+ console.log('new injected tags', nextProps.metaEntities.tags.custom);
574
+ if (!_.has(nextProps.metaEntities.tags.custom, "Registration custom fields")) {
575
+ delete injectedTags["Registration custom fields"];
576
+ }
577
+ if (!_.has(nextProps.metaEntities.tags.custom, "Store custom fields")) {
578
+ delete injectedTags["Store custom fields"];
579
+ }
580
+ if (!_.has(nextProps.metaEntities.tags.custom, "Transaction custom fields")) {
581
+ delete injectedTags["Transaction custom fields"];
582
+ }
583
+ this.setState({injectedTags});
584
+ }
585
+
586
+ // if (this.props.location.query.type.type === 'embedded' && this.props.location.query.module === 'loyalty' && this.state.formData['wechat-template'] !== '') {
587
+ // }
588
+
589
+ if (!nextProps.WeChat.fetchingDefaultTemplates && nextProps.location.query.module === 'outbound' && nextProps.params.id !== undefined) {
590
+ this.setState({ isLoading: false});
591
+ }
592
+ if ((!nextProps.WeChat.fetchingDefaultTemplates && !_.isEqual(nextProps.WeChat.fetchingDefaultTemplates, this.props.WeChat.fetchingDefaultTemplates) && nextProps.location.query.module !== 'loyalty') || (nextProps.location.query.module === 'loyalty')) {
593
+ this.setState({ isLoading: false});
594
+ }
595
+
596
+ if (nextProps.WeChat.fetchingDefaultTemplates && nextProps.location.query.module === 'loyalty' && nextProps.params.id === undefined) {
597
+ this.setState({ isLoading: true});
598
+ }
599
+ }
600
+ }
601
+
602
+ componentWillUnmount() {
603
+ console.log('removed listener create');
604
+ window.removeEventListener("message", this.handleFrameTasks);
605
+ this.props.templateActions.resetTemplate();
606
+ this.resetState();
607
+ }
608
+
609
+ onFormDataChange(formData) {
610
+ let selectedWechatTemplateIndex = -1;
611
+ let selectedTemplate = {};
612
+ let selectedTemplateData = {};
613
+
614
+ if (this.props.location.query.type === 'embedded' && (this.props.location.query.module === 'loyalty')) {
615
+ if (this.props.params.id && _.isEmpty(this.props.WeChat.weChatTemplates) && _.isEqual(formData['wechat-template'], this.state.formData['wechat-template'])) {
616
+ console.log('In If', formData['wechat-template']);
617
+ selectedTemplate = {
618
+ template_id: this.props.WeChat.templateDetails.versions.base.template_id,
619
+ title: this.props.WeChat.templateDetails.versions.base.Title,
620
+ content: this.props.WeChat.templateDetails.versions.base.content,
621
+ };
622
+ selectedTemplateData = this.props.WeChat.templateDetails;
623
+ } else {
624
+ console.log('In Else', formData['wechat-template']);
625
+ _.forEach(this.props.WeChat.weChatTemplates, (template) => {
626
+ if (template.versions.base.template_id === formData['wechat-template']) {
627
+ selectedTemplate = {
628
+ template_id: template.versions.base.template_id,
629
+ title: template.versions.base.Title,
630
+ content: template.versions.base.content,
631
+ };
632
+ selectedTemplateData = template;
633
+ }
634
+ });
635
+ }
636
+ } else if (this.state.isEdit && this.state.editTemplateData.versions) {
637
+ console.log('this.state.editTemplateData', this.state.editTemplateData);
638
+ selectedTemplateData = _.cloneDeep(this.state.editTemplateData);
639
+ selectedTemplate = {
640
+ template_id: selectedTemplateData.versions.base.template_id,
641
+ title: selectedTemplateData.versions.base.Title,
642
+ content: selectedTemplateData.versions.base.content,
643
+ };
644
+ } else if (!this.state.isEdit) {
645
+ selectedWechatTemplateIndex = _.findIndex(this.props.WeChat.weChatDefaultTemplate, {template_id: formData['wechat-template']});
646
+ selectedTemplate = this.props.WeChat.weChatDefaultTemplate[selectedWechatTemplateIndex];
647
+ }
648
+
649
+ if (!_.isEqual(formData['wechat-template'], this.state.formData['wechat-template'])) {
650
+ this.updateSchema = true;
651
+ }
652
+ this.setState({formData, editTemplateData: selectedTemplateData}, () => {
653
+ if (!_.isEmpty(this.state.editTemplateData) && this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty') {
654
+ this.setEditData();
655
+ }
656
+ if (selectedWechatTemplateIndex !== -1 || this.state.isEdit) {
657
+ let templateData = {};
658
+ if (this.state.isEdit && !_.isEmpty(this.state.editTemplateData)) {
659
+ templateData = {
660
+ template_id: this.state.editTemplateData.versions.base.template_id,
661
+ title: this.state.editTemplateData.versions.base.Title,
662
+ content: this.state.editTemplateData.versions.base.content,
663
+ };
664
+ if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'loyalty') {
665
+ this.setSelectedTemplateData(selectedTemplate);
666
+ } else {
667
+ const templateTags = this.getTagsFromContent(templateData.content);
668
+ this.prepareWeChatPreviewData(templateData, templateTags);
669
+ }
670
+ } else if (!this.updateSchema) {
671
+ const templateTags = this.getTagsFromContent(selectedTemplate.content);
672
+ this.prepareWeChatPreviewData(selectedTemplate, templateTags);
673
+ } else {
674
+ this.updateSchema = false;
675
+ this.setSelectedTemplateData(selectedTemplate);
676
+ }
677
+ } else {
678
+ let selectedAccount = {};
679
+ _.forEach(this.props.WeChat.weCrmAccounts, (account) => {
680
+ if (account.configs && account.configs.is_wecrm_enabled) {
681
+ if (account.name === formData['wechat-accounts']) {
682
+ selectedAccount = account;
683
+ }
684
+ }
685
+ });
686
+ this.props.actions.setWeChatAccount(selectedAccount);
687
+ }
688
+ });
689
+ }
690
+
691
+ onTagSelect(data, currentTab, value) {
692
+ const editorId = (value.id).replace('tagList', 'template');
693
+ this.insertAtCursor(document.getElementById(editorId), `{{${data}}}`);
694
+ document.getElementById(editorId).focus();
695
+ }
696
+
697
+ getFormData(e) {
698
+ console.log('posting final result', this.state.formData, this.state.editTemplateData);
699
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.WeChat.selectedWeChatAccount);
700
+ const data = {
701
+ template_id: this.state.editTemplateData.versions.base.template_id,
702
+ Title: this.state.editTemplateData.versions.base.Title,
703
+ Tag: [],
704
+ url: this.state.formData['is-internal-url'] ? this.maskTemplateUrl(this.state.formData['template-link']) : this.state.formData['template-link'],
705
+ TopColor: "#000000",
706
+ data: {},
707
+ preview: '',
708
+ BrandId: (selectedWeChatAccount.configs.brand_id ? selectedWeChatAccount.configs.brand_id : ''),
709
+ OriginalId: selectedWeChatAccount.sourceAccountIdentifier,
710
+ content: this.state.editTemplateData.versions.base.content,
711
+ isInternalUrl: this.state.formData['is-internal-url'],
712
+ creative_template_id: this.state.editTemplateData._id,
713
+ touser: "{{wechat_open_id}}",
714
+ };
715
+ _.forEach(this.state.selectedTemplateTags, (templateTag) => {
716
+ const tagName = templateTag.substr(0, templateTag.indexOf('.'));
717
+ let newTagname = tagName;
718
+ data.Tag.push(tagName);
719
+ if (tagName.match(/first/i)) {
720
+ newTagname = "Header";
721
+ }
722
+ if (tagName.match(/remark/i)) {
723
+ newTagname = "Footer";
724
+ }
725
+ data.data[tagName] = {};
726
+ data.data[tagName] = {
727
+ value: this.state.formData[`template-${newTagname}`],
728
+ color: "#00000",
729
+ };
730
+ });
731
+ const response = {
732
+ action: "getFormData",
733
+ value: data,
734
+ validity: this.state.isFormValid,
735
+ };
736
+ console.log('response ', response);
737
+ this.setState({checkValidation: true});
738
+ if (this.props.location.query.module === 'library') {
739
+ this.props.getLibraryFormData(response);
740
+ } else {
741
+ e.source.postMessage(JSON.stringify(response), e.origin);
742
+ }
743
+ }
744
+
745
+ getCurrentWindow(e) {
746
+ console.log('in sms create', e);
747
+ const response = {
748
+ action: e.action,
749
+ value: 'edit',
750
+ direction: e.value,
751
+ };
752
+ parent.postMessage(JSON.stringify(response), '*');
753
+ }
754
+
755
+ getTagsFromContent(string) {
756
+ const foundTags = [];
757
+ const rxp = /{{([^}]+)}}/g;
758
+ let curMatch;
759
+ /* eslint-disable */
760
+ while ( curMatch = rxp.exec( string ) ) {
761
+ foundTags.push( curMatch[1] );
762
+ }
763
+ return foundTags;
764
+ }
765
+
766
+ startLoading(ifEdit) {
767
+ console.log('startLoading', ifEdit);
768
+ if (ifEdit) {
769
+ this.setState({loading: true});
770
+ }
771
+ }
772
+
773
+ handleFrameTasks = (e) => {
774
+ // console.log('data listened to is', e.data);
775
+ const type = e.data;
776
+ // console.log('data type', typeof type);
777
+ if (typeof type === 'object') {
778
+ // console.log('received something', type);
779
+ const action = type.action;
780
+ switch (action) {
781
+ case "startTemplateCreation":
782
+ this.startTemplateCreation(type.value);
783
+ break;
784
+ case "startLoading":
785
+ this.startLoading(type.edit);
786
+ break;
787
+ case "getCurrentWindow":
788
+ this.getCurrentWindow(type);
789
+ break;
790
+ default:
791
+ break;
792
+ }
793
+ } else {
794
+ switch (type) {
795
+ case "getFormData":
796
+ this.getFormData(e);
797
+ break;
798
+ case "startTemplateCreation":
799
+ console.log('Starting to create template');
800
+ //this.getFormData(e);
801
+ break;
802
+ case "moveToTemplates":
803
+ console.log('moving to templates');
804
+ this.moveToTemplates();
805
+ break;
806
+ case "validateContent":
807
+ console.log('validating Content');
808
+ this.validateContent(e);
809
+ break;
810
+ default:
811
+ break;
812
+ }
813
+ }
814
+ }
815
+
816
+ moveToTemplates() {
817
+ console.log('in move to Templates');
818
+ const modalContent = {
819
+ title: "Alert",
820
+ body: "Do you really want to go back? All your temporary changes will be lost!",
821
+ type: 'confirm',
822
+ id: 'template-back-confirm-modal',
823
+ show: true,
824
+ };
825
+ this.setState({modalContent, showModal: true});
826
+ }
827
+
828
+ injectMessages(elem) {
829
+ const temp = elem;
830
+ if (temp.value && messages[temp.value]) {
831
+ temp.value = this.props.intl.formatMessage(messages[temp.value]);
832
+ }
833
+ if (temp.label && messages[temp.label]) {
834
+ temp.label = this.props.intl.formatMessage(messages[temp.label]);
835
+ }
836
+ if (temp.errorMessage && messages[temp.errorMessage]) {
837
+ temp.errorMessage = this.props.intl.formatMessage(messages[temp.errorMessage]);
838
+ }
839
+ if (temp.placeholder && messages[temp.placeholder]) {
840
+ temp.placeholder = this.props.intl.formatMessage(messages[temp.placeholder]);
841
+ }
842
+ return temp;
843
+ }
844
+
845
+ setSelectedTemplateData(weChatData) {
846
+ if (_.isEmpty(weChatData)) {
847
+ return;
848
+ }
849
+ console.log('Setting Data ', weChatData, this.state.baseSchema);
850
+ const {map} = _.cloneDeep(this.state);
851
+ const schema = _.cloneDeep(this.state.baseSchema);
852
+ const templateTags = this.getTagsFromContent(weChatData.content);
853
+ const formData = _.cloneDeep(this.state.formData);
854
+ _.forEach(templateTags, (tag) => {
855
+ const tagTitle = tag.substr(0, tag.indexOf('.'));
856
+ let title = tagTitle;
857
+
858
+ if (tagTitle.match(/first/i)) {
859
+ title = "Header";
860
+ }
861
+ if (tagTitle.match(/remark/i)) {
862
+ title = "Footer";
863
+ }
864
+
865
+ const colsData = {
866
+ cols: [
867
+ {
868
+ id: `template-label-${title}`,
869
+ metaType: "label",
870
+ value: `${title}`,
871
+ primitive: true,
872
+ type: "div",
873
+ width: 4,
874
+ offset: 0,
875
+ onlyDisplay: true,
876
+ colStyle: {
877
+ flex: 1,
878
+ textAlign: 'left',
879
+ color: '#333333',
880
+ lineHeight: '24px',
881
+ fontSize: '14px',
882
+ fontWeight: '400',
883
+ fontFamily: 'open-sans',
884
+ fontStyle: 'normal',
885
+ textTransform: 'capitalize',
886
+ padding: '1em .833em',
887
+ },
888
+ },
889
+ {
890
+ id: `template-${title}`,
891
+ placeholder: `${title}`,
892
+ type: "input", //Resembles component to be used
893
+ metaType: "text",
894
+ datatype: "string",
895
+ errorMessage: `${title} has invalid content.`,
896
+ required: true,
897
+ fluid: true,
898
+ disabled: (this.props.location.query.type === 'embedded'),
899
+ style: {
900
+ fontSize: '14px',
901
+ fontFamily: 'open-sans',
902
+ fontStyle: 'normal',
903
+ // fontWeight: 600,
904
+ marginBottom: '16px',
905
+ },
906
+ styling: "semantic",
907
+ order: 1,
908
+ width: 15,
909
+ // offSet: 2,
910
+ customComponent: false,
911
+ standalone: true,
912
+ supportedEvents: [
913
+ 'onChange',
914
+ ],
915
+ },
916
+ ],
917
+ };
918
+
919
+ if(this.props.location.query.type !== 'embedded') {
920
+ colsData.cols.push({
921
+ offset: 20,
922
+ id: `tagList-${title}`,
923
+ label: "Tags",
924
+ type: "tag-list", //Resembles component to be used
925
+ metaType: "List",
926
+ datatype: "select",
927
+ required: true,
928
+ fluid: true,
929
+ onlyDisplay: true,
930
+ styling: "semantic",
931
+ order: 1,
932
+ customComponent: true,
933
+ supportedEvents: [
934
+ 'onTagSelect',
935
+ ],
936
+ },);
937
+ }
938
+
939
+ map[`tagList-${title}`] = {
940
+ onTagSelect: this.onTagSelect,
941
+ };
942
+
943
+ // if(!tagTitle.match(/first/i) && !tagTitle.match(/remark/i) && this.props.location.query.type !== 'embedded') {
944
+ // colsData.cols.push({
945
+ // offset: 20,
946
+ // id: `tagList-${title}`,
947
+ // // label: "Tags",
948
+ // type: "tag-list", //Resembles component to be used
949
+ // metaType: "List",
950
+ // datatype: "select",
951
+ // required: true,
952
+ // fluid: true,
953
+ // onlyDisplay: true,
954
+ // styling: "semantic",
955
+ // order: 1,
956
+ // customComponent: true,
957
+ // supportedEvents: [
958
+ // 'onTagSelect',
959
+ // ],
960
+ // },);
961
+
962
+ // map[`tagList-${title}`] = {
963
+ // onTagSelect: this.onTagSelect,
964
+ // };
965
+ // }
966
+ map[`template-${title}`] = {
967
+ onChange: this.setContent,
968
+ };
969
+
970
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[1].inputFields.push(colsData);
971
+ });
972
+
973
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[1].inputFields.push(
974
+ {
975
+ cols: [
976
+ {
977
+ id: "template-label-link",
978
+ metaType: "label",
979
+ value: 'Link',
980
+ primitive: true,
981
+ type: "div",
982
+ width: 4,
983
+ offset: 0,
984
+ onlyDisplay: true,
985
+ colStyle: {
986
+ flex: 1,
987
+ textAlign: 'left',
988
+ color: '#333333',
989
+ lineHeight: '24px',
990
+ fontSize: '14px',
991
+ fontWeight: '400',
992
+ fontFamily: 'open-sans',
993
+ fontStyle: 'normal',
994
+ textTransform: 'capitalize',
995
+ padding: '.5em .833em',
996
+ },
997
+ },
998
+ {
999
+ id: 'template-link',
1000
+ placeholder: this.props.intl.formatMessage(messages.Link),
1001
+ type: "input", //Resembles component to be used
1002
+ metaType: "text",
1003
+ datatype: "string",
1004
+ errorMessage: `Link cannot be empty.`,
1005
+ required: true,
1006
+ fluid: true,
1007
+ disabled: (this.props.location.query.type === 'embedded'),
1008
+ style: {
1009
+ fontSize: '14px',
1010
+ fontFamily: 'open-sans',
1011
+ fontStyle: 'normal',
1012
+ // fontWeight: 600,
1013
+ // marginBottom: '16px',
1014
+ },
1015
+ styling: "semantic",
1016
+ order: 1,
1017
+ width: 15,
1018
+ // offSet: 6,
1019
+ customComponent: false,
1020
+ standalone: true,
1021
+ supportedEvents: [
1022
+ 'onChange',
1023
+ ],
1024
+ },
1025
+ ],
1026
+ },
1027
+ {
1028
+ cols: [
1029
+ {
1030
+ id: "is-internal-url",
1031
+ label: 'Is this internal url',
1032
+ standalone: true,
1033
+ labelStyle: {
1034
+ backgroundColor: "white",
1035
+ },
1036
+ colStyle: {
1037
+ marginBottom: '24px',
1038
+ },
1039
+ style: {
1040
+ textAlign: 'left',
1041
+ color: '#262626',
1042
+ fontFamily: 'Open-Sans',
1043
+ lineHeight: '24px',
1044
+ fontSize: '14px',
1045
+ padding: '.5833em .833em',
1046
+ marginBottom: '24px',
1047
+ paddingLeft: '0',
1048
+ },
1049
+ type: "checkbox",
1050
+ disabled: (this.props.location.query.type === 'embedded'),
1051
+ metaType: "text",
1052
+ datatype: "boolean",
1053
+ required: true,
1054
+ fluid: true,
1055
+ styling: "semantic",
1056
+ order: 1,
1057
+ width: 10,
1058
+ offset: 4,
1059
+ onlyDisplay: false,
1060
+ customComponent: false,
1061
+ supportedEvents: [
1062
+ 'onChange',
1063
+ ],
1064
+ },
1065
+ ],
1066
+ }
1067
+ );
1068
+ if (this.state.isEdit) {
1069
+ _.forEach(this.state.editTemplateData.versions.base.Tag, (tag) => {
1070
+ let tagName = tag;
1071
+ if (tag.match(/first/i)) {
1072
+ tagName = "Header";
1073
+ }
1074
+ if (tag.match(/remark/i)) {
1075
+ tagName = "Footer";
1076
+ }
1077
+ formData[`template-${tagName}`] = this.state.editTemplateData.versions.base.data[tag].value;
1078
+ });
1079
+ if (this.state.editTemplateData.versions.base.url) {
1080
+ formData[`template-link`] = this.state.editTemplateData.versions.base.isInternalUrl ? this.unMaskTemplateUrl(this.state.editTemplateData.versions.base.url) : this.state.editTemplateData.versions.base.url;
1081
+ }
1082
+ if (this.state.editTemplateData.versions.base.isInternalUrl) {
1083
+ formData['is-internal-url'] = this.state.editTemplateData.versions.base.isInternalUrl;
1084
+ }
1085
+ // schema.standalone.sections[0].childSections[1].childSections[1].inputFields[0].cols[0].content = weChatData.content;
1086
+ } else {
1087
+ // schema.standalone.sections[0].childSections[1].childSections[1].inputFields[0].cols[0].content = weChatData.content;
1088
+ }
1089
+ // schema.standalone.sections[0].childSections[1].childSections[1].inputFields[0].cols[0].content = weChatData.content;
1090
+
1091
+ this.setState({schema, map, selectedTemplateTags: templateTags, formData}, () => {
1092
+ console.log('Is internal URL ', this.state.schema, formData);
1093
+ this.prepareWeChatPreviewData(weChatData, templateTags);
1094
+ });
1095
+ }
1096
+
1097
+ resetState() {
1098
+ this.setState({
1099
+ formData: {},
1100
+ schema: {},
1101
+ baseSchema: {},
1102
+ selectedTemplateTags: [],
1103
+ isEdit: false,
1104
+ editTemplateData: {},
1105
+ isFormValid: true,
1106
+ checkValidation: false,
1107
+ injectedTags: {},
1108
+ isLoading: true,
1109
+ });
1110
+ }
1111
+
1112
+ resetSchema() {
1113
+ const formData = _.cloneDeep(this.state.formData);
1114
+ if (this.state.isEdit) {
1115
+ const templateData = {
1116
+ template_id: this.state.editTemplateData.versions.base.template_id,
1117
+ title: this.state.editTemplateData.versions.base.Title,
1118
+ content: this.state.editTemplateData.versions.base.content,
1119
+ };
1120
+ this.setSelectedTemplateData(templateData);
1121
+ } else {
1122
+ this.setState({ schema: this.state.baseSchema, formData: {'wechat-template': "" }});
1123
+ // this.setState({ schema: this.props.metaEntities.layouts[0].definition });
1124
+ }
1125
+ }
1126
+
1127
+ setWechatAccountOptions(weCrmAccounts) {
1128
+ const schema = _.cloneDeep(this.state.schema);
1129
+ const formData = _.cloneDeep(this.state.formData);
1130
+ if (!_.isEmpty(weCrmAccounts)) {
1131
+ _.forEach(weCrmAccounts, (account) => {
1132
+ if (account.configs && account.configs.is_wecrm_enabled) {
1133
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[0].options.push({
1134
+ key: account.uuid,
1135
+ label: account.name,
1136
+ value: account.name,
1137
+ });
1138
+ }
1139
+
1140
+ if (this.props.WeChat.templateDetails && this.props.WeChat.templateDetails.versions.base.OriginalId === account.sourceAccountIdentifier) {
1141
+ formData['wechat-accounts'] = account.name;
1142
+ this.props.actions.setWeChatAccount(account);
1143
+ }
1144
+ });
1145
+ this.setState({schema, formData});
1146
+ }
1147
+ }
1148
+
1149
+ selectWechatAccount(value, option) {
1150
+ // console.log('Test ', value, option);
1151
+ // templateActions.setWeChatAccount();
1152
+ }
1153
+
1154
+ setTemplateOptions(weChatData) {
1155
+ console.log('Set Templates ', weChatData);
1156
+ //const {schema, baseSchema} = this.state;
1157
+ const schema = _.cloneDeep(this.state.schema);
1158
+ const baseSchema = _.cloneDeep(this.state.baseSchema);
1159
+ const baseSchemaTemplateOptionEmpty = (!_.isEmpty(baseSchema) && _.isEmpty(baseSchema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options));
1160
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options = [];
1161
+ if (!_.isEmpty(baseSchema)) {
1162
+ baseSchema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options = [];
1163
+
1164
+ }
1165
+ _.forEach(weChatData, (template) => {
1166
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options.push({
1167
+ key: (template.versions) ? template.versions.base.template_id : template.template_id,
1168
+ label: (template.versions) ? template.name : `${template.title} : ${template.template_id}`,
1169
+ value: (template.versions) ? template.versions.base.template_id : template.template_id,
1170
+ });
1171
+ if ((!_.isEmpty(baseSchema) && this.props.location.query.module === 'loyalty') || (baseSchemaTemplateOptionEmpty)) {
1172
+ baseSchema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options.push({
1173
+ key: (template.versions) ? template.versions.base.template_id : template.template_id,
1174
+ label: (template.versions) ? template.name : `${template.title} : ${template.template_id}`,
1175
+ value: (template.versions) ? template.versions.base.template_id : template.template_id,
1176
+ });
1177
+ }
1178
+ });
1179
+ this.setState({schema, baseSchema: _.cloneDeep(baseSchema)}, () => {
1180
+ console.log('setTemplateOptions', this.state.baseSchema, schema);
1181
+ if (_.isEmpty(this.state.baseSchema)) {
1182
+ this.setState({baseSchema: _.cloneDeep(schema)});
1183
+ }
1184
+ });
1185
+ }
1186
+
1187
+ setFormValidity(isFormValid) {
1188
+ this.setState({isFormValid});
1189
+ }
1190
+
1191
+ setContent(content) {
1192
+ console.log('Template content changed to ', content);
1193
+ }
1194
+
1195
+ setEditData() {
1196
+ console.log('Inside Edit Data ', this.state.editTemplateData);
1197
+ const formData = _.cloneDeep(this.state.formData);
1198
+ const baseSchema = _.cloneDeep(this.state.baseSchema);
1199
+ if (_.isEmpty(baseSchema)) {
1200
+ return;
1201
+ }
1202
+ formData['wechat-template'] = this.state.editTemplateData.versions.base.template_id;
1203
+ if (this.props.location.query.module !== 'loyalty' && !_.isEmpty(baseSchema)) {
1204
+ baseSchema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options = [];
1205
+ baseSchema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].options.push({
1206
+ key: this.state.editTemplateData.versions.base.template_id,
1207
+ label: this.state.editTemplateData.name,
1208
+ value: this.state.editTemplateData.versions.base.template_id,
1209
+ });
1210
+ }
1211
+ const templateData = {
1212
+ 'template_id': this.state.editTemplateData.versions.base.template_id,
1213
+ 'title': this.state.editTemplateData.versions.base.Title,
1214
+ 'content': this.state.editTemplateData.versions.base.content,
1215
+ };
1216
+
1217
+ this.setState({baseSchema, formData, isEdit: true}, () => {
1218
+ this.setSelectedTemplateData(templateData);
1219
+ })
1220
+ }
1221
+
1222
+ maskTemplateUrl(url) {
1223
+ const selectedWeChatAccount = (!_.isEmpty(this.props.Templates.selectedWeChatAccount) ? this.props.Templates.selectedWeChatAccount : this.props.WeChat.selectedWeChatAccount);
1224
+ console.log('wecrm url', selectedWeChatAccount.configs.wecrm_app_id);
1225
+
1226
+ const appid = selectedWeChatAccount.configs.wecrm_app_id;
1227
+ const domain = selectedWeChatAccount.configs.domain;
1228
+ const maskedUrl = `${domain}/web?appid=${appid}&redirect_uri=${escape(url)}&response_type=code&scope=snsapi_base&state=STATE`;
1229
+ console.log('wecrm masked url', maskedUrl);
1230
+ return maskedUrl;
1231
+ }
1232
+
1233
+ unMaskTemplateUrl(url) {
1234
+ let startIndex, endIndex;
1235
+ startIndex = url.indexOf('&redirect_uri=') + 14;
1236
+ endIndex = url.indexOf('&response_type');
1237
+ return decodeURIComponent(url.substring(startIndex, endIndex));
1238
+ }
1239
+
1240
+ getMappedEvent(id, event) {
1241
+ return this.state.map[id][event];
1242
+ }
1243
+
1244
+ handleOnTagsContextChange = (data) => {
1245
+ console.log('parent tags context', data);
1246
+ const query = {
1247
+ layout: 'WECHAT',
1248
+ type: 'TAG',
1249
+ context: data.toLowerCase() === 'all' ? 'default' : data.toLowerCase(),
1250
+ embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
1251
+ };
1252
+ this.props.globalActions.fetchSchemaForEntity(query);
1253
+ }
1254
+
1255
+ startTemplateCreation(data) {
1256
+ console.log('startTemplateCreation');
1257
+ }
1258
+
1259
+ selectWechatTemplate() {
1260
+ console.log('Updated data');
1261
+ }
1262
+
1263
+ removeActionButtons() {
1264
+ const schema = _.cloneDeep(this.state.schema);
1265
+ const headerCols = schema.standalone.sections[0].childSections[0].inputFields[0].cols;
1266
+ _.forEach(headerCols, (col) => {
1267
+ col.colStyle.display = 'none';
1268
+ });
1269
+ this.setState({schema});
1270
+ }
1271
+
1272
+ showNext() {
1273
+ const response = {
1274
+ action: "showNext",
1275
+ value: true,
1276
+ };
1277
+ parent.postMessage(JSON.stringify(response), '*');
1278
+ }
1279
+
1280
+ insertAtCursor(field, myValue) {
1281
+ //IE support
1282
+ const myField = field;
1283
+ if (document.selection) {
1284
+ myField.focus();
1285
+ const sel = document.selection.createRange();
1286
+ sel.text = myValue;
1287
+ } else if (myField.selectionStart || myField.selectionStart === '0') { //MOZILLA and others
1288
+ const startPos = myField.selectionStart;
1289
+ const endPos = myField.selectionEnd;
1290
+ myField.value = myField.value.substring(0, startPos)
1291
+ + myValue
1292
+ + myField.value.substring(endPos, myField.value.length);
1293
+ myField.selectionStart = startPos + myValue.length;
1294
+ myField.selectionEnd = startPos + myValue.length;
1295
+ } else {
1296
+ myField.value += myValue;
1297
+ }
1298
+ const event = new Event('input', { bubbles: true });
1299
+ callNativeEvent({field, value: myField.value, event});
1300
+ }
1301
+
1302
+ internalUrlChecked() {
1303
+
1304
+ }
1305
+
1306
+ discardValues() {
1307
+ // this.setState({ schema: this.state.baseSchema, formData: {}});
1308
+ this.resetSchema();
1309
+ // this.resetState();
1310
+ }
1311
+
1312
+ cancelTemplate() {
1313
+ const type = this.props.location.query.type;
1314
+ this.props.router.push({
1315
+ pathname: `/wechat`,
1316
+ query: type === 'embedded' ? {type: 'embedded'} : {},
1317
+ });
1318
+ }
1319
+
1320
+ saveFormData(formData) {
1321
+ const obj = {};
1322
+ let selectedWechatData = {};
1323
+ if (this.state.isEdit) {
1324
+ obj['_id'] = this.state.editTemplateData._id;
1325
+ selectedWechatData = {
1326
+ 'template_id': this.state.editTemplateData.versions.base.template_id,
1327
+ 'title': this.state.editTemplateData.versions.base.Title,
1328
+ 'content': this.state.editTemplateData.versions.base.content,
1329
+ };
1330
+ } else {
1331
+ const selectedWechatTemplateIndex = _.findIndex(this.props.WeChat.weChatDefaultTemplate, {template_id: formData['wechat-template']});
1332
+ selectedWechatData = this.props.WeChat.weChatDefaultTemplate[selectedWechatTemplateIndex];
1333
+ }
1334
+ obj.name = `${selectedWechatData.title}: ${selectedWechatData.template_id}`;
1335
+ obj.versions = {
1336
+ base: {},
1337
+ history: [],
1338
+ };
1339
+ obj.versions.base = {
1340
+ "template_id": selectedWechatData.template_id,
1341
+ "Title": selectedWechatData.title,
1342
+ Tag: [],
1343
+ url: this.state.formData['is-internal-url'] ? this.maskTemplateUrl(this.state.formData['template-link']) : this.state.formData['template-link'],
1344
+ TopColor: "#000000",
1345
+ data: {},
1346
+ preview: '',
1347
+ BrandId: (this.props.Templates.selectedWeChatAccount.configs.brand_id ? this.props.Templates.selectedWeChatAccount.configs.brand_id : ''),
1348
+ OriginalId: this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier,
1349
+ content: selectedWechatData.content,
1350
+ isInternalUrl: this.state.formData['is-internal-url'],
1351
+ }
1352
+ _.forEach(this.state.selectedTemplateTags, (templateTag) => {
1353
+ const tagName = templateTag.substr(0, templateTag.indexOf('.'));
1354
+ let newTagname = tagName;
1355
+ obj.versions.base.Tag.push(tagName);
1356
+ if (tagName.match(/first/i)) {
1357
+ newTagname = "Header";
1358
+ }
1359
+ if (tagName.match(/remark/i)) {
1360
+ newTagname = "Footer";
1361
+ }
1362
+ obj.versions.base.data[tagName] = {};
1363
+ obj.versions.base.data[tagName] = {
1364
+ value: this.state.formData[`template-${newTagname}`],
1365
+ color: "#00000",
1366
+ }
1367
+ });
1368
+ console.log("Final Object ", obj);
1369
+ this.props.actions.createTemplate(obj);
1370
+ }
1371
+
1372
+ prepareWeChatPreviewData(wechatData, templateTags) {
1373
+ let content = _.cloneDeep(wechatData.content);
1374
+ const {formData} = _.cloneDeep(this.state);
1375
+ _.forEach(templateTags, (tag) => {
1376
+ let tagName = tag.substr(0, tag.indexOf('.'));
1377
+ if (tagName.match(/first/i)) {
1378
+ tagName = "Header";
1379
+ }
1380
+ if (tagName.match(/remark/i)) {
1381
+ tagName = "Footer";
1382
+ }
1383
+ if(this.state.formData[`template-${tagName}`] !== undefined && this.state.formData[`template-${tagName}`] !== '') {
1384
+ content = content.replace(`{{${tag}}}`, this.state.formData[`template-${tagName}`]);
1385
+ }
1386
+ })
1387
+ formData['sms-preview'] = content;
1388
+ // schema.standalone.sections[0].childSections[1].childSections[1].inputFields[0].cols[0].content = content;
1389
+ this.setState({formData}, () => {
1390
+ this.injectEvents(this.state.schema);
1391
+ });
1392
+ }
1393
+
1394
+ injectEvents(schema) {
1395
+ console.log('injecting events', schema);
1396
+ const temp = schema;
1397
+ let newSchema = _.cloneDeep(schema);
1398
+ temp.standalone.sections = this.injectSections(temp.standalone.sections);
1399
+ _.forEach(temp.containers, (container) => {
1400
+ let tempContainer = container;
1401
+ tempContainer = this.injectContainer(tempContainer);
1402
+ return tempContainer;
1403
+ });
1404
+ newSchema = this.hideSchemaElementsByModule(schema);
1405
+ this.setState({schema: newSchema});
1406
+ return schema;
1407
+ }
1408
+
1409
+ hideSchemaElementsByModule(schema) {
1410
+ schema.standalone.sections[0].childSections[0].inputFields[0].cols[0].colStyle.display = (this.props.location.query.type === 'embedded' ? 'none' : 'block');
1411
+ schema.standalone.sections[0].childSections[0].inputFields[0].cols[1].colStyle.display = (this.props.location.query.type === 'embedded' ? 'none' : 'block');
1412
+ schema.standalone.sections[0].childSections[0].inputFields[0].cols[2].colStyle.display = (this.props.location.query.type === 'embedded' ? 'none' : 'block');
1413
+ schema.standalone.sections[0].childSections[0].inputFields[0].cols[3].colStyle.display = (this.props.location.query.type === 'embedded' ? 'none' : 'block');
1414
+
1415
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[0].labelStyle.display = (this.props.location.query.module === 'loyalty' ? 'block' : 'none');
1416
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[0].style.display = (this.props.location.query.module === 'loyalty' ? 'block' : 'none');
1417
+
1418
+ schema.standalone.sections[0].childSections[1].childSections[0].childSections[0].inputFields[1].disabled = (this.props.params.id && this.props.location.query.module !== 'loyalty');
1419
+ return schema;
1420
+ }
1421
+
1422
+ injectContainer(container) {
1423
+ const temp = container;
1424
+ if (temp.type === 'tabs') {
1425
+ temp.tabContent.sections = this.injectSections(temp.tabContent.sections);
1426
+ temp.tabBarExtraContent.sections = this.injectSections(temp.tabBarExtraContent.sections);
1427
+ temp.tabContent.sections = this.injectSections(temp.tabContent.sections);
1428
+ temp.injectedEvents = {};
1429
+ _.forEach(temp.supportedEvents, (event) => {
1430
+ temp.injectedEvents[event] = this.getMappedEvent(temp.id, event);
1431
+ });
1432
+ _.forEach(temp.panes, (pane) => {
1433
+ const tempPane = pane;
1434
+ tempPane.sections = this.injectSections(tempPane.sections);
1435
+ });
1436
+ }
1437
+ return temp;
1438
+ }
1439
+
1440
+ injectMultiColSection(section) {
1441
+ _.forEach(section.inputFields, (inputField) => {
1442
+ _.forEach(inputField.cols, (col) => {
1443
+ console.log('injecting for col', col);
1444
+ let temp = col;
1445
+ if (temp.type === 'popover') {
1446
+ temp.content.sections = this.injectSections(temp.content.sections);
1447
+ temp.value.sections = this.injectSections(temp.value.sections);
1448
+ return true;
1449
+ }
1450
+ temp.injectedEvents = {};
1451
+ _.forEach(col.supportedEvents, (event) => {
1452
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
1453
+ });
1454
+ temp = this.injectMessages(temp);
1455
+ return true;
1456
+ });
1457
+ });
1458
+ _.forEach(section.actionFields, (actionField) => {
1459
+ _.forEach(actionField.cols, (col) => {
1460
+ let temp = col;
1461
+ if (temp.type === 'popover') {
1462
+ temp.content.sections = this.injectSections(temp.content.sections);
1463
+ temp.value.sections = this.injectSections(temp.value.sections);
1464
+ return true;
1465
+ }
1466
+ temp.injectedEvents = {};
1467
+ _.forEach(col.supportedEvents, (event) => {
1468
+ temp.injectedEvents[event] = this.getMappedEvent(col.id, event);
1469
+ });
1470
+ temp = this.injectMessages(temp);
1471
+ return true;
1472
+ });
1473
+ });
1474
+ return section;
1475
+ }
1476
+
1477
+ injectColLabelSection(section) {
1478
+ _.forEach(section.inputFields, (inputField) => {
1479
+ let temp = inputField;
1480
+ if (temp.type === 'popover') {
1481
+ temp.content.sections = this.injectSections(temp.content.sections);
1482
+ temp.value.sections = this.injectSections(temp.value.sections);
1483
+ return true;
1484
+ }
1485
+ temp.injectedEvents = {};
1486
+ _.forEach(inputField.supportedEvents, (event) => {
1487
+ temp.injectedEvents[event] = this.getMappedEvent(inputField.id, event);
1488
+ });
1489
+ temp = this.injectMessages(temp);
1490
+ return true;
1491
+ });
1492
+ _.forEach(section.actionFields, (actionField) => {
1493
+ let temp = actionField;
1494
+ if (temp.type === 'popover') {
1495
+ temp.content.sections = this.injectSections(temp.content.sections);
1496
+ temp.value.sections = this.injectSections(temp.value.sections);
1497
+ return true;
1498
+ }
1499
+ temp.injectedEvents = {};
1500
+ _.forEach(actionField.supportedEvents, (event) => {
1501
+ temp.injectedEvents[event] = this.getMappedEvent(actionField.id, event);
1502
+ });
1503
+ temp = this.injectMessages(temp);
1504
+ return true;
1505
+ });
1506
+ return section;
1507
+ }
1508
+
1509
+ injectSections(sections) {
1510
+ _.forEach(sections, (section) => {
1511
+ let temp = section;
1512
+ if (temp.type === 'col-label') {
1513
+ temp = this.injectColLabelSection(temp);
1514
+ } else if (section.type === 'multicols') {
1515
+ temp = this.injectMultiColSection(temp);
1516
+ } else if (section.type === 'parent') {
1517
+ temp = this.injectSections(temp.childSections);
1518
+ }
1519
+ });
1520
+ return sections;
1521
+ }
1522
+
1523
+ handleCancelModal = () => {
1524
+ this.setState({showModal: false});
1525
+ }
1526
+
1527
+ injectParentSection(section) {
1528
+ _.forEach(section.childSections, (childSection) => {
1529
+ let temp = childSection;
1530
+ if (temp.type === 'col-label') {
1531
+ temp = this.injectColLabelSection(temp);
1532
+ } else if (section.type === 'multicols') {
1533
+ temp = this.injectMultiColSection(temp);
1534
+ } else if (section.type === 'parent') {
1535
+ temp = this.injectParentSection(temp);
1536
+ }
1537
+ });
1538
+ return section;
1539
+ }
1540
+
1541
+ render() {
1542
+ // const schema = this.state.schema;
1543
+ // const options = [
1544
+ // {
1545
+ // label: 'Test',
1546
+ // value: 'Test',
1547
+ // },
1548
+ // {
1549
+ // label: 'Test1',
1550
+ // value: 'Test1',
1551
+ // },
1552
+ // {
1553
+ // label: 'Test2',
1554
+ // value: 'Test2',
1555
+ // },
1556
+ // {
1557
+ // label: 'Test3',
1558
+ // value: 'Test3',
1559
+ // },
1560
+ // ];
1561
+ let tags = this.props.metaEntities && this.props.metaEntities.tags ? this.props.metaEntities.tags.standard : [];
1562
+ if (this.props.supportedTags) {
1563
+ tags = this.props.supportedTags;
1564
+ }
1565
+ return (
1566
+ <Spin
1567
+ tip={this.props.intl.formatMessage(messages.gettingTemplateData)}
1568
+ spinning={this.state.isLoading}>
1569
+ <div>
1570
+ <Helmet
1571
+ title="WeChat"
1572
+ />
1573
+ <Row className="wechat-container">
1574
+ <Col>
1575
+ <FormBuilder
1576
+ schema={this.state.schema}
1577
+ onSubmit={this.saveFormData}
1578
+ onChange={this.onFormDataChange}
1579
+ parent={this}
1580
+ modal={this.state.modalContent}
1581
+ showModal={this.state.showModal}
1582
+ iframeParent={parent}
1583
+ formData={_.cloneDeep(this.state.formData)}
1584
+ onFormValidityChange={this.setFormValidity}
1585
+ location= {this.props.location}
1586
+ tags={tags}
1587
+ tagModule={this.props.getDefaultTags}
1588
+ injectedTags={this.state.injectedTags ? this.state.injectedTags : {}}
1589
+ isEdit={this.state.isEdit}
1590
+ usingTabContainer={false}
1591
+ router={this.props.router}
1592
+ checkValidation={this.state.checkValidation}
1593
+ handleCancelModal={this.handleCancelModal}
1594
+ onContextChange={this.handleOnTagsContextChange}
1595
+ />
1596
+ </Col>
1597
+ </Row>
1598
+ </div>
1599
+ </Spin>
1600
+ );
1601
+ }
1602
+ }
1603
+
1604
+ WeChat.propTypes = {
1605
+ actions: PropTypes.object.isRequired,
1606
+ WeChat: PropTypes.object,
1607
+ globalActions: PropTypes.object,
1608
+ Templates: PropTypes.object,
1609
+ location: PropTypes.object,
1610
+ router: PropTypes.object,
1611
+ params: PropTypes.object,
1612
+ metaEntities: PropTypes.object,
1613
+ intl: intlShape.isRequired,
1614
+ isGetFormData: PropTypes.bool,
1615
+ getLibraryFormData: PropTypes.func,
1616
+ getDefaultTags: PropTypes.string,
1617
+ templateData: PropTypes.object,
1618
+ templateActions: PropTypes.object,
1619
+ };
1620
+
1621
+ const mapStateToProps = createStructuredSelector({
1622
+ WeChat: makeSelectWeChat(),
1623
+ Templates: makeSelectTemplates(),
1624
+ metaEntities: makeSelectMetaEntities(),
1625
+ });
1626
+
1627
+ function mapDispatchToProps(dispatch) {
1628
+ return {
1629
+ actions: bindActionCreators(actions, dispatch),
1630
+ globalActions: bindActionCreators(globalActions, dispatch),
1631
+ templateActions: bindActionCreators(templateActions, dispatch),
1632
+ };
1633
+ }
1634
+
1635
+ export default UserIsAuthenticated(connect(mapStateToProps, mapDispatchToProps)(injectIntl(WeChat)));