@capillarytech/creatives-library 8.0.166 → 8.0.167

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 (294) hide show
  1. package/components/BreadCrumbs/index.js +65 -0
  2. package/components/BreadCrumbs/messages.js +13 -0
  3. package/components/CapTagList/index.js +235 -0
  4. package/components/CapTagList/messages.js +45 -0
  5. package/components/Card/_customCard.scss +40 -0
  6. package/components/Card/index.js +78 -0
  7. package/components/Card/tests/__snapshots__/index.test.js.snap +22 -0
  8. package/components/Card/tests/index.test.js +20 -0
  9. package/components/CardGrid/index.js +71 -0
  10. package/components/Ckeditor/index.js +238 -0
  11. package/components/Ckeditor/messages.js +13 -0
  12. package/components/Ckeditor/style.scss +3 -0
  13. package/components/Component/index.js +29 -0
  14. package/components/CustomPopOver/index.js +81 -0
  15. package/components/CustomPopOver/messages.js +17 -0
  16. package/components/DateFilter/index.js +349 -0
  17. package/components/DateFilter/messages.js +57 -0
  18. package/components/DateRange/index.js +114 -0
  19. package/components/DateRange/messages.js +25 -0
  20. package/components/Edmeditor/index.js +65 -0
  21. package/components/Edmeditor/messages.js +13 -0
  22. package/components/EmailPreview/_emailPreview.scss +119 -0
  23. package/components/EmailPreview/assets/images/iPad.svg +10 -0
  24. package/components/EmailPreview/assets/images/mobile.png +0 -0
  25. package/components/EmailPreview/index.js +107 -0
  26. package/components/EmailPreview/messages.js +33 -0
  27. package/components/Footer/index.js +27 -0
  28. package/components/Footer/messages.js +13 -0
  29. package/components/FormBuilder/_formBuilder.scss +83 -0
  30. package/components/FormBuilder/index.js +3279 -0
  31. package/components/FormBuilder/messages.js +61 -0
  32. package/components/Header/index.js +44 -0
  33. package/components/Header/messages.js +29 -0
  34. package/components/ImagePreview/_imagePreview.scss +63 -0
  35. package/components/ImagePreview/index.js +52 -0
  36. package/components/ImagePreview/messages.js +17 -0
  37. package/components/PageHeader/_pageHeader.scss +22 -0
  38. package/components/PageHeader/index.js +37 -0
  39. package/components/PageHeader/messages.js +13 -0
  40. package/components/Pagination/_pagination.scss +5 -0
  41. package/components/Pagination/index.js +49 -0
  42. package/components/PreviewSideBar/_previewsidebar.scss +28 -0
  43. package/components/PreviewSideBar/index.js +152 -0
  44. package/components/PreviewSideBar/messages.js +41 -0
  45. package/components/Sidebar/_sidebar.scss +115 -0
  46. package/components/Sidebar/index.js +214 -0
  47. package/components/Sidebar/messages.js +21 -0
  48. package/components/SlideBox/_slideBox.scss +63 -0
  49. package/components/SlideBox/index.js +47 -0
  50. package/components/SlideBox/tests/index.test.js +103 -0
  51. package/components/SmsEditor/index.js +55 -0
  52. package/components/SmsTest/index.js +117 -0
  53. package/components/SmsTest/messages.js +21 -0
  54. package/components/TemplatePreview/WechatRichmediaTemplatePreview/_wechatRichmediaTemplatePrev.scss +42 -0
  55. package/components/TemplatePreview/WechatRichmediaTemplatePreview/index.js +141 -0
  56. package/components/TemplatePreview/WechatRichmediaTemplatePreview/messages.js +21 -0
  57. package/components/TemplatePreview/_templatePreview.scss +642 -0
  58. package/components/TemplatePreview/assets/images/WECHAT_5x.png +0 -0
  59. package/components/TemplatePreview/assets/images/androidPushMessage.svg +45 -0
  60. package/components/TemplatePreview/assets/images/home-screen-android.svg +21 -0
  61. package/components/TemplatePreview/assets/images/home-screen-ios.svg +16 -0
  62. package/components/TemplatePreview/assets/images/iPhonePushMessage.svg +135 -0
  63. package/components/TemplatePreview/assets/images/mobile.svg +24 -0
  64. package/components/TemplatePreview/assets/images/sms-body.png +0 -0
  65. package/components/TemplatePreview/assets/images/sms-icon.png +0 -0
  66. package/components/TemplatePreview/assets/images/sms_mobile.png +0 -0
  67. package/components/TemplatePreview/assets/images/sms_mobile_android.svg +22 -0
  68. package/components/TemplatePreview/assets/images/sms_mobile_ios.svg +16 -0
  69. package/components/TemplatePreview/assets/images/user-icon.svg +19 -0
  70. package/components/TemplatePreview/assets/images/wechat-mobile.svg +78 -0
  71. package/components/TemplatePreview/assets/images/wechat_mobile_android.svg +20 -0
  72. package/components/TemplatePreview/index.js +617 -0
  73. package/components/TemplatePreview/messages.js +78 -0
  74. package/components/Toastr/index.js +60 -0
  75. package/components/Toastr/messages.js +13 -0
  76. package/components/ToastrMessage/index.js +113 -0
  77. package/components/ToastrMessage/messages.js +17 -0
  78. package/components/TopBar/_topbar.scss +46 -0
  79. package/components/TopBar/assets/images/capillary_logo.png +0 -0
  80. package/components/TopBar/assets/images/old_capillary_logo.png +0 -0
  81. package/components/TopBar/index.js +113 -0
  82. package/components/TopBar/messages.js +29 -0
  83. package/containers/App/actions.js +7 -0
  84. package/containers/App/constants.js +114 -0
  85. package/containers/App/index.js +52 -0
  86. package/containers/App/reducer.js +19 -0
  87. package/containers/App/sagas.js +31 -0
  88. package/containers/App/selectors.js +25 -0
  89. package/containers/App/test/saga.test.js +11 -0
  90. package/containers/Assets/Gallery/_gallery.scss +126 -0
  91. package/containers/Assets/Gallery/actions.js +37 -0
  92. package/containers/Assets/Gallery/constants.js +23 -0
  93. package/containers/Assets/Gallery/index.js +473 -0
  94. package/containers/Assets/Gallery/messages.js +93 -0
  95. package/containers/Assets/Gallery/reducer.js +81 -0
  96. package/containers/Assets/Gallery/sagas.js +80 -0
  97. package/containers/Assets/Gallery/selectors.js +25 -0
  98. package/containers/Assets/Gallery/tests/__snapshots__/reducer.test.js.snap +9 -0
  99. package/containers/Assets/Gallery/tests/actions.test.js +25 -0
  100. package/containers/Assets/Gallery/tests/reducer.test.js +96 -0
  101. package/containers/Assets/Gallery/tests/saga.test.js +157 -0
  102. package/containers/Cap/actions.js +66 -0
  103. package/containers/Cap/constants.js +25 -0
  104. package/containers/Cap/index.js +402 -0
  105. package/containers/Cap/messages.js +75 -0
  106. package/containers/Cap/reducer.js +113 -0
  107. package/containers/Cap/sagas.js +159 -0
  108. package/containers/Cap/selectors.js +75 -0
  109. package/containers/Cap/tests/__snapshots__/index.test.js.snap +2270 -0
  110. package/containers/Cap/tests/index.test.js +22 -0
  111. package/containers/Cap/tests/saga.test.js +284 -0
  112. package/containers/Dashboard/actions.js +15 -0
  113. package/containers/Dashboard/constants.js +7 -0
  114. package/containers/Dashboard/index.js +76 -0
  115. package/containers/Dashboard/messages.js +13 -0
  116. package/containers/Dashboard/reducer.js +21 -0
  117. package/containers/Dashboard/sagas.js +17 -0
  118. package/containers/Dashboard/selectors.js +25 -0
  119. package/containers/Dashboard/test/saga.test.js +9 -0
  120. package/containers/Ebill/_ebill.scss +5 -0
  121. package/containers/Ebill/actions.js +43 -0
  122. package/containers/Ebill/constants.js +20 -0
  123. package/containers/Ebill/index.js +1278 -0
  124. package/containers/Ebill/messages.js +77 -0
  125. package/containers/Ebill/reducer.js +72 -0
  126. package/containers/Ebill/sagas.js +74 -0
  127. package/containers/Ebill/selectors.js +25 -0
  128. package/containers/Ebill/test/saga.test.js +11 -0
  129. package/containers/Email/_email.scss +141 -0
  130. package/containers/Email/actions.js +81 -0
  131. package/containers/Email/constants.js +36 -0
  132. package/containers/Email/index.js +3325 -0
  133. package/containers/Email/messages.js +289 -0
  134. package/containers/Email/reducer.js +142 -0
  135. package/containers/Email/sagas.js +135 -0
  136. package/containers/Email/selectors.js +31 -0
  137. package/containers/Email/test/saga.test.js +671 -0
  138. package/containers/LanguageProvider/actions.js +17 -0
  139. package/containers/LanguageProvider/constants.js +8 -0
  140. package/containers/LanguageProvider/index.js +80 -0
  141. package/containers/LanguageProvider/reducer.js +30 -0
  142. package/containers/LanguageProvider/selectors.js +20 -0
  143. package/containers/LanguageProvider/tests/actions.test.js +19 -0
  144. package/containers/LanguageProvider/tests/index.test.js +78 -0
  145. package/containers/LanguageProvider/tests/reducer.test.js +20 -0
  146. package/containers/LanguageProvider/tests/selectors.test.js +15 -0
  147. package/containers/Line/Create/_lineCreate.scss +54 -0
  148. package/containers/Line/Create/actions.js +90 -0
  149. package/containers/Line/Create/constants.js +39 -0
  150. package/containers/Line/Create/index.js +836 -0
  151. package/containers/Line/Create/messages.js +189 -0
  152. package/containers/Line/Create/reducer.js +99 -0
  153. package/containers/Line/Create/sagas.js +121 -0
  154. package/containers/Line/Create/selectors.js +36 -0
  155. package/containers/Line/Create/tests/saga.test.js +202 -0
  156. package/containers/Line/Edit/_lineEdit.scss +35 -0
  157. package/containers/Line/Edit/actions.js +79 -0
  158. package/containers/Line/Edit/constants.js +27 -0
  159. package/containers/Line/Edit/index.js +1050 -0
  160. package/containers/Line/Edit/messages.js +177 -0
  161. package/containers/Line/Edit/reducer.js +83 -0
  162. package/containers/Line/Edit/sagas.js +80 -0
  163. package/containers/Line/Edit/selectors.js +29 -0
  164. package/containers/Line/Edit/test/saga.test.js +160 -0
  165. package/containers/Login/assets/images/capillary_logo.png +0 -0
  166. package/containers/Login/components/LoginForm/index.js +62 -0
  167. package/containers/Login/components/LoginForm/messages.js +33 -0
  168. package/containers/Login/index.js +130 -0
  169. package/containers/Login/messages.js +25 -0
  170. package/containers/Login/selectors.js +25 -0
  171. package/containers/MobilePush/Create/_mobilePushCreate.scss +39 -0
  172. package/containers/MobilePush/Create/actions.js +46 -0
  173. package/containers/MobilePush/Create/constants.js +23 -0
  174. package/containers/MobilePush/Create/index.js +2303 -0
  175. package/containers/MobilePush/Create/messages.js +269 -0
  176. package/containers/MobilePush/Create/reducer.js +70 -0
  177. package/containers/MobilePush/Create/sagas.js +74 -0
  178. package/containers/MobilePush/Create/selectors.js +28 -0
  179. package/containers/MobilePush/Create/test/saga.test.js +19 -0
  180. package/containers/MobilePush/Edit/_mobilePushCreate.scss +39 -0
  181. package/containers/MobilePush/Edit/actions.js +91 -0
  182. package/containers/MobilePush/Edit/constants.js +35 -0
  183. package/containers/MobilePush/Edit/index.js +2601 -0
  184. package/containers/MobilePush/Edit/messages.js +266 -0
  185. package/containers/MobilePush/Edit/reducer.js +112 -0
  186. package/containers/MobilePush/Edit/sagas.js +126 -0
  187. package/containers/MobilePush/Edit/selectors.js +29 -0
  188. package/containers/MobilePush/Edit/tests/saga.test.js +255 -0
  189. package/containers/NotFoundPage/index.js +25 -0
  190. package/containers/NotFoundPage/messages.js +13 -0
  191. package/containers/NotFoundPage/tests/index.test.js +17 -0
  192. package/containers/Sms/Create/_smsCreate.scss +42 -0
  193. package/containers/Sms/Create/actions.js +27 -0
  194. package/containers/Sms/Create/constants.js +16 -0
  195. package/containers/Sms/Create/index.js +1488 -0
  196. package/containers/Sms/Create/messages.js +109 -0
  197. package/containers/Sms/Create/reducer.js +41 -0
  198. package/containers/Sms/Create/sagas.js +40 -0
  199. package/containers/Sms/Create/selectors.js +28 -0
  200. package/containers/Sms/Create/test/saga.test.js +11 -0
  201. package/containers/Sms/Edit/actions.js +40 -0
  202. package/containers/Sms/Edit/constants.js +17 -0
  203. package/containers/Sms/Edit/index.js +1472 -0
  204. package/containers/Sms/Edit/messages.js +105 -0
  205. package/containers/Sms/Edit/reducer.js +50 -0
  206. package/containers/Sms/Edit/sagas.js +60 -0
  207. package/containers/Sms/Edit/selectors.js +32 -0
  208. package/containers/Sms/Edit/test/saga.test.js +13 -0
  209. package/containers/TagList/_tagList.scss +8 -0
  210. package/containers/TagList/actions.js +15 -0
  211. package/containers/TagList/constants.js +32 -0
  212. package/containers/TagList/index.js +236 -0
  213. package/containers/TagList/messages.js +13 -0
  214. package/containers/TagList/reducer.js +23 -0
  215. package/containers/TagList/sagas.js +11 -0
  216. package/containers/TagList/selectors.js +25 -0
  217. package/containers/Templates/_templates.scss +333 -0
  218. package/containers/Templates/actions.js +103 -0
  219. package/containers/Templates/constants.js +60 -0
  220. package/containers/Templates/index.js +1756 -0
  221. package/containers/Templates/messages.js +337 -0
  222. package/containers/Templates/reducer.js +142 -0
  223. package/containers/Templates/sagas.js +163 -0
  224. package/containers/Templates/selectors.js +28 -0
  225. package/containers/Templates/test/saga.test.js +241 -0
  226. package/containers/WeChat/MapTemplates/_mapTemplates.scss +8 -0
  227. package/containers/WeChat/MapTemplates/actions.js +52 -0
  228. package/containers/WeChat/MapTemplates/constants.js +28 -0
  229. package/containers/WeChat/MapTemplates/index.js +1610 -0
  230. package/containers/WeChat/MapTemplates/messages.js +157 -0
  231. package/containers/WeChat/MapTemplates/reducer.js +74 -0
  232. package/containers/WeChat/MapTemplates/sagas.js +84 -0
  233. package/containers/WeChat/MapTemplates/selectors.js +25 -0
  234. package/containers/WeChat/MapTemplates/test/saga.test.js +155 -0
  235. package/containers/WeChat/RichmediaTemplates/Create/_createRichmedia.scss +57 -0
  236. package/containers/WeChat/RichmediaTemplates/Create/actions.js +36 -0
  237. package/containers/WeChat/RichmediaTemplates/Create/constants.js +15 -0
  238. package/containers/WeChat/RichmediaTemplates/Create/index.js +1071 -0
  239. package/containers/WeChat/RichmediaTemplates/Create/messages.js +165 -0
  240. package/containers/WeChat/RichmediaTemplates/Create/reducer.js +60 -0
  241. package/containers/WeChat/RichmediaTemplates/Create/richmediaschema.js +497 -0
  242. package/containers/WeChat/RichmediaTemplates/Create/sagas.js +51 -0
  243. package/containers/WeChat/RichmediaTemplates/Create/selectors.js +37 -0
  244. package/containers/WeChat/RichmediaTemplates/Create/test/saga.test.js +13 -0
  245. package/containers/WeChat/RichmediaTemplates/Edit/actions.js +20 -0
  246. package/containers/WeChat/RichmediaTemplates/Edit/constants.js +10 -0
  247. package/containers/WeChat/RichmediaTemplates/Edit/index.js +136 -0
  248. package/containers/WeChat/RichmediaTemplates/Edit/messages.js +13 -0
  249. package/containers/WeChat/RichmediaTemplates/Edit/reducer.js +28 -0
  250. package/containers/WeChat/RichmediaTemplates/Edit/sagas.js +36 -0
  251. package/containers/WeChat/RichmediaTemplates/Edit/selectors.js +30 -0
  252. package/containers/WeChat/RichmediaTemplates/Edit/test/saga.test.js +12 -0
  253. package/containers/WeChat/RichmediaTemplates/View/actions.js +15 -0
  254. package/containers/WeChat/RichmediaTemplates/View/constants.js +7 -0
  255. package/containers/WeChat/RichmediaTemplates/View/index.js +47 -0
  256. package/containers/WeChat/RichmediaTemplates/View/messages.js +21 -0
  257. package/containers/WeChat/RichmediaTemplates/View/reducer.js +23 -0
  258. package/containers/WeChat/RichmediaTemplates/View/sagas.js +11 -0
  259. package/containers/WeChat/RichmediaTemplates/View/selectors.js +25 -0
  260. package/index.js +2 -4
  261. package/package.json +1 -1
  262. package/routes.js +202 -136
  263. package/services/getSchema.js +1 -1
  264. package/services/localStorageApi.js +0 -1
  265. package/tests/i18n.test.js +1 -1
  266. package/utils/asyncInjectors.js +78 -0
  267. package/utils/authWrapper.js +1 -1
  268. package/utils/callNativeEvent.js +16 -0
  269. package/utils/checkStore.js +21 -0
  270. package/utils/common.js +2 -2
  271. package/utils/customAuthWrapper.js +62 -0
  272. package/utils/customConnectedAuthWrapper.js +26 -0
  273. package/utils/tagValidations.js +1 -1
  274. package/utils/tests/authWrapper.test.js +1 -1
  275. package/utils/tests/checkStore.test.js +1 -1
  276. package/utils/tests/customAuth.test.js +1 -1
  277. package/utils/transformerUtils.js +1 -1
  278. package/v2Components/CapTagList/index.js +14 -9
  279. package/v2Components/Carousel/style.scss +1 -1
  280. package/v2Components/EmailMobilePreview/index.js +2 -2
  281. package/v2Components/FormBuilder/index.js +2 -2
  282. package/v2Components/NavigationBar/tests/saga.test.js +31 -36
  283. package/v2Components/TemplatePreview/index.js +1 -2
  284. package/v2Containers/Cap/tests/saga.test.js +1 -1
  285. package/v2Containers/Email/index.js +1 -1
  286. package/v2Containers/FTP/index.js +1 -1
  287. package/v2Containers/Line/Container/Text/index.js +1 -1
  288. package/v2Containers/Sms/Create/index.js +1 -1
  289. package/v2Containers/Sms/Edit/index.js +1 -1
  290. package/v2Containers/TagList/index.js +1 -1
  291. package/v2Containers/TagList/utils.js +1 -1
  292. package/v2Containers/Templates/index.js +1 -1
  293. package/v2Containers/Templates/sagas.js +1 -1
  294. package/constants/unified.js +0 -189
@@ -0,0 +1,1610 @@
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));