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