@capillarytech/creatives-library 2.0.69 → 2.0.71

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