@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,1682 @@
1
+ /*
2
+ *
3
+ * Templates
4
+ *
5
+ */
6
+
7
+ import PropTypes from 'prop-types';
8
+
9
+ import React from 'react';
10
+ import { connect } from 'react-redux';
11
+ import {injectIntl, intlShape, FormattedMessage } from 'react-intl';
12
+ import { createStructuredSelector } from 'reselect';
13
+ import moment from "moment";
14
+ import _ from 'lodash';
15
+ import { bindActionCreators } from 'redux';
16
+ import { Modal} from 'antd';
17
+ import {CapMenu, CapDropdown, CapButton, CapInput, CapIcon, CapSelect, CapPopover, CapSpin, CapCustomCard, CapRow, CapSlideBox} from '@capillarytech/cap-ui-library';
18
+ import { makeSelectTemplates, makeSelectTemplatesResponse } from './selectors';
19
+ import { makeSelectCreate as makeSelectCreateSms} from '../Sms/Create/selectors';
20
+ import { makeSelectCreate as makeSelectCreateMobilePush } from '../MobilePush/Create/selectors';
21
+ import { makeSelectEbill as makeSelectCreateEbill } from '../Ebill/selectors';
22
+ import { makeSelectEmail as makeSelectCreateEmail } from '../Email/selectors';
23
+ import { makeSelectEdit } from '../Sms/Edit/selectors';
24
+ import { makeSelectLine } from '../Line/Create/selectors';
25
+ import { UserIsAuthenticated } from '../../utils/authWrapper';
26
+ import messages from './messages';
27
+ import {checkUnicode} from '../../utils/smsCharCountV2';
28
+ import * as actions from './actions';
29
+ import * as smsActions from '../Sms/Create/actions';
30
+ import * as mobilepushActions from '../MobilePush/Create/actions';
31
+ import * as smsEditActions from '../Sms/Edit/actions';
32
+ import * as ebillActions from '../Ebill/actions';
33
+ import * as emailActions from '../Email/actions';
34
+ import * as lineActions from '../Line/Create/actions';
35
+ import CardGrid from '../../components/CardGrid';
36
+ import './_templates.scss';
37
+ import * as globalActions from '../Cap/actions';
38
+ import { makeSelectAuthenticated } from '../Cap/selectors';
39
+ import {getMessageObject} from '../../utils/messageUtils';
40
+ import * as commonUtil from '../../utils/common';
41
+ import Pagination from '../../components/Pagination';
42
+ import EmailPreview from '../../components/EmailPreview';
43
+ import CreativesContainer from '../CreativesContainer';
44
+ import WechatRichmediaTemplatePreview from '../../components/TemplatePreview/WechatRichmediaTemplatePreview';
45
+ import { MOBILE_PUSH, WECHAT, SMS, EMAIL, EBILL, LINE } from '../CreativesContainer/constants';
46
+ const {CapCustomCardList} = CapCustomCard;
47
+
48
+ export class Templates extends React.Component { // eslint-disable-line react/prefer-stateless-function
49
+ constructor(props) {
50
+ super(props);
51
+ this.state = {
52
+ channel: '',
53
+ hoveredItem: '',
54
+ clickedItem: '',
55
+ previewOpen: false,
56
+ previewTemplate: {},
57
+ searchText: '',
58
+ sortBy: 'Most Recent',
59
+ selectedAccount: '',
60
+ page: 1,
61
+ perPageLimit: 25,
62
+ templatesCount: 0,
63
+ showEdmEmailTemplates: false,
64
+ showModal: false,
65
+ actionTemplate: {},
66
+ showHtmlPreview: false,
67
+ device: 'desktop',
68
+ searchedTemplates: false,
69
+ defaultAccount: true,
70
+ modeType: null,
71
+ routeParams: null,
72
+ };
73
+ this.handleOnHoverItem = this.handleOnHoverItem.bind(this);
74
+ this.handleOnItemClick = this.handleOnItemClick.bind(this);
75
+ this.handleEditClick = this.handleEditClick.bind(this);
76
+ this.handlePreviewClick = this.handlePreviewClick.bind(this);
77
+ this.createTemplate = this.createTemplate.bind(this);
78
+ this.duplicateTemplate = this.duplicateTemplate.bind(this);
79
+ this.deleteTemplate = this.deleteTemplate.bind(this);
80
+ this.togglePreview = this.togglePreview.bind(this);
81
+ this.searchTemplate = this.searchTemplate.bind(this);
82
+ this.handleSortBy = this.handleSortBy.bind(this);
83
+ this.getCurrentWindow = this.getCurrentWindow.bind(this);
84
+ this.handleFrameTasks = this.handleFrameTasks.bind(this);
85
+ this.startTemplateCreation = this.startTemplateCreation.bind(this);
86
+ this.startLoading = this.startLoading.bind(this);
87
+ this.prepareWeChatPreviewData = this.prepareWeChatPreviewData.bind(this);
88
+ this.prepareWeChatMappedPreviewData = this.prepareWeChatMappedPreviewData.bind(this);
89
+ this.onAccountSelect = this.onAccountSelect.bind(this);
90
+ this.prepareMobilePushPreviewData = this.prepareMobilePushPreviewData.bind(this);
91
+ this.menuOnClickEvent = this.menuOnClickEvent.bind(this);
92
+ }
93
+
94
+ componentWillMount() {
95
+ if (this.state.channel === '') {
96
+ let channel = '';
97
+
98
+ switch (this.props.route.name.toUpperCase()) {
99
+ case SMS:
100
+ channel = 'Sms';
101
+ break;
102
+ case MOBILE_PUSH:
103
+ channel = "MobilePush";
104
+ this.props.actions.getWeCrmAccounts(channel);
105
+ break;
106
+ case WECHAT:
107
+ channel = 'wechat';
108
+ this.props.actions.getWeCrmAccounts();
109
+ break;
110
+ case EMAIL:
111
+ channel = 'Email';
112
+ break;
113
+ case EBILL:
114
+ channel = 'Ebill';
115
+ break;
116
+ case LINE:
117
+ channel = "Line";
118
+ break;
119
+ default:
120
+ channel = '';
121
+ }
122
+ this.setState({ channel });
123
+ if (_.isEmpty(this.props.Templates.userList)) {
124
+ this.props.actions.getUserList();
125
+ }
126
+ }
127
+ }
128
+
129
+ componentDidMount() {
130
+ if (this.props.location.query.type === 'embedded' && this.isEnabledInLibraryModule("setLocale")) {
131
+ this.setLocale();
132
+ }
133
+ if (this.state.channel.toLowerCase() === 'line' || this.state.channel.toLowerCase() === 'sms' || this.state.channel.toLowerCase() === 'email' || this.state.channel.toLowerCase() === 'ebill' || ((this.state.channel.toLowerCase() === 'wechat' || this.state.channel.toLowerCase() === 'mobilepush') && !_.isEmpty(this.props.Templates.selectedWeChatAccount))) {
134
+ const queryParams = {
135
+ // name: this.state.searchText,
136
+ // sortBy: this.state.sortBy,
137
+ };
138
+ if (this.state.channel.toLowerCase() === 'wechat' && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
139
+ queryParams.wecrmId = this.props.Templates.selectedWeChatAccount.configs.wecrm_app_id;
140
+ queryParams.wecrmToken = this.props.Templates.selectedWeChatAccount.configs.wecrm_token;
141
+ queryParams.originalId = this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier;
142
+ }
143
+ if (this.state.channel.toLowerCase() === "mobilepush" && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
144
+ queryParams.accountId = this.props.Templates.selectedWeChatAccount.id;
145
+ }
146
+ queryParams.page = this.state.page;
147
+ queryParams.perPage = this.state.perPageLimit;
148
+ const channel = this.state.channel;
149
+ this.props.actions.getAllTemplates(channel, queryParams);
150
+ //this.getAllTemplates({});
151
+ // if (this.state.channel.toLowerCase() === "email") {
152
+ // this.props.actions.getEdmDefaultTemplates();
153
+ // }
154
+ }
155
+
156
+ window.addEventListener("message", this.handleFrameTasks);
157
+ }
158
+ componentWillReceiveProps(nextProps) {
159
+ const params = {
160
+ name: this.state.searchText,
161
+ sortBy: this.state.sortBy,
162
+ };
163
+ if (!_.isEmpty(this.props.TemplatesList) && !this.props.Templates.getAllTemplatesInProgress && this.props.TemplatesList[0] && this.props.TemplatesList[0].totalCount && this.state.templatesCount === 0) {
164
+ this.setState({templatesCount: this.props.TemplatesList[0].totalCount});
165
+ }
166
+ if (!_.isEqual(nextProps.route.name, this.props.route.name)) {
167
+ let channel = '';
168
+ this.props.actions.resetTemplate();
169
+ this.props.actions.resetAccount();
170
+ if (nextProps.route.name.toLowerCase() === 'sms') {
171
+ channel = 'Sms';
172
+ } else if (nextProps.route.name.toLowerCase() === 'wechat') {
173
+ this.setState({defaultAccount: true});
174
+ channel = 'wechat';
175
+ nextProps.actions.getWeCrmAccounts();
176
+ } else if (nextProps.route.name.toLowerCase() === 'email') {
177
+ channel = 'Email';
178
+ // this.props.actions.getEdmDefaultTemplates();
179
+ } else if (nextProps.route.name.toLowerCase() === "mobilepush") {
180
+ this.setState({defaultAccount: true});
181
+ channel = "mobilepush";
182
+ nextProps.actions.getWeCrmAccounts(channel);
183
+ } else if (nextProps.route.name.toLowerCase() === 'ebill') {
184
+ channel = 'Ebill';
185
+ } else if (nextProps.route.name.toLowerCase() === 'line') {
186
+ channel = 'Line';
187
+ }
188
+ this.setState({ channel }, () => {
189
+ if (this.state.channel.toLowerCase() === 'line' || this.state.channel.toLowerCase() === 'sms' || this.state.channel.toLowerCase() === 'email' || this.state.channel.toLowerCase() === 'ebill' || (this.state.channel.toLowerCase() === 'wechat' && !_.isEmpty(nextProps.Templates.selectedWeChatAccount))) {
190
+ if (this.state.channel.toLowerCase() === 'wechat' && !_.isEmpty(nextProps.Templates.selectedWeChatAccount)) {
191
+ params.wecrmId = nextProps.Templates.selectedWeChatAccount.configs.wecrm_app_id;
192
+ params.wecrmToken = nextProps.Templates.selectedWeChatAccount.configs.wecrm_token;
193
+ params.originalId = nextProps.Templates.selectedWeChatAccount.sourceAccountIdentifier;
194
+ }
195
+ if (this.state.channel.toLowerCase() === "mobilepush" && !_.isEmpty(nextProps.Templates.selectedWeChatAccount)) {
196
+ params.accountId = nextProps.Templates.selectedWeChatAccount.id;
197
+ }
198
+ this.getAllTemplates({params}, true);
199
+ }
200
+ });
201
+ }
202
+ if (this.state.channel.toLowerCase() === 'wechat' && nextProps.Templates.selectedWeChatAccount) {
203
+ params.wecrmId = nextProps.Templates.selectedWeChatAccount.configs.wecrm_app_id;
204
+ params.wecrmToken = nextProps.Templates.selectedWeChatAccount.configs.wecrm_token;
205
+ params.originalId = nextProps.Templates.selectedWeChatAccount.sourceAccountIdentifier;
206
+ }
207
+ if (this.state.channel.toLowerCase() === "mobilepush" && nextProps.Templates.selectedWeChatAccount) {
208
+ params.accountId = nextProps.Templates.selectedWeChatAccount.id;
209
+ }
210
+ if ((this.state.channel.toLowerCase() === 'wechat' || this.state.channel.toLowerCase() === 'mobilepush') && _.isEmpty(nextProps.Templates.selectedWeChatAccount) && (this.props.location.query.type === 'embedded') && !this.isEnabledInLibraryModule("showAccountSelection")) {
211
+ let selectedAccount = '';
212
+ if (_.isEmpty(nextProps.Templates.weCrmAccounts)) {
213
+ return;
214
+ }
215
+ if (this.state.channel.toLowerCase() === 'wechat') {
216
+ _.forEach(nextProps.Templates.weCrmAccounts, (account) => {
217
+ if (account.configs && account.configs.is_wecrm_enabled) {
218
+ if (nextProps.location.query.source_account_id && account.sourceAccountIdentifier === nextProps.location.query.source_account_id) {
219
+ selectedAccount = account;
220
+ }
221
+ }
222
+ });
223
+ this.setState({selectedAccount: selectedAccount.name}, () => {
224
+ params.wecrmId = selectedAccount.configs.wecrm_app_id;
225
+ params.wecrmToken = selectedAccount.configs.wecrm_token;
226
+ params.originalId = selectedAccount.sourceAccountIdentifier;
227
+ nextProps.actions.setWeChatAccount(selectedAccount);
228
+ this.getAllTemplates({params});
229
+ });
230
+ } else if (this.state.channel.toLowerCase() === 'mobilepush' && (nextProps.location.query.account_id || nextProps.location.query.source_account_id)) {
231
+ _.forEach(nextProps.Templates.weCrmAccounts, (account) => {
232
+ if ((nextProps.location.query.account_id && account.id === Number(nextProps.location.query.account_id)) || (nextProps.location.query.source_account_id && account.sourceAccountIdentifier && account.sourceAccountIdentifier === nextProps.location.query.source_account_id)) {
233
+ selectedAccount = account;
234
+ }
235
+ });
236
+ this.props.actions.setWeChatAccount(selectedAccount);
237
+ params.accountId = Number(nextProps.location.query.account_id);
238
+ this.getAllTemplates({params});
239
+ }
240
+ }
241
+ if (this.state.channel.toLowerCase() === "mobilepush" && nextProps.CreateMobilePush && nextProps.CreateMobilePush.response && nextProps.CreateMobilePush.response.templateId && nextProps.CreateMobilePush.response.templateId !== '') {
242
+ if (this.state.channel.toLowerCase() === "mobilepush" && !_.isEmpty(nextProps.Templates.selectedWeChatAccount)) {
243
+ params.accountId = nextProps.Templates.selectedWeChatAccount.id;
244
+ }
245
+ const message = getMessageObject('success', `${this.state.channel} ${this.props.intl.formatMessage(messages.templateDuplicateSuccess)}`, true);
246
+ this.props.globalActions.addMessageToQueue(message);
247
+ this.getAllTemplates({params});
248
+ this.props.mobilepushActions.clearCreateResponse();
249
+ }
250
+
251
+ if (this.state.channel.toLowerCase() === "ebill" && nextProps.CreateEbill && nextProps.CreateEbill.createResponse && nextProps.CreateEbill.createResponse.templateId && nextProps.CreateEbill.createResponse.templateId !== '') {
252
+ const message = getMessageObject('success', `${this.state.channel} ${this.props.intl.formatMessage(messages.templateDuplicateSuccess)}`, true);
253
+ this.props.globalActions.addMessageToQueue(message);
254
+ this.getAllTemplates({params, resetPage: true});
255
+ this.props.ebillActions.clearStoreValues();
256
+ }
257
+
258
+ if (this.state.channel.toLowerCase() === "email" && nextProps.EmailCreate && nextProps.EmailCreate.duplicateResponse && nextProps.EmailCreate.duplicateResponse.templateId && nextProps.EmailCreate.duplicateResponse.templateId !== '') {
259
+ const message = getMessageObject('success', `${this.state.channel} ${this.props.intl.formatMessage(messages.templateDuplicateSuccess)}`, true);
260
+ this.props.globalActions.addMessageToQueue(message);
261
+ this.getAllTemplates({params, resetPage: true});
262
+ this.props.emailActions.clearStoreValues();
263
+ }
264
+
265
+ if (this.state.channel.toLowerCase() === "line" && nextProps.Line && nextProps.Line.response && nextProps.Line.response.templateId && nextProps.Line.response.templateId !== '') {
266
+ const message = getMessageObject('success', `${this.state.channel} ${this.props.intl.formatMessage(messages.templateDuplicateSuccess)}`, true);
267
+ this.props.globalActions.addMessageToQueue(message);
268
+ this.getAllTemplates({params, resetPage: true});
269
+ this.props.lineActions.clearCreateResponse();
270
+ }
271
+
272
+ if (nextProps.Create && this.props.Create && nextProps.Create.createTemplateError && !_.isEqual(nextProps.Create.createTemplateError, this.props.Create.createTemplateError)) {
273
+ const message = getMessageObject('error', this.props.intl.formatMessage(messages.somethingWentWrong), true);
274
+ this.props.globalActions.addMessageToQueue(message);
275
+ if (this.state.channel.toLowerCase() === "sms") {
276
+ this.props.smsActions.clearCreateResponse();
277
+ } else if (this.state.channel.toLowerCase() === "mobilepush") {
278
+ this.props.mobilepushActions.clearCreateResponse();
279
+ } else if (this.state.channel.toLowerCase() === "ebill") {
280
+ this.props.ebillActions.clearCreateResponse();
281
+ } else if (this.state.channel.toLowerCase() === "line") {
282
+ this.props.lineActions.clearCreateResponse();
283
+ }
284
+ }
285
+
286
+ if (nextProps.Edit && nextProps.Edit.editResponse && nextProps.Edit.editResponse.templateId && nextProps.Edit.editResponse.templateId !== '') {
287
+ this.props.smsEditActions.clearEditResponse();
288
+ }
289
+ if (!nextProps.Templates.deleteTemplateInProgress && !_.isEqual(nextProps.Templates.deleteTemplateInProgress, this.props.Templates.deleteTemplateInProgress) &&
290
+ nextProps.Templates.deleteResponse) {
291
+ const message = getMessageObject('success', `${this.state.channel.toUpperCase()} ${this.props.intl.formatMessage(messages['Template deleted successfully'])}`, true);
292
+ nextProps.globalActions.addMessageToQueue(message);
293
+ this.getAllTemplates({params, resetPage: true});
294
+ }
295
+
296
+ if (!nextProps.Templates.sendingFile && !_.isEqual(this.props.Templates.sendingFile, nextProps.Templates.sendingFile) && !nextProps.Templates.errorSendingFile) {
297
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
298
+ const isLanguageSupport = (this.props.location.query.isLanguageSupport) ? this.props.location.query.isLanguageSupport : true;
299
+ const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
300
+ const type = this.props.location.query.type;
301
+ if (this.isEnabledInLibraryModule("callCreateFromProps")) {
302
+ this.props.createNew();
303
+ return;
304
+ }
305
+ this.setState({routeParams: {
306
+ pathname: `/${nextProps.route.name.toLowerCase()}/create`,
307
+ query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module},
308
+ }});
309
+ }
310
+
311
+ if (!nextProps.Templates.sendingFile && !_.isEqual(this.props.Templates.sendingFile, nextProps.Templates.sendingFile) && nextProps.Templates.errorSendingFile) {
312
+ let errorMessage = this.props.intl.formatMessage(messages.zipUploadFailed);
313
+ if (nextProps.Templates.errorMessage && nextProps.Templates.errorMessage !== "") {
314
+ errorMessage = nextProps.Templates.errorMessage;
315
+ }
316
+ const message = getMessageObject('error', errorMessage, true);
317
+ nextProps.globalActions.addMessageToQueue(message);
318
+ }
319
+
320
+ if (!_.isEmpty(nextProps.Templates.templateDetails) && !_.isEqual(nextProps.Templates.templateDetails, this.props.Templates.templateDetails)) {
321
+ this.setState({previewTemplate: nextProps.Templates.templateDetails});
322
+ }
323
+
324
+ if (nextProps.Templates.weCrmAccounts !== undefined && nextProps.Templates.weCrmAccounts.length === 1 && this.state.defaultAccount && (['wechat', 'mobilepush'].indexOf(this.state.channel.toLowerCase()) > -1)) {
325
+ const paramsDefault = {
326
+ name: this.state.searchText,
327
+ sortBy: this.state.sortBy,
328
+ };
329
+ if (this.state.channel.toLowerCase() === 'wechat') {
330
+ paramsDefault.wecrmId = nextProps.Templates.weCrmAccounts[0].configs.wecrm_app_id;
331
+ paramsDefault.wecrmToken = nextProps.Templates.weCrmAccounts[0].configs.wecrm_token;
332
+ paramsDefault.originalId = nextProps.Templates.weCrmAccounts[0].sourceAccountIdentifier;
333
+ nextProps.actions.setWeChatAccount(nextProps.Templates.weCrmAccounts[0]);
334
+ } else if (this.state.channel.toLowerCase() === 'mobilepush') {
335
+ nextProps.actions.setWeChatAccount(nextProps.Templates.weCrmAccounts[0]);
336
+ paramsDefault.accountId = nextProps.Templates.weCrmAccounts[0].id;
337
+ }
338
+ this.setState({defaultAccount: false});
339
+ this.getAllTemplates({params: paramsDefault}, true);
340
+ }
341
+ }
342
+
343
+ componentWillUnmount() {
344
+ window.removeEventListener("message", this.handleFrameTasks);
345
+ this.props.actions.resetTemplateStoreData();
346
+ this.props.globalActions.clearMetaEntities();
347
+ // this.setState({defaultAccount: false});
348
+ }
349
+
350
+ onAccountSelect(value) {
351
+ this.setState({selectedAccount: value}, () => {
352
+ const params = {
353
+ name: this.state.searchText,
354
+ sortBy: this.state.sortBy,
355
+ };
356
+ if (this.state.channel.toLowerCase() === 'wechat') {
357
+ params.wecrmId = this.props.Templates.weCrmAccounts[_.findIndex(this.props.Templates.weCrmAccounts, { name: value})].configs.wecrm_app_id;
358
+ params.wecrmToken = this.props.Templates.weCrmAccounts[_.findIndex(this.props.Templates.weCrmAccounts, { name: value})].configs.wecrm_token;
359
+ this.props.actions.setWeChatAccount(this.props.Templates.weCrmAccounts[_.findIndex(this.props.Templates.weCrmAccounts, { name: value})]);
360
+ params.originalId = this.props.Templates.weCrmAccounts[_.findIndex(this.props.Templates.weCrmAccounts, { name: value})].sourceAccountIdentifier;
361
+ } else if (this.state.channel.toLowerCase() === 'mobilepush') {
362
+ this.props.actions.setWeChatAccount(this.props.Templates.weCrmAccounts[_.findIndex(this.props.Templates.weCrmAccounts, { name: value})]);
363
+ params.accountId = this.props.Templates.weCrmAccounts[_.findIndex(this.props.Templates.weCrmAccounts, { name: value})].id;
364
+ }
365
+ console.log("getAllTemplates params: ", params);
366
+ this.getAllTemplates({params, resetPage: true});
367
+ });
368
+ }
369
+ onPaginationChange = () => { this.getAllTemplates({getNextPage: true}); }
370
+ onCreateComplete = () => {
371
+ this.setState({routeParams: null});
372
+ }
373
+ getCurrentWindow(e) {
374
+ const response = {
375
+ action: e.action,
376
+ value: 'templates',
377
+ direction: e.value,
378
+ };
379
+ parent.postMessage(JSON.stringify(response), '*');
380
+ }
381
+ getCreativesParams = () => {
382
+ const routeParams = this.state.routeParams;
383
+ let creativesParams = {mode: ''};
384
+ if (!_.isEmpty(routeParams)) {
385
+ if (routeParams.pathname.indexOf('create') > -1) {
386
+ creativesParams.mode = 'create';
387
+ } else if (routeParams.pathname.indexOf('edit') > -1) {
388
+ creativesParams.mode = 'edit';
389
+ creativesParams._id = routeParams.pathname.split('/')[3];
390
+ creativesParams.type = this.state.channel.toUpperCase();
391
+ }
392
+ }
393
+ if (this.state.previewOpen) {
394
+ creativesParams.mode = 'preview';
395
+ creativesParams = {...creativesParams, ...this.state.previewTemplate};
396
+ }
397
+ return creativesParams;
398
+ }
399
+ getMappedLocale = (locale) => {
400
+ const map = {
401
+ 'en': 'en',
402
+ 'zh-cn': 'zh',
403
+ };
404
+ return map[locale];
405
+ };
406
+ setLocale = () => {
407
+ const user = localStorage.getItem('user');
408
+ let locale = 'en';
409
+ if (user) {
410
+ locale = JSON.parse(user).lang;
411
+ }
412
+ locale = this.getMappedLocale(locale);
413
+ //locale = 'zh';
414
+
415
+ moment.locale(locale);
416
+ };
417
+ getAllTemplates = ({params, getNextPage, resetPage}, resetTemplates) => {
418
+ let queryParams = params;
419
+ let page = this.state.page;
420
+ if (resetTemplates) {
421
+ queryParams.name = this.state.searchText;
422
+ queryParams.sortBy = this.state.sortBy;
423
+ queryParams.page = this.state.page;
424
+ queryParams.perPage = this.state.perPageLimit;
425
+ const channel = this.state.channel;
426
+ this.props.actions.getAllTemplates(channel, queryParams);
427
+ } else if ((resetPage || (page === 1 && this.state.templatesCount === 0) || page <= (this.state.templatesCount / this.state.perPageLimit))) {
428
+ if (getNextPage) {
429
+ page += 1;
430
+ }
431
+ let templatesCount = this.state.templatesCount;
432
+ if (resetPage) {
433
+ page = 1;
434
+ templatesCount = 0;
435
+ }
436
+ if (!params || _.isEmpty(params)) {
437
+ queryParams = {
438
+ name: this.state.searchText,
439
+ sortBy: this.state.sortBy,
440
+ };
441
+ if (this.state.channel.toLowerCase() === 'wechat' && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
442
+ queryParams.wecrmId = this.props.Templates.selectedWeChatAccount.configs.wecrm_app_id;
443
+ queryParams.wecrmToken = this.props.Templates.selectedWeChatAccount.configs.wecrm_token;
444
+ queryParams.originalId = this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier;
445
+ }
446
+ if (this.state.channel.toLowerCase() === "mobilepush" && !_.isEmpty(this.props.Templates.selectedWeChatAccount)) {
447
+ queryParams.accountId = this.props.Templates.selectedWeChatAccount.id;
448
+ if (this.state.mode) {
449
+ queryParams.mode = this.state.mode.toLowerCase();
450
+ }
451
+ }
452
+ }
453
+ this.setState({page, templatesCount}, () => {
454
+ queryParams.page = page;
455
+ queryParams.perPage = this.state.perPageLimit;
456
+ const channel = this.state.channel;
457
+ this.props.actions.getAllTemplates(channel, queryParams);
458
+ });
459
+ }
460
+ };
461
+ getTemplateDataForGrid = ({templates, handlers, filterContent, channel, isLoading, loadingTip}) => {
462
+ const currentChannel = channel.toUpperCase();
463
+ const cardDataList = templates && templates.length ? _.map(templates, (template) => {
464
+ const templateData =
465
+ {
466
+ key: `${currentChannel}-card-${template.name}`,
467
+ title: <span title={template.name} >{template.name}</span>,
468
+ extra: [
469
+ <CapIcon
470
+ style={{marginRight: '16px'}}
471
+ type="eye"
472
+ onClick={() => { if (this.props.isFullMode) { handlers.handlePreviewClick(template); } else { this.props.handlePeviewTemplate(template); } }}
473
+ />,
474
+ ],
475
+ hoverOption: <CapButton onClick={(e) => handlers.handleEditClick(e, template._id)}>{this.props.intl.formatMessage(this.props.isFullMode ? messages.creativesTemplatesEdit : messages.selectButton)}</CapButton>,
476
+ };
477
+ if (this.props.isFullMode) {
478
+ templateData.extra.push(<CapDropdown
479
+ overlay={
480
+ <CapMenu>
481
+ <CapMenu.Item onClick={() => this.duplicateTemplate(template)}>
482
+ <FormattedMessage {...messages.duplicateButton} />
483
+ </CapMenu.Item>
484
+ <CapMenu.Item
485
+ onClick={() => this.deleteTemplate(template)}
486
+ >
487
+ <FormattedMessage {...messages.deleteButton} />
488
+ </CapMenu.Item>
489
+ </CapMenu>
490
+ }
491
+ >
492
+ <CapIcon type="more" />
493
+ </CapDropdown>);
494
+ }
495
+ if (currentChannel === "SMS") {
496
+ templateData.content = template.versions.base['sms-editor'];
497
+ } else if (currentChannel === "EMAIL") {
498
+ templateData.url = template.versions.base.preview_http_url;
499
+ } else if (currentChannel === "MOBILEPUSH" && template.type === "MOBILEPUSH") {
500
+ templateData.content = template;
501
+ }
502
+ return templateData;
503
+ }) : [];
504
+ return (<div>
505
+ {filterContent}
506
+ <CapSpin spinning={isLoading} tip={loadingTip}>
507
+ {!_.isEmpty(templates) && <div className="pagination-container">
508
+ <CapCustomCardList key={`${currentChannel}-card-list`} cardList={cardDataList} type={currentChannel} />
509
+ </div>}
510
+ {(this.state.selectedAccount === '' && _.isEmpty(this.props.Templates.selectedWeChatAccount)) && (this.state.channel.toLowerCase() === 'wechat' || this.state.channel.toLowerCase() === "mobilepush") && <div style={{ height: '65vh', textAlign: 'center', lineHeight: '65vh'}}>
511
+ <span style={{ fontFamily: 'open-sans', fontSize: '24px', color: '#B5B5B5'}}>{this.props.intl.formatMessage(messages.noAccountMessage)}</span>
512
+ </div>}
513
+ </CapSpin>
514
+
515
+ </div>);
516
+ }
517
+ skipTemplateSelection = (e) => {
518
+ const type = this.props.location.query.type;
519
+ const module = (type === 'embedded') ? this.props.location.query.module : 'default';
520
+ let routeParams = {};
521
+ if (this.state.channel.toLowerCase() === 'email') {
522
+ const isLanguageSupport = this.props.location.query.isLanguageSupport || false;
523
+ routeParams = {
524
+ pathname: `/email/view`,
525
+ query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport} : {},
526
+ };
527
+ } else if (this.state.channel.toLowerCase() === 'sms') {
528
+ routeParams = {
529
+ pathname: `/sms/view`,
530
+ query: type === 'embedded' ? {type: 'embedded', module} : {},
531
+ };
532
+ } else if (this.state.channel.toLowerCase() === 'mobilepush') {
533
+ routeParams = {
534
+ pathname: `/mobilepush/edit/${e.template_id}`,
535
+ query: type === 'embedded' ? {type: 'embedded', module, account_id: e.account_id} : {},
536
+ };
537
+ } else if (this.state.channel.toLowerCase() === 'wechat') {
538
+ if (e.template_type && e.template_type === 'RICHMEDIA_WECHAT_TEMPLATE') {
539
+ this.props.router.push({
540
+ pathname: `/wechat/richmedia/edit/${e.template_id}`,
541
+ query: type === 'embedded' ? {type: 'embedded', module, source_account_id: e.source_account_id} : {},
542
+ });
543
+ } else {
544
+ this.props.router.push({
545
+ pathname: `/wechat/edit/${e.template_id}`,
546
+ query: type === 'embedded' ? {type: 'embedded', module, source_account_id: e.source_account_id} : {},
547
+ });
548
+ }
549
+ } else if (this.state.channel.toLowerCase() === 'line') {
550
+ routeParams = {
551
+ pathname: `/line/view/${e.msg_type}/`,
552
+ query: type === 'embedded' ? {type: 'embedded', module, account_id: e.account_id } : {},
553
+ };
554
+ }
555
+ this.setState({loading: true, routeParams});
556
+ }
557
+
558
+ handleMenuAction = (item) => {
559
+ if (item.key.toLowerCase() === 'uploadfile') {
560
+ document.getElementById('filename').click();
561
+ } else if (item.key.toLowerCase() === 'useeditor') {
562
+ this.toggleEdmEmailTemplateSelection();
563
+ }
564
+ };
565
+
566
+ handleBlankTemplateAction = (item, channel) => {
567
+ const type = this.props.location.query.type;
568
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
569
+ let routeParams = {};
570
+ if (item === "uploadFile") {
571
+ document.getElementById('filename').click();
572
+ } else if (item === "editor") {
573
+ this.toggleEdmEmailTemplateSelection();
574
+ } else if (this.isEnabledInLibraryModule("callCreateFromProps")) {
575
+ this.props.createNew(item);
576
+ } else if (item === 'textTemplate') {
577
+ routeParams = {
578
+ pathname: `/${channel === 'line' ? 'line' : 'mobilepush'}/create/text`,
579
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
580
+ };
581
+ } else if (item === 'imageTemplate') {
582
+ routeParams = {
583
+ pathname: `/${channel === 'line' ? 'line' : 'mobilepush'}/create/image`,
584
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
585
+ };
586
+ }
587
+ this.setState({routeParams});
588
+ }
589
+
590
+ handleFileUpload = (e, {files}) => {
591
+ if (files.length === 0) {
592
+ return;
593
+ }
594
+ const fileExtension = files[0].name.split('.').pop();
595
+ const supportedZipFormats = ['zip'];
596
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
597
+ const isLanguageSupport = (this.props.location.query.isLanguageSupport) ? this.props.location.query.isLanguageSupport : true;
598
+ const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
599
+
600
+ if (supportedZipFormats.indexOf(fileExtension.toLowerCase()) !== -1) {
601
+ this.props.actions.handleZipUpload(files[0]);
602
+ document.getElementById("filename").value = "";
603
+ } else if (fileExtension === 'html' || fileExtension === 'htm') {
604
+ const reader = new FileReader();
605
+ reader.onload = () => {
606
+ const text = reader.result;
607
+ this.props.actions.handleHtmlUpload(text);
608
+ document.getElementById("filename").value = "";
609
+ const type = this.props.location.query.type;
610
+ if (this.isEnabledInLibraryModule("callCreateFromProps")) {
611
+ this.props.createNew();
612
+ return;
613
+ }
614
+ this.setState({routeParams: {
615
+ pathname: `/${this.props.route.name.toLowerCase()}/create`,
616
+ query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module},
617
+ }});
618
+ };
619
+ reader.readAsText(files[0]);
620
+ } else {
621
+ const message = getMessageObject('error', this.props.intl.formatMessage(messages.invalidUploadFileError), true);
622
+ this.props.globalActions.addMessageToQueue(message);
623
+ }
624
+ };
625
+
626
+ prepareWeChatPreviewData(template) {
627
+ if (template && template.versions && template.versions.base && !_.isEmpty(template.versions.base)) {
628
+ if (template.definition && template.definition.msgcontent && template.definition.msgcontent === "RICH_MEDIA_WECHAT") {
629
+ return template.versions.base.mediaList;
630
+ }
631
+ return this.prepareWeChatMappedPreviewData(template.versions.base.content, template.versions.base.Tag, template.versions.base.data);
632
+ }
633
+ return 'wrong template';
634
+ }
635
+
636
+ prepareWeChatMappedPreviewData(content, templateTags, tagData) {
637
+ let formattedContent = _.cloneDeep(content);
638
+ _.forEach(templateTags, (tag) => {
639
+ if (tagData[tag].value !== undefined) {
640
+ formattedContent = formattedContent.replace(`{{${tag}.DATA}}`, tagData[tag].value);
641
+ }
642
+ });
643
+ return formattedContent;
644
+ }
645
+
646
+ prepareMobilePushPreviewData(content) {
647
+ let result;
648
+ if (content.ANDROID) {
649
+ const data = content.ANDROID;
650
+ const bodyTextStyle = { WebkitLineClamp: 12};
651
+ if (data.expandableDetails && data.expandableDetails.ctas && ((data.expandableDetails.ctas[0] && data.expandableDetails.ctas[0].actionText) || (data.expandableDetails.ctas[1] && data.expandableDetails.ctas[1].actionText))) {
652
+ bodyTextStyle.WebkitLineClamp = 10;
653
+ }
654
+ if (data.expandableDetails && data.expandableDetails.image) {
655
+ bodyTextStyle.WebkitLineClamp = 3;
656
+ }
657
+ result = (
658
+ <div className="android-push-message-Container">
659
+ <div className="message-pop align-left">
660
+ <div className="message-container">
661
+ <div className="app-name">
662
+ <span className="app-icon"></span> {this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.name ? this.props.Templates.selectedWeChatAccount.name : "App name"}
663
+ </div>
664
+ <div className="title">
665
+ {data.title}
666
+ </div>
667
+ <div className="body-text" style={bodyTextStyle} >
668
+ {data.message}
669
+ </div>
670
+ {data.expandableDetails && data.expandableDetails.image && <div className="body-image">
671
+ <img src={data.expandableDetails.image} alt={data.expandableDetails.image}/>
672
+ </div>}
673
+ {(data.expandableDetails && data.expandableDetails.ctas && ((data.expandableDetails.ctas[0] && data.expandableDetails.ctas[0].actionText) || (data.expandableDetails.ctas[1] && data.expandableDetails.ctas[1].actionText))) &&
674
+ <div className="actions">
675
+ {_.map(data.expandableDetails.ctas, (action) => !!action.actionText &&
676
+ <span className="action">{action.actionText && action.actionText.toUpperCase()}</span>)}
677
+ </div>
678
+ }
679
+ </div>
680
+ </div>
681
+ </div>);
682
+ } else if (content.IOS) {
683
+ const data = content.IOS;
684
+ const bodyTextStyle = { WebkitLineClamp: 11};
685
+ if (data.expandableDetails && data.expandableDetails.ctas && data.expandableDetails.ctas[0] && data.expandableDetails.ctas[0].actionText) {
686
+ bodyTextStyle.WebkitLineClamp = 6;
687
+ }
688
+ if (data.expandableDetails && data.expandableDetails.image) {
689
+ bodyTextStyle.WebkitLineClamp = 1;
690
+ }
691
+ const iosActions = [];
692
+ if (data.expandableDetails.ctas && data.expandableDetails.ctas.length) {
693
+ if (data.expandableDetails.ctas[0].actionLabel) {
694
+ iosActions.push(<div className="actions">
695
+ <span className="action">{data.expandableDetails.ctas[0].actionLabel.toUpperCase()}</span>
696
+ </div>);
697
+ }
698
+ if (data.expandableDetails.ctas[0].actionLabel2) {
699
+ iosActions.push(<div className="actions">
700
+ <span className="action">{data.expandableDetails.ctas[0].actionLabel2.toUpperCase()}</span>
701
+ </div>);
702
+ }
703
+ }
704
+
705
+ result = (
706
+ <div className="iphone-push-message-Container">
707
+ <div className="message-pop align-left">
708
+ <div className="message-container">
709
+ <div className="app-name">
710
+ <span className="app-icon"></span>{this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.name ? this.props.Templates.selectedWeChatAccount.name : "App name"} <i className="material-icons">close</i>
711
+ </div>
712
+ {data.expandableDetails && data.expandableDetails.image && <div className={`body-image ${iosActions.length > 0 ? 'image-half' : ''}`}>
713
+ <img src={data.expandableDetails.image} alt={data.image}/>
714
+ </div>}
715
+ <div className="title">
716
+ {data.title}
717
+ </div>
718
+ <div className="body-text" style={bodyTextStyle}>
719
+ {data.message}
720
+ </div>
721
+ {data.expandableDetails && data.expandableDetails.ctas && data.expandableDetails.ctas[0] && data.expandableDetails.ctas[0].actionText && iosActions}
722
+ </div>
723
+ </div>
724
+ </div>);
725
+ }
726
+ return result;
727
+ }
728
+ startLoading(ifEdit) {
729
+ if (ifEdit) {
730
+ this.setState({loading: true});
731
+ }
732
+ }
733
+
734
+ startTemplateCreation(data) {
735
+ if (data.edit) {
736
+ const ifUnicode = checkUnicode(data.content);
737
+
738
+ const content = data.content;
739
+ const tempData = {
740
+ 'sms-editor': content,
741
+ 'unicode-validity': ifUnicode,
742
+ 'base': true,
743
+ };
744
+ const formData = {};
745
+ formData[0] = tempData;
746
+ formData.base = tempData;
747
+ this.setState({formData, loading: false});
748
+ }
749
+ }
750
+
751
+ handleFrameTasks = (e) => {
752
+ const type = e.data;
753
+ if (typeof type === 'object') {
754
+ const action = type.action;
755
+ switch (action) {
756
+ case "startTemplateCreation":
757
+ this.startTemplateCreation(type.value);
758
+ break;
759
+ case "startLoading":
760
+ this.startLoading(type.edit);
761
+ break;
762
+ case "getCurrentWindow":
763
+ this.getCurrentWindow(e.data);
764
+ break;
765
+ case "skipTemplateSelection":
766
+ this.skipTemplateSelection(e.data);
767
+ break;
768
+ default:
769
+ break;
770
+ }
771
+ }
772
+ switch (type) {
773
+ case "getFormData":
774
+ this.getFormData(e);
775
+ break;
776
+ case "startTemplateCreation":
777
+
778
+ //this.getFormData(e);
779
+ break;
780
+ case "validateContent":
781
+
782
+ this.validateContent(e);
783
+ break;
784
+ default:
785
+ break;
786
+ }
787
+ };
788
+
789
+ createTemplate(ev) {
790
+ const type = this.props.location.query.type;
791
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
792
+ const channel = this.state.channel.toLowerCase();
793
+ //const keyType = ev.key && ev.key.toLowerCase() !== undefined ? ev.state.toLowerCase() : '';
794
+ let routeParams = {};
795
+ if (this.isEnabledInLibraryModule("callCreateFromProps")) {
796
+ this.props.createNew();
797
+ } else if (ev.key && (ev.key.toLowerCase() === "text" || ev.key.toLowerCase() === "image")) {
798
+ routeParams = {
799
+ pathname: `/${channel === 'line' ? 'line' : 'mobilepush'}/create/${ev.key.toLowerCase()}`,
800
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
801
+ };
802
+ } else {
803
+ routeParams = {
804
+ pathname: `/${this.state.channel.toLowerCase()}/create`,
805
+ query: type === 'embedded' ? {type: 'embedded', module} : {module},
806
+ };
807
+ }
808
+ this.setState({routeParams});
809
+ }
810
+
811
+ menuOnClickEvent(ev) {
812
+ let type = this.props.location.query.type;
813
+ // const module = this.props.location.query.module ? this.props.location.query.module : 'default';
814
+ const channel = this.state.channel.toLowerCase();
815
+ switch (channel) {
816
+ case 'wechat':
817
+ if (ev && ev.key && ev.key.toLowerCase() === "map_template") {
818
+ type = this.props.location.query.type;
819
+ this.props.router.push({
820
+ pathname: `/wechat/create`,
821
+ query: type === 'embedded' ? {type: 'embedded'} : {},
822
+ });
823
+ } else if (ev && ev.key && ev.key.toLowerCase() === "richmedia_template") {
824
+ type = this.props.location.query.type;
825
+ if (this.props.Templates && this.props.Templates.selectedWeChatAccount && this.props.Templates.selectedWeChatAccount.configs && (_.isEmpty(this.props.Templates.selectedWeChatAccount.configs.wechat_app_id) || _.isEmpty(this.props.Templates.selectedWeChatAccount.configs.wechat_app_secret))) {
826
+ const errorMessage = this.props.intl.formatMessage(messages.wechatAccountNotConfigured);
827
+ const message = getMessageObject('error', errorMessage, true);
828
+ this.props.globalActions.addMessageToQueue(message);
829
+ } else {
830
+ this.props.router.push({
831
+ pathname: `/wechat/richmedia/create`,
832
+ query: type === 'embedded' ? {type: 'embedded'} : {},
833
+ });
834
+ }
835
+ }
836
+ break;
837
+ default:
838
+ this.props.router.push({
839
+ pathname: `*`,
840
+ });
841
+ break;
842
+ }
843
+ }
844
+
845
+ searchTemplate(data) {
846
+ this.setState({searchText: data}, () => {
847
+ const params = {
848
+ name: this.state.searchText,
849
+ sortBy: this.state.sortBy,
850
+ };
851
+ if (this.state.channel.toLowerCase() === 'wechat') {
852
+ params.wecrmId = this.props.Templates.selectedWeChatAccount.configs.wecrm_app_id;
853
+ params.wecrmToken = this.props.Templates.selectedWeChatAccount.configs.wecrm_token;
854
+ params.originalId = this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier;
855
+ }
856
+ if (this.state.channel.toLowerCase() === "mobilepush") {
857
+ params.accountId = this.props.Templates.selectedWeChatAccount.id;
858
+ }
859
+ this.getAllTemplates({params, resetPage: true});
860
+ });
861
+ }
862
+
863
+ handleSortBy(data) {
864
+ this.setState({sortBy: data}, () => {
865
+ const params = {
866
+ name: this.state.searchText,
867
+ sortBy: this.state.sortBy,
868
+ };
869
+ if (this.state.channel.toLowerCase() === 'wechat') {
870
+ params.wecrmId = this.props.Templates.selectedWeChatAccount.configs.wecrm_app_id;
871
+ params.wecrmToken = this.props.Templates.selectedWeChatAccount.configs.wecrm_token;
872
+ params.originalId = this.props.Templates.selectedWeChatAccount.sourceAccountIdentifier;
873
+ }
874
+ if (this.state.channel.toLowerCase() === "mobilepush") {
875
+ params.accountId = this.props.Templates.selectedWeChatAccount.id;
876
+ }
877
+ this.getAllTemplates({params, resetPage: true});
878
+ });
879
+ }
880
+ handleType = (data) => {
881
+ this.setState({mode: data}, () => {
882
+ const params = {
883
+ name: this.state.searchText,
884
+ sortBy: this.state.sortBy,
885
+ };
886
+ if (this.state.channel.toLowerCase() === "mobilepush") {
887
+ params.accountId = this.props.Templates.selectedWeChatAccount.id;
888
+ }
889
+ if ( (this.state.channel.toLowerCase() === 'mobilepush' || this.state.channel.toLowerCase() === 'line') && data.toLowerCase() !== "all") {
890
+ params.mode = this.state.mode.toLowerCase();
891
+ }
892
+ this.getAllTemplates({params, resetPage: true});
893
+ });
894
+ };
895
+ togglePreview() {
896
+ if (this.state.channel.toLowerCase() === 'ebill' || this.state.channel.toLowerCase() === 'email') {
897
+ this.toggleEmailPreview();
898
+ } else {
899
+ this.setState( (prevState) => ({
900
+ previewOpen: !prevState.previewOpen}));
901
+ }
902
+ }
903
+
904
+ toggleEdmEmailTemplateSelection = () => {
905
+ this.setState( (prevState) => ({
906
+ showEdmEmailTemplates: !prevState.showEdmEmailTemplates}), () => {
907
+ this.props.actions.getEdmDefaultTemplates();
908
+ });
909
+ };
910
+
911
+ deleteTemplate(template) {
912
+ this.props.actions.deleteTemplate(this.state.channel.toUpperCase(), template._id);
913
+ this.setState({actionTemplate: {}});
914
+ }
915
+
916
+ duplicateTemplate(template) {
917
+ const duplicateObj = _.cloneDeep(template);
918
+ duplicateObj.name = `Copy of ${template.name} ${moment().format('MM-DD-YYYY hh:mma')}`;
919
+ delete duplicateObj._id;
920
+ const params = {
921
+ name: this.state.searchText,
922
+ sortBy: this.state.sortBy,
923
+ };
924
+ if (this.state.channel.toLowerCase() === "sms") {
925
+ this.props.smsActions.createTemplate(duplicateObj, (response) => {
926
+ if (response && response.templateId) {
927
+ const message = getMessageObject('success', `${this.state.channel} ${this.props.intl.formatMessage(messages.templateDuplicateSuccess)}`, true);
928
+ this.props.globalActions.addMessageToQueue(message);
929
+ this.getAllTemplates({params, resetPage: true});
930
+ this.props.smsActions.clearCreateResponse();
931
+ }
932
+ });
933
+ } else if (this.state.channel.toLowerCase() === "mobilepush") {
934
+ duplicateObj.definition.accountId = this.props.Templates.selectedWeChatAccount.id;
935
+ this.props.mobilepushActions.createTemplate(duplicateObj);
936
+ } else if (this.state.channel.toLowerCase() === "ebill") {
937
+ this.props.ebillActions.createTemplate(duplicateObj);
938
+ } else if (this.state.channel.toLowerCase() === "email") {
939
+ this.props.emailActions.duplicateTemplate(template._id, "EMAIL");
940
+ } else if (this.state.channel.toLowerCase() === "line") {
941
+ this.props.lineActions.createTemplate(duplicateObj);
942
+ }
943
+ }
944
+
945
+ handleOnHoverItem(isHovering, id) {
946
+ if (isHovering) {
947
+ this.setState({hoveredItem: id});
948
+ } else {
949
+ this.setState({hoveredItem: ''});
950
+ }
951
+ }
952
+
953
+ handleOnItemClick(isClicked, id) {
954
+ this.setState({clickedItem: id});
955
+ }
956
+
957
+ handleEdmDefaultTemplateSelection = (isSelected, id) => {
958
+ if (isSelected) {
959
+ const data = _.find(this.props.Templates.cmsTemplates, {_id: id});
960
+ const type = this.props.location.query.type;
961
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
962
+ const isLanguageSupport = (this.props.location.query.isLanguageSupport) ? this.props.location.query.isLanguageSupport : true;
963
+ const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
964
+ let getQuery = '';
965
+
966
+ this.props.actions.setEdmTemplate(data);
967
+ if (this.state.channel && this.state.channel.toLowerCase() === 'email') {
968
+ getQuery = (type === 'embedded') ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module, isLanguageSupport, isEdmSupport};
969
+ } else {
970
+ getQuery = (type === 'embedded') ? {type: 'embedded', module} : {module};
971
+ }
972
+ if (this.isEnabledInLibraryModule("callCreateFromProps")) {
973
+ this.props.createNew();
974
+ return;
975
+ }
976
+ this.setState({routeParams: {
977
+ pathname: `/${this.state.channel.toLowerCase()}/create`,
978
+ query: getQuery,
979
+ }});
980
+ }
981
+ };
982
+
983
+ handleEditClick(e, id, modeType, path) {
984
+ if (modeType && modeType !== undefined) {
985
+ this.setState({modeType});
986
+ }
987
+ const type = this.props.location.query.type;
988
+ const module = this.props.location.query.module;
989
+ const isLanguageSupport = (this.props.location.query.isLanguageSupport) ? this.props.location.query.isLanguageSupport : false;
990
+ const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
991
+ let getQuery = "";
992
+ let pathName = path;
993
+ e.stopPropagation();
994
+
995
+ this.props.actions.resetTemplateData();
996
+ if (this.state.channel.toLowerCase() === 'sms') {
997
+ pathName = `/sms/edit/${id}`;
998
+ }
999
+ if (this.state.channel.toLowerCase() === 'mobilepush') {
1000
+ pathName = `/mobilepush/edit/${id}`;
1001
+ }
1002
+ if (this.state.channel.toLowerCase() === 'email') {
1003
+ pathName = `/email/edit/${id}`;
1004
+ }
1005
+ if (this.state.channel.toLowerCase() === 'email') {
1006
+ getQuery = type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module, isEdmSupport};
1007
+ } else {
1008
+ getQuery = type === 'embedded' ? {type: 'embedded', module, account_id: this.props.location.query.account_id} : {module};
1009
+ }
1010
+ if (this.state.channel.toLowerCase() === 'ebill') {
1011
+ pathName = `/ebill/edit/${id}`;
1012
+ }
1013
+ if (this.state.channel.toLowerCase() === 'line') {
1014
+ pathName = `/line/edit/${modeType}/${id}`;
1015
+ }
1016
+ if (this.isEnabledInLibraryModule("callSelectFromProps")) {
1017
+ this.props.onSelectTemplate(id);
1018
+ } else {
1019
+ if (this.state.channel.toLowerCase() === 'ebill') {
1020
+ pathName = `/ebill/edit/${id}`;
1021
+ }
1022
+ this.setState({routeParams: {
1023
+ pathname: pathName,
1024
+ query: getQuery,
1025
+ }});
1026
+ }
1027
+ }
1028
+
1029
+ handlePreviewClick(template, modeType) {
1030
+ this.togglePreview();
1031
+ const templateInfo = _.cloneDeep(template);
1032
+ if (this.state.channel.toLowerCase() === 'line') {
1033
+ templateInfo.modeType = modeType;
1034
+ }
1035
+ templateInfo.updatedByName = commonUtil.getUserNameById(parseInt(template.updatedBy, 10), commonUtil.getMergedUserList(this.props.Templates.userList));
1036
+ if (this.state.channel === 'wechat') {
1037
+ templateInfo.content = this.prepareWeChatPreviewData(template);
1038
+ } else if (this.state.channel.toLowerCase() === "mobilepush") {
1039
+ templateInfo.content = template.versions.base;
1040
+ templateInfo.appName = this.props.Templates.selectedWeChatAccount.name;
1041
+ } else if (this.state.channel.toLowerCase() === "email") {
1042
+ this.props.actions.getTemplateDetails(template._id);
1043
+ } else if (this.state.channel.toLowerCase() === 'ebill') {
1044
+ this.props.actions.getTemplateDetails(template._id);
1045
+ }
1046
+ if (this.state.channel.toLowerCase() !== 'ebill') {
1047
+ this.setState({previewTemplate: templateInfo});
1048
+ }
1049
+ }
1050
+
1051
+ toggleDeleteTemplateModal = (template) => {
1052
+ this.setState({actionTemplate: template}, () => {
1053
+ this.setState({showModal: true});
1054
+ });
1055
+ }
1056
+
1057
+ handleOk = () => {
1058
+ this.setState({showModal: false});
1059
+ this.deleteTemplate(this.state.actionTemplate);
1060
+ }
1061
+
1062
+ handleCancel = () => {
1063
+ this.setState({showModal: false});
1064
+ }
1065
+
1066
+ populateTemplatesList = (data, blankTemplateRequired, layoutSelection) => {
1067
+ if (!data) {
1068
+ return [];
1069
+ }
1070
+ const type = this.props.location.query.type;
1071
+ const items = [];
1072
+ const channel = this.state.channel.toLowerCase();
1073
+
1074
+ if (type === 'embedded' && channel !== 'wechat' && blankTemplateRequired) {
1075
+ let content;
1076
+ if (channel === 'sms') {
1077
+ content = (<div className="sms-template-content" onClick={this.createTemplate}>
1078
+ <div style={{textAlign: 'center', lineHeight: '260px'}} className="sms-text">{this.props.intl.formatMessage(messages.blankTemplate)}</div>
1079
+ </div>);
1080
+ } else if (channel === 'email') {
1081
+ content = (<div className="sms-template-content">
1082
+ <div style={{textAlign: 'center', lineHeight: '260px'}} className="sms-text">
1083
+ <div>
1084
+ <button type="button" className="ant-btn cap-button edit-button ant-btn-ghost" onClick={() => this.handleBlankTemplateAction('uploadFile')}><span>Upload File</span></button>
1085
+ <button type="button" className="ant-btn cap-button preview-button ant-btn-danger" onClick={() => this.handleBlankTemplateAction('editor')}><span>Use Editor</span></button>
1086
+ </div>
1087
+ </div>
1088
+ </div>);
1089
+ } else if (channel === 'mobilepush' || channel === 'line') {
1090
+ content = (<div className="sms-template-content">
1091
+ <div style={{textAlign: 'center', lineHeight: '260px'}} className="sms-text">
1092
+ <div>
1093
+ <button
1094
+ type="button"
1095
+ className="ant-btn cap-button edit-button ant-btn-ghost"
1096
+ onClick={() => this.handleBlankTemplateAction('textTemplate', channel)}>
1097
+ <span>{this.props.intl.formatMessage(messages.textTemplate)}</span>
1098
+ </button>
1099
+ <button
1100
+ type="button"
1101
+ className="ant-btn cap-button preview-button ant-btn-danger"
1102
+ onClick={() => this.handleBlankTemplateAction('imageTemplate', channel)}>
1103
+ <span>{this.props.intl.formatMessage(messages.imageTemplate)}</span>
1104
+ </button>
1105
+ </div>
1106
+ </div>
1107
+ </div>);
1108
+ }
1109
+ items.push(
1110
+ {
1111
+ id: 'blankTemplate',
1112
+ content,
1113
+ }
1114
+ );
1115
+ }
1116
+ data.map( (template) => {
1117
+ //
1118
+ const temp = {};
1119
+ //
1120
+ const updateDateTime = (moment().format('DD-MM-YYYY') === moment(template.updatedAt).format('DD-MM-YYYY')) ? moment(template.updatedAt).format('hh:mma') : moment(template.updatedAt).format('DD MMM YYYY');
1121
+ let content = '';
1122
+ temp.id = template._id;
1123
+ if (this.state.channel === 'wechat') {
1124
+ let path = '';
1125
+ if (template && template.versions && template.versions.base && !_.isEmpty(template.versions.base)) {
1126
+ if (template.definition && template.definition.msgcontent && template.definition.msgcontent === "RICH_MEDIA_WECHAT") {
1127
+ path = `/wechat/richmedia/edit/${template._id}`;
1128
+ content = <WechatRichmediaTemplatePreview type={this.props.location && this.props.location.query.type ? this.props.location.query.type : ''} content={template.versions.base.mediaList}/>;
1129
+ } else {
1130
+ path = `/wechat/edit/${template._id}`;
1131
+ content = this.prepareWeChatPreviewData(template);
1132
+ }
1133
+ temp.content = (
1134
+ <div
1135
+ className="sms-template-content">
1136
+ <div className={`sms-text ${this.state.hoveredItem === template._id ? 'sms-text-blurred' : ''}`}>
1137
+ {content || ''}
1138
+ </div>
1139
+ {template._id === this.state.hoveredItem ? <CapButton onClick={(e) => this.handleEditClick(e, template._id, null, path)} className="edit-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectButton) : this.props.intl.formatMessage(messages.editButton)}</CapButton> : ''}
1140
+ {template._id === this.state.hoveredItem ? <CapButton onClick={() => this.handlePreviewClick(template)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''}
1141
+ </div>
1142
+ );
1143
+ }
1144
+ } else if (this.state.channel.toLowerCase() === 'email' || this.state.channel.toLowerCase() === 'ebill') {
1145
+ //
1146
+
1147
+ const imgSrc = template && template.versions && template.versions.base ? template.versions.base.preview_http_url : '';
1148
+ // const ifPreviewGenerated = template && template.versions && template.versions.base ? template.versions.base.isPreviewGenerated : 0;
1149
+ content = <img src={imgSrc || ''} alt={this.props.intl.formatMessage(messages.previewGenerateText)} width="100%" height="100%"/>;
1150
+
1151
+ temp.content = (
1152
+ <div
1153
+ className="sms-template-content">
1154
+ <div className={`sms-text ${this.state.hoveredItem === template._id ? 'sms-text-blurred' : ''}`}>
1155
+ {content}
1156
+ </div>
1157
+ {!layoutSelection && template._id === this.state.hoveredItem ? <CapButton onClick={(e) => this.handleEditClick(e, template._id)} className="edit-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectButton) : this.props.intl.formatMessage(messages.editButton)}</CapButton> : ''}
1158
+ {layoutSelection && template._id === this.state.hoveredItem ? <CapButton onClick={() => this.handleEdmDefaultTemplateSelection(true, template._id)} className="select-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectDefaultButton) : this.props.intl.formatMessage(messages.selectDefaultButton)}</CapButton> : ''}
1159
+ {!layoutSelection && template._id === this.state.hoveredItem ? <CapButton onClick={() => this.handlePreviewClick(template)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''}
1160
+ </div>);
1161
+ } else if (this.state.channel.toLowerCase() === 'mobilepush') {
1162
+ content = this.prepareMobilePushPreviewData(template.versions.base);
1163
+ temp.content = (
1164
+ <div>
1165
+ <div className={`mobilepush-message ${this.state.hoveredItem === template._id ? 'sms-text-blurred' : ''}`}>
1166
+ {content || ''}
1167
+ </div>
1168
+ {template._id === this.state.hoveredItem ? <CapButton onClick={(e) => this.handleEditClick(e, template._id)} className="edit-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectButton) : this.props.intl.formatMessage(messages.editButton)}</CapButton> : ''}
1169
+ {template._id === this.state.hoveredItem ? <CapButton onClick={() => this.handlePreviewClick(template)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''}
1170
+ </div>);
1171
+ } else if (this.state.channel.toLowerCase() === 'line') {
1172
+ //content = template.versions.base.messages[0].Text;
1173
+ content = {
1174
+ bodyText: template.versions.base.content.messages[0].text ? template.versions.base.content.messages[0].text : '',
1175
+ bodyImage: template.versions.base.content.messages[0].originalContentUrl ? template.versions.base.content.messages[0].originalContentUrl : '',
1176
+ };
1177
+ const modeType = template.versions.base.content.messages[0].type;
1178
+ temp.content = (
1179
+ <div className="sms-template-content" key={template._id}>
1180
+ {content.bodyText ? <div className={`sms-text ${this.state.hoveredItem === template._id ? 'sms-text-blurred' : ''}`}>{content.bodyText || ''}</div> : ''}
1181
+ {content.bodyImage ? <div className={`sms-text ${this.state.hoveredItem === template._id ? 'sms-text-blurred' : ''}`}>
1182
+ <img src={content.bodyImage} role={"presentation"} style={{maxWidth: '100%', objectFit: 'cover', height: '100%'}}/></div> : ''}
1183
+ {template._id === this.state.hoveredItem ? <CapButton onClick={(e) => this.handleEditClick(e, template._id, modeType)} className="edit-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectButton) : this.props.intl.formatMessage(messages.editButton)}</CapButton> : ''}
1184
+ {template._id === this.state.hoveredItem ? <CapButton onClick={() => this.handlePreviewClick(template, modeType)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''}
1185
+ </div>
1186
+ );
1187
+ } else {
1188
+ content = template && template.versions && template.versions.base ? template.versions.base['sms-editor'] : '';
1189
+ for (let idx = 2; idx <= 5; idx += 1) {
1190
+ if ((content === '' || !content) && template && template.versions && template.versions.base && template && template.versions && template.versions.base[`sms-editor${idx}`]) {
1191
+ content = template.versions.base[`sms-editor${idx}`];
1192
+ }
1193
+ }
1194
+ temp.content = (
1195
+ <div
1196
+ className="sms-template-content">
1197
+ <div className={`sms-text ${this.state.hoveredItem === template._id ? 'sms-text-blurred' : ''}`}>{content || ''}</div>
1198
+ {template._id === this.state.hoveredItem ? <CapButton onClick={(e) => this.handleEditClick(e, template._id)} className="edit-button" type="secondary">{type === 'embedded' ? this.props.intl.formatMessage(messages.selectButton) : this.props.intl.formatMessage(messages.editButton)}</CapButton> : ''}
1199
+ {template._id === this.state.hoveredItem ? <CapButton onClick={() => this.handlePreviewClick(template)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''}
1200
+ </div>
1201
+ );
1202
+ }
1203
+ let availableTemplates = "Android";
1204
+ if (template.versions && template.versions.base && template.versions.base.ANDROID && template.versions.base.IOS) {
1205
+ availableTemplates = `${availableTemplates} & IOS`;
1206
+ } else if (template.versions && template.versions.base && template.versions.base.IOS) {
1207
+ availableTemplates = 'iOS';
1208
+ }
1209
+ let deleteOption = this.props.intl.formatMessage(messages.deleteButton);
1210
+ if (this.state.channel.toLowerCase() === 'wechat' && !template.definition) {
1211
+ deleteOption = this.props.intl.formatMessage(messages.unMapButton);
1212
+ }
1213
+ if (!layoutSelection) {
1214
+ temp.footer = (
1215
+ <div className="footer-container">
1216
+ <div className="card-title">
1217
+ <span className="template-name" style={{ fontWeight: `${this.state.channel.toLowerCase() === 'wechat' ? '400' : '600'}` }}>
1218
+ { template && template.versions && template.versions.history && template.versions.history.length > 1 && this.state.channel.toLowerCase() !== 'mobilepush' && <i style={{fontSize: '16px', margin: '0 8px 0 0', verticalAlign: 'middle'}} className="material-icons">filter_none</i>}
1219
+ {template.name}
1220
+ </span>
1221
+ {this.props.location.query.type !== 'embedded' && <CapPopover
1222
+ trigger="click"
1223
+ content={
1224
+ <div className="popover-content">
1225
+ {this.state.channel !== 'wechat' && <div className="popover-action-container">
1226
+ <span onClick={() => this.duplicateTemplate(template)} className="popover-action" style={{cursor: 'pointer', padding: '8px 0px'}}>{this.props.intl.formatMessage(messages.duplicateButton)}</span>
1227
+ </div>}
1228
+ <div className="popover-action-container">
1229
+ <span onClick={() => this.toggleDeleteTemplateModal(template)} className="popover-action" style={{cursor: 'pointer', padding: '8px 0px'}}>{deleteOption}</span>
1230
+ </div>
1231
+ </div>
1232
+ }
1233
+ placement="bottomRight"
1234
+ >
1235
+ <i className="material-icons options-icon">&#xE5D4;</i>
1236
+ </CapPopover>}
1237
+ </div>
1238
+ {this.state.channel.toLowerCase() === "mobilepush" ?
1239
+ <p className="card-detail">{availableTemplates}</p>
1240
+ :
1241
+ <p className="card-detail">{this.props.intl.formatMessage(messages.uploadedAt)}: {updateDateTime}</p>
1242
+ }
1243
+ </div>
1244
+ );
1245
+ }
1246
+ items.push(temp);
1247
+ return true;
1248
+ });
1249
+ return items;
1250
+ };
1251
+
1252
+ toggleEmailPreview = () => {
1253
+ this.setState({ showHtmlPreview: !this.state.showHtmlPreview }, () => {
1254
+ if (!this.state.showHtmlPreview) {
1255
+ this.setState({previewTemplate: {}});
1256
+ }
1257
+ });
1258
+ };
1259
+
1260
+ changePreviewDevice = (device) => {
1261
+ this.setState({ device });
1262
+ };
1263
+ //Gets called only when creatives gets used as node library
1264
+ isEnabledInLibraryModule = (property) => {
1265
+ if (this.props.location.query.type === "embedded" && this.props.location.query.module === "library") {
1266
+ switch (property) {
1267
+ case "showAccountSelection":
1268
+ return (this.props.route && (this.props.route.name.toLowerCase() === "wechat" || this.props.route.name.toLowerCase() === "mobilepush"));
1269
+ case "setLocale":
1270
+ return true;
1271
+ case "callCreateFromProps":
1272
+ return true;
1273
+ case "callSelectFromProps":
1274
+ return true;
1275
+ default:
1276
+ return false;
1277
+ }
1278
+ } else {
1279
+ return false;
1280
+ }
1281
+ }
1282
+ isFullMode = () => this.props.location.query.type !== "embedded" || this.props.isFullMode
1283
+ isCreateDisabled = () => {
1284
+ let isDisabled = this.isLoading();
1285
+ if (this.state.channel === MOBILE_PUSH || this.state.channel === WECHAT) {
1286
+ isDisabled = isDisabled || _.isEmpty(this.props.Templates.selectedWeChatAccount);
1287
+ }
1288
+ return isDisabled;
1289
+ }
1290
+
1291
+
1292
+ isLoading = () => {
1293
+ const lineLoader = (this.props.Templates.getAllTemplatesInProgress && this.state.channel.toLowerCase() === 'line');
1294
+ const smsLoader = (this.props.Templates.getAllTemplatesInProgress && this.state.channel.toLowerCase() === 'sms');
1295
+ const wechatLoader = (((this.state.selectedAccount !== '' && this.props.Templates.getAllTemplatesInProgress) || (this.props.Templates.fetchingWeCrmAccounts)) && this.state.channel.toLowerCase() === 'wechat');
1296
+ const mobilePushLoader = (((this.props.Templates.getAllTemplatesInProgress) || (this.props.Templates.fetchingWeCrmAccounts)) && this.state.channel.toLowerCase() === 'mobilepush');
1297
+ const emailLoader = ((this.props.Templates.getAllTemplatesInProgress || this.props.Templates.sendingFile) && this.state.channel.toLowerCase() === 'email');
1298
+ const ebillLoader = ((this.props.Templates.getAllTemplatesInProgress || this.props.Templates.sendingFile) && this.state.channel.toLowerCase() === 'ebill');
1299
+ const isLoading = ((wechatLoader !== undefined) ? wechatLoader : false) ||
1300
+ (smsLoader !== undefined ? smsLoader : false) ||
1301
+ (emailLoader !== undefined ? emailLoader : false) ||
1302
+ (ebillLoader !== undefined ? ebillLoader : false) ||
1303
+ (mobilePushLoader !== undefined ? mobilePushLoader : false) ||
1304
+ (lineLoader !== undefined ? lineLoader : false);
1305
+ return isLoading;
1306
+ }
1307
+ renderEmailPreviewModal() {
1308
+ const slideboxContent = (
1309
+ <div style={{height: "75vh", width: '55vw'}}>
1310
+ <iframe />
1311
+ </div>
1312
+ );
1313
+
1314
+ return (
1315
+ <CapSlideBox
1316
+ header={this.state.previewTemplate.name}
1317
+ content={slideboxContent}
1318
+ show={this.state.showEmailPreviewModal}
1319
+ handleClose={this.toggleImagePreview}
1320
+ width={60}
1321
+ />
1322
+ );
1323
+ }
1324
+ renderDeleteConfirmationModal = () => {
1325
+ const modal =
1326
+ (<Modal
1327
+ visible={this.state.showModal}
1328
+ title={"Alert"}
1329
+ onOk={this.handleOk}
1330
+ onCancel={this.handleCancel}
1331
+ footer={[
1332
+ <CapButton key="back" onClick={this.handleCancel}>{this.props.intl.formatMessage(messages.cancelText)}</CapButton>,
1333
+ <CapButton key="submit" type="primary" id="delete-version" onClick={this.handleOk}>
1334
+ {this.props.intl.formatMessage(messages.yesText)}
1335
+ </CapButton>,
1336
+ ]}
1337
+ >
1338
+ {this.props.intl.formatMessage(messages.templateDeleteConfirm)}
1339
+ </Modal>);
1340
+ return modal;
1341
+ };
1342
+ render() {
1343
+ const accountOptions = [];
1344
+ const isFullMode = this.isFullMode();
1345
+ if ((this.state.channel.toUpperCase() === 'WECHAT' || this.state.channel.toUpperCase() === "MOBILEPUSH") && !_.isEmpty(this.props.Templates.weCrmAccounts)) {
1346
+ _.forEach(this.props.Templates.weCrmAccounts, (account) => {
1347
+ if ((this.state.channel.toUpperCase() === 'WECHAT' && account.configs && account.configs.is_wecrm_enabled) || this.state.channel.toUpperCase() === 'MOBILEPUSH') {
1348
+ if (this.props.location.query.type === 'embedded' && (!this.props.location.query.module || (this.props.location.query.module && this.props.location.query.module !== 'library'))) {
1349
+ if (this.props.location.query.source_account_id && account.sourceAccountIdentifier === this.props.location.query.source_account_id) {
1350
+ accountOptions.push(
1351
+ { key: this.state.channel.toUpperCase() === "MOBILEPUSH" ? account.id : account.uuid,
1352
+ label: account.name,
1353
+ value: account.name,
1354
+ }
1355
+ );
1356
+ } else if (this.props.location.query.module && (this.state.channel.toUpperCase() === "WECHAT" || this.state.channel.toUpperCase() === "MOBILEPUSH")) {
1357
+ accountOptions.push(
1358
+ {
1359
+ key: this.state.channel.toUpperCase() === "MOBILEPUSH" ? account.id : account.uuid,
1360
+ value: account.name,
1361
+ label: account.name,
1362
+ }
1363
+ );
1364
+ }
1365
+ } else {
1366
+ accountOptions.push(
1367
+ {
1368
+ key: this.state.channel.toUpperCase() === "MOBILEPUSH" ? account.id : account.uuid,
1369
+ value: account.name,
1370
+ label: account.name,
1371
+ }
1372
+ );
1373
+ }
1374
+ }
1375
+ });
1376
+ }
1377
+ const pageHeader = (
1378
+ <div>
1379
+ {(this.isEnabledInLibraryModule("showAccountSelection") || (((this.state.channel.toUpperCase() === 'WECHAT' || this.state.channel.toUpperCase() === "MOBILEPUSH") && (this.props.location.query.type !== 'embedded') && !_.isEmpty(this.props.Templates.weCrmAccounts)))) &&
1380
+ <CapSelect
1381
+ className="selectAccount"
1382
+ onSelect={this.onAccountSelect}
1383
+ value={this.props.Templates.selectedWeChatAccount ? this.props.Templates.selectedWeChatAccount.name : undefined}
1384
+ placeholder={this.props.intl.formatMessage(messages.selectAccount)}
1385
+ options={accountOptions}
1386
+ style={{width: '200px'}}
1387
+ />
1388
+ }
1389
+ </div>
1390
+ );
1391
+ const pageHeaderDvs = (
1392
+ <div>
1393
+ {((this.state.channel.toUpperCase() === 'WECHAT' || this.state.channel.toUpperCase() === "MOBILEPUSH") && (this.props.location.query.type === 'embedded') && !_.isEmpty(this.props.Templates.weCrmAccounts)) &&
1394
+ <CapSelect
1395
+ className="selectAccount"
1396
+ onSelect={this.onAccountSelect}
1397
+ value={this.props.Templates.selectedWeChatAccount ? this.props.Templates.selectedWeChatAccount.name : undefined} placeholder={this.props.intl.formatMessage(messages.selectAccount)}
1398
+ options={accountOptions}
1399
+ style={{width: '200px'}}
1400
+
1401
+ />
1402
+ }
1403
+ </div>
1404
+ );
1405
+ // let actionButton = '';
1406
+ // if (this.props.location.query.type !== 'embedded') {
1407
+ // if (this.state.channel.toUpperCase() === 'WECHAT') {
1408
+ // const createPushMenu = (
1409
+ // <Menu onClick={this.menuOnClickEvent}>
1410
+ // <MenuItem key="map_template">
1411
+ // {this.props.intl.formatMessage(messages.mapTemplate)}
1412
+ // </MenuItem>
1413
+ // <MenuItem key="richmedia_template">
1414
+ // {this.props.intl.formatMessage(messages.weChatRichmediaTemplate)}
1415
+ // </MenuItem>
1416
+ // </Menu>
1417
+ // );
1418
+ // actionButton = (<Dropdown disabled={_.isEmpty(this.props.Templates.selectedWeChatAccount)} overlay={createPushMenu} trigger={['click']}>
1419
+ // <CapButton style={{paddingLeft: '24px', paddingRight: '4px'}}>
1420
+ // <div style={{display: 'inline-flex'}}>
1421
+ // <p style={{ lineHeight: '28px'}}>{this.props.intl.formatMessage(messages.newTemplate)}</p>
1422
+ // <p style={{ height: '28px'}}>
1423
+ // <i style={{ color: '#fff', paddingTop: '2px', margin: '0', paddingRight: '8px'}} className="material-icons">arrow_drop_down</i>
1424
+ // </p>
1425
+ // </div>
1426
+ // </CapButton>
1427
+ // </Dropdown>);
1428
+ // } else if (this.state.channel.toUpperCase() === 'EMAIL' || this.state.channel.toUpperCase() === 'EBILL') {
1429
+ // const menuItems = [];
1430
+ // menuItems.push(<MenuItem key={'uploadFile'}>{this.props.intl.formatMessage(messages.uploadFile)}</MenuItem>);
1431
+ // menuItems.push(<MenuItem key={'useEditor'}>{this.props.intl.formatMessage(messages.useEditor)}</MenuItem>);
1432
+ // const menu = (
1433
+ // <Menu onClick={this.handleMenuAction}>
1434
+ // {menuItems}
1435
+ // </Menu>
1436
+ // );
1437
+ // actionButton = (
1438
+ // <Dropdown overlay={menu} trigger={["click"]}>
1439
+ // <CapButton style={{paddingLeft: '24px', paddingRight: '4px'}}>
1440
+ // <div style={{display: 'inline-flex'}}>
1441
+ // <p style={{ lineHeight: '32px', paddingRight: '12px' }}>{this.props.intl.formatMessage(messages.newTemplate)}</p>
1442
+ // <p style={{ height: '32px' }}>
1443
+ // <i style={{ color: '#fff', lineHeight: '32px', margin: '0'}} className="material-icons">arrow_drop_down</i>
1444
+ // </p>
1445
+ // </div>
1446
+ // </CapButton>
1447
+ // </Dropdown>
1448
+ // );
1449
+ // } else if (this.props.route.name.toLowerCase() === "mobilepush") {
1450
+ // const createPushMenu = (
1451
+ // <Menu onClick={this.createTemplate}>
1452
+ // <MenuItem key="text">
1453
+ // {this.props.intl.formatMessage(messages.textTemplate)}
1454
+ // </MenuItem>
1455
+ // <MenuItem key="image">
1456
+ // {this.props.intl.formatMessage(messages.imageTemplate)}
1457
+ // </MenuItem>
1458
+ // </Menu>
1459
+ // );
1460
+ // actionButton = (<Dropdown disabled={_.isEmpty(this.props.Templates.selectedWeChatAccount)} overlay={createPushMenu} trigger={['click']}>
1461
+ // <CapButton style={{paddingLeft: '24px', paddingRight: '4px'}}>
1462
+ // <div style={{display: 'inline-flex'}}>
1463
+ // <p style={{ lineHeight: '28px'}}>New Template</p>
1464
+ // <p style={{ height: '28px'}}>
1465
+ // <i style={{ color: '#fff', paddingTop: '2px', margin: '0', paddingRight: '8px'}} className="material-icons">arrow_drop_down</i>
1466
+ // </p>
1467
+ // </div>
1468
+ // </CapButton>
1469
+ // </Dropdown>);
1470
+ // } else if (this.props.route.name.toLowerCase() === "line") {
1471
+ // const lineMenu = (
1472
+ // <Menu onClick={this.createTemplate}>
1473
+ // <MenuItem key="text">
1474
+ // {this.props.intl.formatMessage(messages.textTemplate)}
1475
+ // </MenuItem>
1476
+ // <MenuItem key="image">
1477
+ // {this.props.intl.formatMessage(messages.imageTemplate)}
1478
+ // </MenuItem>
1479
+ // </Menu>
1480
+ // );
1481
+ // actionButton = (<Dropdown overlay={lineMenu} trigger={['click']}>
1482
+ // <CapButton style={{paddingLeft: '24px', paddingRight: '4px'}}>
1483
+ // <div style={{display: 'inline-flex'}}>
1484
+ // <p style={{ lineHeight: '28px'}}>New Template</p>
1485
+ // <p style={{ height: '28px'}}>
1486
+ // <i style={{ color: '#fff', paddingTop: '2px', margin: '0', paddingRight: '8px'}} className="material-icons">arrow_drop_down</i>
1487
+ // </p>
1488
+ // </div>
1489
+ // </CapButton>
1490
+ // </Dropdown>);
1491
+ // } else {
1492
+ // actionButton = (<CapButton onClick={this.createTemplate}>{this.state.channel.toUpperCase() === 'SMS' ? this.props.intl.formatMessage(messages.createSmsActionButton) : 'Create SMS'}</CapButton>);
1493
+ // }
1494
+ // }
1495
+
1496
+ const isLoading = this.isLoading();
1497
+ let previewHeader = this.props.intl.formatMessage(messages.preview);
1498
+ // const previewHeader = (this.state.channel.toLowerCase() === 'email' ? <h3>{this.props.intl.formatMessage(messages.emailPreview)}</h3> : <h3>{this.props.intl.formatMessage(messages.ebillPreview)}</h3>);
1499
+ if (this.state.channel.toLowerCase() === 'email' || this.state.channel.toLowerCase() === 'ebill') {
1500
+ if (this.state.previewTemplate && this.state.previewTemplate.name !== '') {
1501
+ previewHeader = this.state.previewTemplate.name;
1502
+ }
1503
+ }
1504
+
1505
+ const cmsTemplateSelectionContent = (
1506
+ <CardGrid
1507
+ className={""}
1508
+ listItem={this.populateTemplatesList(this.props.Templates.cmsTemplates, false, true)}
1509
+ // filterContent={filterContent}
1510
+ onHoverItem={this.handleOnHoverItem}
1511
+ onItemClick={this.handleEdmDefaultTemplateSelection}
1512
+ colNumber={2}
1513
+ >
1514
+ </CardGrid>
1515
+ );
1516
+ const filterContent = (
1517
+ <div className="action-container">
1518
+ <CapInput.Search
1519
+ className="search-text"
1520
+ style={{width: '210px'}}
1521
+ placeholder={this.props.intl.formatMessage(messages.searchText)}
1522
+ value={this.state.searchText}
1523
+ onChange={(e) => this.searchTemplate(e.target.value)}
1524
+ />
1525
+ <div style={{display: "flex", justifyContent: "space-between", alignItems: 'center'}}>
1526
+ {(this.props.location.query.type === 'embedded' ) ? pageHeaderDvs : pageHeader}
1527
+ <CapButton
1528
+ type={"primary"}
1529
+ disabled={this.isCreateDisabled()}
1530
+ style={{marginLeft: '8px'}}
1531
+ onClick={this.createTemplate} >
1532
+ { this.props.intl.formatMessage(messages.createNewActionButton) }
1533
+ </CapButton>
1534
+ </div>
1535
+
1536
+ </div>
1537
+ );
1538
+ let htmlPreviewContent = "";
1539
+ if (this.state.channel.toLowerCase() === 'ebill') {
1540
+ htmlPreviewContent = this.state.previewTemplate && this.state.previewTemplate.versions && this.state.previewTemplate.versions.base && this.state.previewTemplate.versions.base['ebill-editor'];
1541
+ } else if (this.state.channel.toLowerCase() === 'email') {
1542
+ htmlPreviewContent = this.state.previewTemplate && this.state.previewTemplate.versions && this.state.previewTemplate.versions.base && this.state.previewTemplate.versions.base[this.props.Global.currentOrgDetails.basic_details.base_language ? this.props.Global.currentOrgDetails.basic_details.base_language : 'en']['template-content'];
1543
+ }
1544
+
1545
+
1546
+ const creativesParams = this.getCreativesParams();
1547
+ const {route} = this.props;
1548
+ const loadingTip = (this.props.Templates.sendingFile && (this.state.channel.toLowerCase() === 'email' || this.state.channel.toLowerCase() === 'ebill')) ? this.props.intl.formatMessage(messages.uploadingFile) : this.props.intl.formatMessage(messages.gettingAllTemplates);
1549
+ return (
1550
+ <div>
1551
+ <input type="file" id="filename" style={{ display: 'none'}} accept=".zip, .html, .htm" onChange={(event) => this.handleFileUpload(event, {files: event.target.files})} />
1552
+
1553
+
1554
+ <CapRow>
1555
+ <Pagination onPageChange={this.onPaginationChange} paginationSelector="pagination-container">
1556
+ {this.getTemplateDataForGrid({isLoading, loadingTip, channel: this.state.channel, templates: this.props.TemplatesList, filterContent, handlers: {handlePreviewClick: this.handlePreviewClick, handleEditClick: this.handleEditClick}})}
1557
+ </Pagination>
1558
+ {/* {!this.props.renderNewCardGrid && ((templateList && templateList.length > 0) || isSearch) && // old UI GRID
1559
+ <Pagination onPageChange={this.onPaginationChange} paginationSelector="pagination-container">
1560
+ <CardGrid
1561
+ className={this.state.channel.toLowerCase() === "mobilepush" ? "mobilepush-templates" : ""}
1562
+ listItem={templateList}
1563
+ filterContent={filterContent}
1564
+ onHoverItem={this.handleOnHoverItem}
1565
+ onItemClick={this.handleOnItemClick}
1566
+ enablePagination
1567
+ isLoading={isLoading}
1568
+ loadingTip={loadingTip}
1569
+ >
1570
+ </CardGrid>
1571
+ </Pagination>} */}
1572
+ {(((this.state.selectedAccount !== '' && !_.isEmpty(this.props.Templates.selectedWeChatAccount) && this.state.channel.toLowerCase() === 'wechat') || this.state.channel.toLowerCase() !== 'wechat') && _.isEmpty(this.props.TemplatesList)) && !this.props.Templates.getAllTemplatesInProgress && <div style={{ height: '65vh', textAlign: 'center', lineHeight: '65vh'}}>
1573
+ <span style={{ fontFamily: 'open-sans', fontSize: '24px', color: '#B5B5B5'}}>{this.props.intl.formatMessage(messages.noTemplatesMessage)}</span>
1574
+ </div>}
1575
+ </CapRow>
1576
+ <CapRow>
1577
+ {!_.isEmpty(creativesParams.mode) && isFullMode && //creatives container for fullmode
1578
+ <CreativesContainer
1579
+ key={creativesParams.mode}
1580
+ messageDetails={{type: "default"}}
1581
+ creativesMode={creativesParams.mode}
1582
+ messages={messages}
1583
+ isFullMode={isFullMode}
1584
+ templateData={creativesParams}
1585
+ getCreativesData={this.onCreateComplete}
1586
+ channel={route.name.toUpperCase()}
1587
+ handleCloseCreatives={this.onCreateComplete}/>
1588
+ }
1589
+ </CapRow>
1590
+ <CapRow>
1591
+ {this.state.channel.toLowerCase() === 'wechat' && this.state.previewTemplate && this.state.previewTemplate.definition && this.state.previewTemplate.definition.msgcontent && this.state.previewTemplate.definition.msgcontent === 'RICH_MEDIA_WECHAT' &&
1592
+ <WechatRichmediaTemplatePreview
1593
+ show={this.state.previewOpen}
1594
+ closeSlideBox={this.togglePreview}
1595
+ header={this.state.previewTemplate.name}
1596
+ width={30}
1597
+ showSlidebox
1598
+ const type={this.props.location && this.props.location.query.type ? this.props.location.query.type : ''}
1599
+ content={this.state.previewTemplate.versions.base.mediaList}
1600
+ onEditClick={this.handleEditClick}
1601
+ showEdit
1602
+ templateId={this.state.previewTemplate._id}
1603
+ path={`/wechat/richmedia/edit/${this.state.previewTemplate._id}`}
1604
+ />
1605
+ }
1606
+
1607
+ {(this.state.channel.toLowerCase() === 'ebill' || this.state.channel.toLowerCase() === 'email') && htmlPreviewContent && <EmailPreview
1608
+ header={previewHeader}
1609
+ content={htmlPreviewContent}
1610
+ show={this.state.showHtmlPreview}
1611
+ device={this.state.device}
1612
+ handleClose={this.toggleEmailPreview}
1613
+ changePreviewDevice={this.changePreviewDevice}
1614
+ lastModified={this.state.previewTemplate ? this.state.previewTemplate.updatedAt : ''}
1615
+ updatedByName={commonUtil.getUserNameById(parseInt(this.state.previewTemplate.updatedBy, 10), commonUtil.getMergedUserList(this.props.Templates.userList))}
1616
+ />}
1617
+ <CapSlideBox
1618
+ header={(<h3>{this.props.intl.formatMessage(messages.layoutSelection)}</h3>)}
1619
+ width={60}
1620
+ content={cmsTemplateSelectionContent}
1621
+ show={this.state.showEdmEmailTemplates}
1622
+ handleClose={this.toggleEdmEmailTemplateSelection}
1623
+ loadingText={"Loading EDM Templates"}
1624
+ isLoading={this.props.Templates.getCmsTemplatesInProgress}
1625
+ />
1626
+ {this.renderDeleteConfirmationModal()}
1627
+ </CapRow>
1628
+
1629
+ </div>
1630
+ );
1631
+ }
1632
+ }
1633
+
1634
+ Templates.propTypes = {
1635
+ actions: PropTypes.object.isRequired,
1636
+ smsActions: PropTypes.object,
1637
+ mobilepushActions: PropTypes.object,
1638
+ smsEditActions: PropTypes.object,
1639
+ ebillActions: PropTypes.object,
1640
+ emailActions: PropTypes.object,
1641
+ TemplatesList: PropTypes.array,
1642
+ Templates: PropTypes.object,
1643
+ route: PropTypes.object,
1644
+ Create: PropTypes.object,
1645
+ location: PropTypes.object,
1646
+ globalActions: PropTypes.object,
1647
+ intl: intlShape.isRequired,
1648
+ Global: PropTypes.object,
1649
+ createNew: PropTypes.func,
1650
+ onSelectTemplate: PropTypes.func,
1651
+ lineActions: PropTypes.object,
1652
+ isFullMode: PropTypes.bool,
1653
+ handlePeviewTemplate: PropTypes.func,
1654
+ router: PropTypes.object,
1655
+ };
1656
+
1657
+ const mapStateToProps = createStructuredSelector({
1658
+ Templates: makeSelectTemplates(),
1659
+ TemplatesList: makeSelectTemplatesResponse(),
1660
+ Create: makeSelectCreateSms(),
1661
+ CreateMobilePush: makeSelectCreateMobilePush(),
1662
+ CreateEbill: makeSelectCreateEbill(),
1663
+ Edit: makeSelectEdit(),
1664
+ EmailCreate: makeSelectCreateEmail(),
1665
+ Global: makeSelectAuthenticated(),
1666
+ Line: makeSelectLine(),
1667
+ });
1668
+
1669
+ function mapDispatchToProps(dispatch) {
1670
+ return {
1671
+ actions: bindActionCreators(actions, dispatch),
1672
+ smsActions: bindActionCreators(smsActions, dispatch),
1673
+ mobilepushActions: bindActionCreators(mobilepushActions, dispatch),
1674
+ smsEditActions: bindActionCreators(smsEditActions, dispatch),
1675
+ ebillActions: bindActionCreators(ebillActions, dispatch),
1676
+ emailActions: bindActionCreators(emailActions, dispatch),
1677
+ globalActions: bindActionCreators(globalActions, dispatch),
1678
+ lineActions: bindActionCreators(lineActions, dispatch),
1679
+ };
1680
+ }
1681
+
1682
+ export default UserIsAuthenticated(connect(mapStateToProps, mapDispatchToProps)(injectIntl(Templates)));