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