@capillarytech/creatives-library 2.0.81 → 2.0.83

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 (241) hide show
  1. package/components/CapTagList/index.js +24 -21
  2. package/components/CardGrid/index.js +10 -16
  3. package/components/Ckeditor/index.js +1 -2
  4. package/components/CustomPopOver/index.js +1 -1
  5. package/components/EmailPreview/index.js +2 -3
  6. package/components/FormBuilder/_formBuilder.scss +15 -8
  7. package/components/FormBuilder/index.js +192 -258
  8. package/components/Header/index.js +1 -4
  9. package/components/PreviewSideBar/_previewsidebar.scss +1 -1
  10. package/components/PreviewSideBar/index.js +5 -3
  11. package/components/TemplatePreview/WechatRichmediaTemplatePreview/index.js +3 -2
  12. package/components/TemplatePreview/_templatePreview.scss +1 -1
  13. package/components/TemplatePreview/index.js +47 -47
  14. package/components/TemplatePreview/messages.js +1 -9
  15. package/containers/Assets/Gallery/index.js +1 -1
  16. package/containers/Email/index.js +1 -1
  17. package/containers/Login/components/LoginForm/index.js +1 -1
  18. package/containers/Templates/index.js +1 -1
  19. package/containers/WeChat/RichmediaTemplates/Create/index.js +1 -1
  20. package/package.json +2 -1
  21. package/v2Components/BreadCrumbs/index.js +65 -0
  22. package/v2Components/BreadCrumbs/messages.js +13 -0
  23. package/v2Components/BreadCrumbs/tests/index.test.js +10 -0
  24. package/v2Components/CallTaskPreview/_callTaskPreview.scss +17 -0
  25. package/v2Components/CallTaskPreview/images/Footer.png +0 -0
  26. package/v2Components/CallTaskPreview/images/Header.png +0 -0
  27. package/v2Components/CallTaskPreview/index.js +37 -0
  28. package/v2Components/CallTaskPreview/messages.js +13 -0
  29. package/v2Components/CallTaskPreview/tests/index.test.js +15 -0
  30. package/v2Components/CapTagList/index.js +232 -0
  31. package/v2Components/CapTagList/messages.js +25 -0
  32. package/{containers/TemplatesV2 → v2Components/CapTagList}/tests/index.test.js +2 -2
  33. package/v2Components/Card/_customCard.scss +27 -0
  34. package/v2Components/Card/index.js +78 -0
  35. package/{containers/WeChat → v2Components/Card}/tests/index.test.js +2 -2
  36. package/v2Components/CardGrid/index.js +77 -0
  37. package/{containers/EmailWrapper → v2Components/CardGrid}/tests/index.test.js +2 -2
  38. package/v2Components/Ckeditor/index.js +234 -0
  39. package/v2Components/Ckeditor/messages.js +13 -0
  40. package/{containers/ChannelTemplates → v2Components/Ckeditor}/tests/index.test.js +2 -2
  41. package/v2Components/CmsTemplatesComponent/index.js +33 -0
  42. package/v2Components/CmsTemplatesComponent/messages.js +17 -0
  43. package/v2Components/CmsTemplatesComponent/tests/index.test.js +10 -0
  44. package/v2Components/Component/index.js +29 -0
  45. package/v2Components/Component/tests/index.test.js +10 -0
  46. package/v2Components/CustomPopOver/index.js +82 -0
  47. package/v2Components/CustomPopOver/messages.js +13 -0
  48. package/v2Components/CustomPopOver/tests/index.test.js +10 -0
  49. package/v2Components/DateFilter/index.js +349 -0
  50. package/v2Components/DateFilter/messages.js +17 -0
  51. package/v2Components/DateFilter/tests/index.test.js +15 -0
  52. package/v2Components/DateRange/index.js +113 -0
  53. package/v2Components/DateRange/messages.js +13 -0
  54. package/v2Components/DateRange/tests/index.test.js +10 -0
  55. package/v2Components/Edmeditor/index.js +65 -0
  56. package/v2Components/Edmeditor/messages.js +13 -0
  57. package/v2Components/Edmeditor/tests/index.test.js +10 -0
  58. package/v2Components/EmailMobilePreview/index.js +129 -0
  59. package/v2Components/EmailMobilePreview/index.scss +55 -0
  60. package/v2Components/EmailPreview/_emailPreview.scss +119 -0
  61. package/v2Components/EmailPreview/index.js +106 -0
  62. package/v2Components/EmailPreview/messages.js +17 -0
  63. package/v2Components/EmailPreview/tests/index.test.js +10 -0
  64. package/v2Components/EmailPreviewV2/_emailPreviewV2.scss +69 -0
  65. package/v2Components/EmailPreviewV2/index.js +132 -0
  66. package/v2Components/EmailPreviewV2/messages.js +41 -0
  67. package/v2Components/EmailPreviewV2/tests/index.test.js +10 -0
  68. package/v2Components/Footer/index.js +27 -0
  69. package/v2Components/Footer/messages.js +13 -0
  70. package/v2Components/Footer/tests/index.test.js +10 -0
  71. package/v2Components/FormBuilder/_formBuilder.scss +78 -0
  72. package/v2Components/FormBuilder/index.js +3309 -0
  73. package/v2Components/FormBuilder/messages.js +13 -0
  74. package/v2Components/FormBuilder/tests/index.test.js +10 -0
  75. package/v2Components/Header/index.js +46 -0
  76. package/v2Components/Header/messages.js +25 -0
  77. package/v2Components/Header/tests/index.test.js +10 -0
  78. package/v2Components/ImagePreview/_imagePreview.scss +63 -0
  79. package/v2Components/ImagePreview/index.js +52 -0
  80. package/v2Components/ImagePreview/messages.js +13 -0
  81. package/v2Components/ImagePreview/tests/index.test.js +10 -0
  82. package/v2Components/MobilePushPreviewV2/index.js +120 -0
  83. package/v2Components/MobilePushPreviewV2/messages.js +13 -0
  84. package/{containers/MobilepushWrapper → v2Components/MobilePushPreviewV2}/tests/index.test.js +2 -2
  85. package/v2Components/NewCallTask/_newCallTask.scss +9 -0
  86. package/v2Components/NewCallTask/index.js +152 -0
  87. package/v2Components/NewCallTask/messages.js +29 -0
  88. package/{containers/CallTask → v2Components/NewCallTask}/tests/index.test.js +2 -2
  89. package/v2Components/PageHeader/_pageHeader.scss +22 -0
  90. package/v2Components/PageHeader/index.js +37 -0
  91. package/v2Components/PageHeader/messages.js +13 -0
  92. package/v2Components/PageHeader/tests/index.test.js +10 -0
  93. package/v2Components/Pagination/_pagination.scss +5 -0
  94. package/v2Components/Pagination/index.js +49 -0
  95. package/v2Components/Pagination/tests/index.test.js +10 -0
  96. package/v2Components/PreviewSideBar/_previewsidebar.scss +28 -0
  97. package/v2Components/PreviewSideBar/index.js +150 -0
  98. package/v2Components/PreviewSideBar/messages.js +33 -0
  99. package/v2Components/PreviewSideBar/tests/index.test.js +10 -0
  100. package/v2Components/Sidebar/_sidebar.scss +115 -0
  101. package/v2Components/Sidebar/index.js +208 -0
  102. package/v2Components/Sidebar/messages.js +21 -0
  103. package/v2Components/Sidebar/tests/index.test.js +10 -0
  104. package/v2Components/SlideBox/_slideBox.scss +63 -0
  105. package/v2Components/SlideBox/index.js +48 -0
  106. package/v2Components/SlideBox/tests/index.test.js +103 -0
  107. package/v2Components/SmsEditor/index.js +55 -0
  108. package/v2Components/SmsEditor/tests/index.test.js +10 -0
  109. package/v2Components/SmsTest/index.js +115 -0
  110. package/v2Components/SmsTest/messages.js +13 -0
  111. package/v2Components/SmsTest/tests/index.test.js +10 -0
  112. package/v2Components/TemplatePreview/WechatRichmediaTemplatePreview/_wechatRichmediaTemplatePrev.scss +42 -0
  113. package/v2Components/TemplatePreview/WechatRichmediaTemplatePreview/index.js +139 -0
  114. package/v2Components/TemplatePreview/WechatRichmediaTemplatePreview/messages.js +21 -0
  115. package/v2Components/TemplatePreview/WechatRichmediaTemplatePreview/tests/index.test.js +10 -0
  116. package/v2Components/TemplatePreview/_templatePreview.scss +352 -0
  117. package/v2Components/TemplatePreview/assets/images/WECHAT_5x.png +0 -0
  118. package/v2Components/TemplatePreview/assets/images/androidPushMessage.svg +45 -0
  119. package/v2Components/TemplatePreview/assets/images/iPhonePushMessage.svg +135 -0
  120. package/v2Components/TemplatePreview/assets/images/mobile.svg +24 -0
  121. package/v2Components/TemplatePreview/assets/images/sms-body.png +0 -0
  122. package/v2Components/TemplatePreview/assets/images/sms-icon.png +0 -0
  123. package/v2Components/TemplatePreview/assets/images/sms_mobile.png +0 -0
  124. package/v2Components/TemplatePreview/assets/images/user-icon.svg +19 -0
  125. package/v2Components/TemplatePreview/assets/images/wechat-mobile.svg +78 -0
  126. package/v2Components/TemplatePreview/index.js +175 -0
  127. package/v2Components/TemplatePreview/messages.js +37 -0
  128. package/v2Components/TemplatePreview/tests/index.test.js +10 -0
  129. package/v2Components/Toastr/index.js +60 -0
  130. package/v2Components/Toastr/messages.js +13 -0
  131. package/v2Components/Toastr/tests/index.test.js +10 -0
  132. package/v2Components/ToastrMessage/index.js +110 -0
  133. package/v2Components/ToastrMessage/messages.js +13 -0
  134. package/v2Components/ToastrMessage/tests/index.test.js +10 -0
  135. package/v2Components/TopBar/_topbar.scss +46 -0
  136. package/v2Components/TopBar/assets/images/capillary_logo.png +0 -0
  137. package/v2Components/TopBar/index.js +113 -0
  138. package/v2Components/TopBar/messages.js +29 -0
  139. package/v2Components/TopBar/tests/index.test.js +10 -0
  140. package/v2Containers/Assets/Gallery/index.js +1 -1
  141. package/v2Containers/CallTask/index.js +1 -1
  142. package/v2Containers/Cap/index.js +2 -2
  143. package/v2Containers/CreativesContainer/SlideBoxContent.js +3 -3
  144. package/v2Containers/CreativesContainer/index.js +1 -0
  145. package/v2Containers/Dashboard/index.js +2 -2
  146. package/v2Containers/Ebill/index.js +2 -2
  147. package/v2Containers/Email/index.js +13 -13
  148. package/v2Containers/EmailWrapper/index.js +1 -1
  149. package/v2Containers/Line/Create/index.js +1 -1
  150. package/v2Containers/Line/Edit/index.js +1 -1
  151. package/v2Containers/Login/index.js +1 -1
  152. package/v2Containers/MobilePush/Create/index.js +26 -3
  153. package/v2Containers/MobilePush/Edit/index.js +32 -7
  154. package/v2Containers/MobilePush/initialSchema.js +2 -0
  155. package/v2Containers/Sms/Create/index.js +1 -1
  156. package/v2Containers/Sms/Edit/index.js +1 -1
  157. package/v2Containers/TagList/index.js +1 -1
  158. package/v2Containers/Templates/index.js +4 -4
  159. package/v2Containers/TestPage/index.js +1 -1
  160. package/v2Containers/WeChat/MapTemplates/index.js +3 -3
  161. package/v2Containers/WeChat/RichmediaTemplates/Create/index.js +3 -3
  162. package/components/FormBuilder/test +0 -1845
  163. package/containers/CallTask/_callTask.scss +0 -5
  164. package/containers/CallTask/actions.js +0 -15
  165. package/containers/CallTask/constants.js +0 -7
  166. package/containers/CallTask/index.js +0 -141
  167. package/containers/CallTask/messages.js +0 -21
  168. package/containers/CallTask/reducer.js +0 -23
  169. package/containers/CallTask/sagas.js +0 -11
  170. package/containers/CallTask/selectors.js +0 -25
  171. package/containers/CallTask/tests/actions.test.js +0 -18
  172. package/containers/CallTask/tests/reducer.test.js +0 -9
  173. package/containers/CallTask/tests/sagas.test.js +0 -15
  174. package/containers/CallTask/tests/selectors.test.js +0 -10
  175. package/containers/ChannelTemplates/actions.js +0 -20
  176. package/containers/ChannelTemplates/constants.js +0 -8
  177. package/containers/ChannelTemplates/index.js +0 -48
  178. package/containers/ChannelTemplates/messages.js +0 -13
  179. package/containers/ChannelTemplates/reducer.js +0 -34
  180. package/containers/ChannelTemplates/sagas.js +0 -32
  181. package/containers/ChannelTemplates/selectors.js +0 -25
  182. package/containers/ChannelTemplates/tests/actions.test.js +0 -18
  183. package/containers/ChannelTemplates/tests/reducer.test.js +0 -9
  184. package/containers/ChannelTemplates/tests/sagas.test.js +0 -15
  185. package/containers/ChannelTemplates/tests/selectors.test.js +0 -10
  186. package/containers/CreativesContainer/SlideBoxContent.js +0 -248
  187. package/containers/CreativesContainer/SlideBoxFooter.js +0 -38
  188. package/containers/CreativesContainer/SlideBoxHeader.js +0 -65
  189. package/containers/CreativesContainer/actions.js +0 -27
  190. package/containers/CreativesContainer/constants.js +0 -13
  191. package/containers/CreativesContainer/index.js +0 -418
  192. package/containers/CreativesContainer/index.scss +0 -27
  193. package/containers/CreativesContainer/messages.js +0 -17
  194. package/containers/CreativesContainer/reducer.js +0 -29
  195. package/containers/CreativesContainer/sagas.js +0 -11
  196. package/containers/CreativesContainer/selectors.js +0 -30
  197. package/containers/CreativesContainer/tests/actions.test.js +0 -18
  198. package/containers/CreativesContainer/tests/index.test.js +0 -10
  199. package/containers/CreativesContainer/tests/reducer.test.js +0 -9
  200. package/containers/CreativesContainer/tests/sagas.test.js +0 -15
  201. package/containers/CreativesContainer/tests/selectors.test.js +0 -10
  202. package/containers/EmailWrapper/actions.js +0 -15
  203. package/containers/EmailWrapper/constants.js +0 -7
  204. package/containers/EmailWrapper/index.js +0 -238
  205. package/containers/EmailWrapper/messages.js +0 -57
  206. package/containers/EmailWrapper/reducer.js +0 -23
  207. package/containers/EmailWrapper/sagas.js +0 -11
  208. package/containers/EmailWrapper/selectors.js +0 -25
  209. package/containers/EmailWrapper/tests/actions.test.js +0 -18
  210. package/containers/EmailWrapper/tests/reducer.test.js +0 -9
  211. package/containers/EmailWrapper/tests/sagas.test.js +0 -15
  212. package/containers/EmailWrapper/tests/selectors.test.js +0 -10
  213. package/containers/MobilePush/commonMethods.js +0 -249
  214. package/containers/MobilePush/eventsMap.js +0 -127
  215. package/containers/MobilePush/initialSchema.js +0 -1739
  216. package/containers/MobilepushWrapper/_mobilepushWrapper.scss +0 -18
  217. package/containers/MobilepushWrapper/index.js +0 -97
  218. package/containers/MobilepushWrapper/messages.js +0 -25
  219. package/containers/TemplatesV2/_templatesV2.scss +0 -5
  220. package/containers/TemplatesV2/actions.js +0 -16
  221. package/containers/TemplatesV2/constants.js +0 -10
  222. package/containers/TemplatesV2/index.js +0 -207
  223. package/containers/TemplatesV2/messages.js +0 -29
  224. package/containers/TemplatesV2/selectors.js +0 -25
  225. package/containers/TemplatesV2/tests/actions.test.js +0 -18
  226. package/containers/TemplatesV2/tests/reducer.test.js +0 -9
  227. package/containers/TemplatesV2/tests/sagas.test.js +0 -15
  228. package/containers/TemplatesV2/tests/selectors.test.js +0 -10
  229. package/containers/WeChat/RichmediaTemplates/Create/testschema.js +0 -379
  230. package/containers/WeChat/_wechat.scss +0 -8
  231. package/containers/WeChat/actions.js +0 -52
  232. package/containers/WeChat/constants.js +0 -28
  233. package/containers/WeChat/index.js +0 -1635
  234. package/containers/WeChat/messages.js +0 -73
  235. package/containers/WeChat/reducer.js +0 -74
  236. package/containers/WeChat/sagas.js +0 -86
  237. package/containers/WeChat/selectors.js +0 -25
  238. package/containers/WeChat/tests/actions.test.js +0 -18
  239. package/containers/WeChat/tests/reducer.test.js +0 -9
  240. package/containers/WeChat/tests/sagas.test.js +0 -15
  241. package/containers/WeChat/tests/selectors.test.js +0 -10
@@ -0,0 +1,3309 @@
1
+ /* eslint-disable no-case-declarations */
2
+
3
+ /**
4
+ *
5
+ * FormBuilder
6
+ *
7
+ */
8
+
9
+ import PropTypes from 'prop-types';
10
+
11
+ import React from 'react';
12
+ import { Label } from 'semantic-ui-react';
13
+ import _ from 'lodash';
14
+ import { Tabs, Table, Modal} from 'antd';
15
+ import { CapButton, CapInput, CapPopover, CapCheckbox, CapRadio, CapSelect, CapTable, CapRow, CapColumn, CapNotification} from '@capillarytech/cap-ui-library';
16
+ import LabelHOC from '@capillarytech/cap-ui-library/assets/HOCs/ComponentWithLabelHOC';
17
+ import TemplatePreview from '../../components/TemplatePreview';
18
+ import TagList from '../../containers/TagList';
19
+ import SmsEditor from '../SmsEditor';
20
+ import SlideBox from '../SlideBox';
21
+ import CardGrid from '../CardGrid';
22
+ import CKEditor from "../../components/Ckeditor/";
23
+ import EDMEditor from "../../components/Edmeditor";
24
+ import CustomPopOver from '../../components/CustomPopOver';
25
+ import './_formBuilder.scss';
26
+ import {updateCharCount, checkUnicode} from "../../utils/smsCharCountV2";
27
+ const TabPane = Tabs.TabPane;
28
+ const {Column} = Table;
29
+ const {TextArea} = CapInput;
30
+ const {CapRadioGroup} = CapRadio;
31
+ // import styled from 'styled-components';
32
+
33
+ // import { FormattedMessage } from 'react-intl';
34
+ // import messages from './messages';
35
+ const isUrl = (str) => {
36
+ // eslint-disable-next-line no-useless-escape
37
+ const res = str.match(/(http(s)?:\/\/.)?(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=]*)/g);
38
+ return res;
39
+ };
40
+ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-stateless-function
41
+ constructor(props) {
42
+ super(props);
43
+ this.state = {
44
+ formData: {},
45
+ errorData: {},
46
+ currentTab: 1,
47
+ currentLangTab: 'en',
48
+ usingTabContainer: false,
49
+ tabCount: 1,
50
+ tabKey: '',
51
+ isFormValid: false,
52
+ checkValidation: false,
53
+ showModal: false,
54
+ modal: {},
55
+ currentEvent: {},
56
+ currentEventData: {},
57
+ popoverVisible: false,
58
+ customPopoverVisible: false,
59
+ };
60
+ this.renderForm = this.renderForm.bind(this);
61
+ this.updateFormData = this.updateFormData.bind(this);
62
+ this.callChildEvent = this.callChildEvent.bind(this);
63
+ this.renderColLabelSection = this.renderColLabelSection.bind(this);
64
+ this.renderMultiColSection = this.renderMultiColSection.bind(this);
65
+ this.renderSection = this.renderSection.bind(this);
66
+ this.renderContainer = this.renderContainer.bind(this);
67
+ this.renderParentSection = this.renderParentSection.bind(this);
68
+ this.initializeStandAloneSections = this.initializeStandAloneSections.bind(this);
69
+ this.initializeMultiColSection = this.initializeMultiColSection.bind(this);
70
+ this.initializeParentSection = this.initializeParentSection.bind(this);
71
+ this.initializeColLabelSection = this.initializeColLabelSection.bind(this);
72
+ this.initializeContainers = this.initializeContainers.bind(this);
73
+ this.cloneVersionData = this.cloneVersionData.bind(this);
74
+ this.markFinalTabVersion = this.markFinalTabVersion.bind(this);
75
+ this.duplicateVersion = this.duplicateVersion.bind(this);
76
+ this.deleteVersion = this.deleteVersion.bind(this);
77
+ this.renameVersion = this.renameVersion.bind(this);
78
+ this.resetState = this.resetState.bind(this);
79
+ this.onEdit = this.onEdit.bind(this);
80
+ this.changeVersionName = this.changeVersionName.bind(this);
81
+ this.hasClass = this.hasClass.bind(this);
82
+ this.validateForm = this.validateForm.bind(this);
83
+ this.indexOfEnd = this.indexOfEnd.bind(this);
84
+ this.saveForm = this.saveForm.bind(this);
85
+ this.initializeEditErrorData = this.initializeEditErrorData.bind(this);
86
+ this.checkIfSupportedTag = this.checkIfSupportedTag.bind(this);
87
+ this.transformInjectedTags = this.transformInjectedTags.bind(this);
88
+ this.handleSetRadioValue = this.handleSetRadioValue.bind(this);
89
+ this.formElements = [];
90
+ }
91
+
92
+ componentWillMount() {
93
+ this.setState({usingTabContainer: this.props.usingTabContainer ? this.props.usingTabContainer : false});
94
+ if (this.props.formData && (this.props.isEdit || (!this.props.isEdit && !_.isEmpty(this.props.formData)))) {
95
+ this.setState({formData: this.props.formData}, () => {
96
+ // if (!this.props.isNewVersionFlow) {
97
+ this.initialiseForm(this.props.schema, false, true);
98
+ // }
99
+ });
100
+ } else {
101
+ this.initialiseForm(this.props.schema, true);
102
+ }
103
+ }
104
+
105
+ componentWillReceiveProps(nextProps) {
106
+ const type = this.props.location.query.type;
107
+ const isLibraryModule = this.props.location.query.module === "library";
108
+ if (this.state.usingTabContainer && nextProps.tabCount !== this.props.tabCount) {
109
+ this.setState({tabCount: nextProps.tabCount});
110
+ }
111
+ if (nextProps.startValidation && nextProps.startValidation !== false && this.props.startValidation !== nextProps.startValidation) {
112
+ this.setState({checkValidation: true});
113
+ const ifValid = this.validateForm(null, null, null, true);
114
+
115
+ if (ifValid) {
116
+ this.saveForm(true);
117
+ } else {
118
+ this.props.stopValidation();
119
+ }
120
+ }
121
+ // if (nextProps.saveForm && this.props.saveForm !== nextProps.saveForm) {
122
+ // this.saveForm(saveForm);
123
+ // }
124
+ if (nextProps.isEdit) {
125
+ if (!_.isEqual(nextProps.formData, this.state.formData) && !_.isEmpty(nextProps.formData)) {
126
+ if (type === 'embedded' && !isLibraryModule) { //TODO: has to be checked and changed.
127
+ this.setState({checkValidation: true, formData: nextProps.formData}, () => {
128
+ this.validateForm();
129
+ });
130
+ // this.setState({formData: nextProps.formData}, () => {
131
+ // this.validateForm();
132
+ // });
133
+ }
134
+ //TODO change this structure
135
+ if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'WECHAT') {
136
+ this.setState({formData: nextProps.formData});
137
+ } else if ( !_.isEmpty(nextProps.formData) && !_.isEqual(this.state.formData, nextProps.formData) && this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH') {
138
+ this.setState({formData: nextProps.formData, tabCount: nextProps.tabCount});
139
+ // this.resetTabKeys(nextProps.formData, nextProps.tabCount);
140
+ } else if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'EMAIL') {
141
+ this.setState({formData: nextProps.formData});
142
+ }
143
+
144
+ if (this.state.usingTabContainer && this.state.tabKey === '') {
145
+ //this.setState({formData: nextProps.formData});
146
+ if (nextProps.isNewVersionFlow && !_.isEqual(this.state.tabKey, nextProps.tabKey)) {
147
+ this.setState({tabKey: nextProps.tabKey});
148
+ } else if (!nextProps.isNewVersionFlow) {
149
+ this.resetTabKeys(nextProps.formData, nextProps.tabCount);
150
+ }
151
+ this.initializeEditErrorData(nextProps.formData, nextProps.tabCount);
152
+ }
153
+ }
154
+ if (_.isEmpty(this.props.formData) && !_.isEmpty(nextProps.formData)) {
155
+ if (this.state.usingTabContainer) {
156
+ this.resetTabKeys(nextProps.formData, nextProps.tabCount);
157
+ }
158
+ this.initializeEditErrorData(nextProps.formData, nextProps.tabCount);
159
+ }
160
+ if (!_.isEmpty(this.props.formData) && this.props.formData !== this.state.formData && _.isEmpty(this.state.formData) && this.state.usingTabContainer) {
161
+ this.resetTabKeys(this.props.formData, nextProps.tabCount);
162
+ }
163
+ if ( this.state.usingTabContainer && nextProps.formData && !_.isEmpty(nextProps.formData) && _.isEmpty(this.props.formData) && nextProps.tabCount && this.state.tabCount !== nextProps.tabCount) {
164
+ this.setState({ formData: nextProps.formData, tabCount: nextProps.tabCount }, () => {
165
+ this.initializeEditErrorData(nextProps.formData, nextProps.tabCount);
166
+ if (this.state.usingTabContainer) {
167
+ this.resetTabKeys(nextProps.formData, nextProps.tabCount);
168
+ }
169
+ });
170
+ if (nextProps.tabCount > 1) {
171
+ this.setState({usingTabContainer: true});
172
+ }
173
+ }
174
+ // if (nextProps.currentTab) {
175
+ // this.setState({currentTab: nextProps.currentTab});
176
+ // }
177
+ } else if (!_.isEmpty(nextProps.formData) &&
178
+ ( !this.state.usingTabContainer || (this.state.usingTabContainer && nextProps.tabKey !== ''))
179
+ && !_.isEqual(nextProps.formData, this.state.formData) &&
180
+ !_.isEqual(nextProps.formData, this.props.formData)) {
181
+ this.setState({formData: nextProps.formData, tabKey: nextProps.tabKey}, () => {
182
+ this.validateForm();
183
+ });
184
+ //this.resetTabKeys(nextProps.formData, nextProps.tabCount);
185
+ } else if ((_.isEmpty(this.props.formData) || !this.props.formData) && _.isEmpty(this.state.formData)) {
186
+ this.initialiseForm(nextProps.schema, true);
187
+ } else if (_.isEmpty(this.props.formData) && !_.isEmpty(nextProps.formData)) {
188
+ this.setState({formData: nextProps.formData});
189
+ }
190
+
191
+ let currentLangTab = _.cloneDeep(this.state.currentLangTab);
192
+ if (nextProps.isNewVersionFlow && nextProps.formData[`${this.state.currentTab - 1}`] && nextProps.formData[`${this.state.currentTab - 1}`].activeTab) {
193
+ currentLangTab = nextProps.formData[`${this.state.currentTab - 1}`].activeTab;
194
+ }
195
+
196
+ if (nextProps.isNewVersionFlow && nextProps.currentTab && nextProps.currentTab !== this.props.currentTab) {
197
+ this.setState({currentTab: nextProps.currentTab});
198
+ }
199
+
200
+ if (!_.isEmpty(nextProps.formData) && !_.isEqual(this.state.formData, nextProps.formData)) {
201
+ if (nextProps.isNewVersionFlow) {
202
+ const tabKey = (this.state.tabKey !== nextProps.formData[nextProps.currentTab - 1].tabKey) ? nextProps.formData[nextProps.currentTab - 1].tabKey : this.state.tabKey;
203
+
204
+ this.setState({tabKey});
205
+ }
206
+ this.setState({formData: nextProps.formData, currentLangTab}, () => {
207
+ if (nextProps.isNewVersionFlow && !this.state.formData[this.state.currentTab - 1][this.state.formData[this.state.currentTab - 1].activeTab].tabKey) {
208
+ this.resetTabKeys(nextProps.formData, nextProps.tabCount, false, true);
209
+ }
210
+ if (type === 'embedded' || this.props.schema.channel.toUpperCase() === 'EMAIL') {
211
+ this.validateForm();
212
+ }
213
+ if ((this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH')) {
214
+ this.validateForm();
215
+ }
216
+ });
217
+ }
218
+
219
+
220
+ if (!_.isEqual(nextProps.schema, this.props.schema)) {
221
+ this.setState({ isFormValid: (this.props.isEdit ? this.props.isEdit : true) }, () => {
222
+ if (!this.props.isEdit || (this.props.isEdit && !_.isEmpty(nextProps.formData))) {
223
+ let resetTabKeys = (this.state.formData.tabKey === undefined);
224
+ if ((this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH')) {
225
+ resetTabKeys = false;
226
+ }
227
+ if (this.props.isNewVersionFlow) {
228
+ resetTabKeys = false;
229
+ }
230
+
231
+ this.initialiseForm(nextProps.schema, false, resetTabKeys);
232
+ this.validateForm();
233
+ }
234
+ });
235
+ }
236
+ if (!_.isEqual(nextProps.checkValidation, this.props.checkValidation)) {
237
+ this.setState({ checkValidation: nextProps.checkValidation });
238
+ }
239
+
240
+ if (this.props.currentTab !== nextProps.currentTab && nextProps.currentTab) {
241
+ this.setState({currentTab: nextProps.currentTab});
242
+ }
243
+
244
+ if (!_.isEmpty(nextProps.injectedTags) && !_.isEqual(nextProps.injectedTags, this.props.injectedTags)) {
245
+ this.validateForm(nextProps.tags, nextProps.injectedTags);
246
+ }
247
+ if (!_.isEmpty(nextProps.tags) && !_.isEqual(nextProps.tags, this.props.tags)) {
248
+ this.validateForm(nextProps.tags, nextProps.injectedTags);
249
+ }
250
+ if (!_.isEqual(nextProps.showModal, this.props.showModal)) {
251
+ this.setState({showModal: nextProps.showModal});
252
+ }
253
+ if (nextProps.modal && (!_.isEqual(nextProps.modal, this.props.modal) || _.isEmpty(this.state.modal))) {
254
+ this.setState({modal: nextProps.modal});
255
+ }
256
+ }
257
+
258
+ onEdit() {
259
+
260
+ }
261
+
262
+ getModal = () => {
263
+ let modal;
264
+ if (this.state.modal) {
265
+ if (this.state.modal.type === 'confirm') {
266
+ modal = (<Modal
267
+ visible={this.state.showModal}
268
+ title={this.state.modal.title}
269
+ onOk={this.handleOk}
270
+ onCancel={this.handleCancel}
271
+ footer={[
272
+ <CapButton key="back" onClick={this.handleCancel}>Cancel</CapButton>,
273
+ <CapButton key="submit" type="primary" id={this.state.modal.id} onClick={this.handleOk}>
274
+ Yes
275
+ </CapButton>,
276
+ ]}
277
+ >
278
+ {this.state.modal.body}
279
+ </Modal>);
280
+ } else if (this.state.modal.type === "info") {
281
+ modal = (<Modal
282
+ visible={this.state.showModal}
283
+ title={this.state.modal.title}
284
+ onOk={this.handleOk}
285
+ onCancel={this.handleCancel}
286
+ footer={[
287
+ <CapButton key="back" onClick={this.handleCancel}>Ok</CapButton>,
288
+ ]}
289
+ >
290
+ {this.state.modal.body}
291
+ </Modal>);
292
+ } else if (this.state.modal.type === "action") {
293
+ modal = (<Modal
294
+ visible={this.state.showModal}
295
+ title={this.state.modal.title}
296
+ onOk={this.handleOk}
297
+ onCancel={this.handleCancel}
298
+ footer={[
299
+ ]}
300
+ afterClose={this.handleCloseModal}
301
+ >
302
+ {this.state.modal.jsx}
303
+ </Modal>);
304
+ }
305
+ }
306
+ return modal;
307
+ };
308
+
309
+ openNotificationWithIcon = (type, message, key) => {
310
+ CapNotification.error({
311
+ key: key || type + message,
312
+ message: (`${type.toUpperCase()} ! ! ! `),
313
+ description: message, //'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
314
+ });
315
+ }
316
+
317
+ handleCloseModal = () => {
318
+ const event = this.state.currentEvent;
319
+ if (!_.isEmpty(this.state.currentEvent)) {
320
+ switch (event) {
321
+ case "addLanguage":
322
+ this.updateFormData(this.state.currentEventData, this.state.currentEventVal, this.state.currentEvent);
323
+ break;
324
+ default:
325
+ break;
326
+ }
327
+ }
328
+ }
329
+
330
+ handleVisibleChange = (popoverVisible) => {
331
+ this.setState({ popoverVisible });
332
+ };
333
+
334
+ handleCustomPopoverVisibleChange = (customPopoverVisible) => {
335
+ this.setState({ customPopoverVisible });
336
+ };
337
+
338
+ resetTabKeys(form, count, changeDefaultTab, setFormTabKey) {
339
+ const tabCount = count || this.state.tabCount;
340
+
341
+
342
+ const formData = _.cloneDeep(form);
343
+ let baseIndex = 0;
344
+ for (let idx = 0; idx < tabCount; idx += 1) {
345
+ if (this.props.isNewVersionFlow && formData[idx].selectedLanguages.length > 0) {
346
+ for (let langIndex = 0; langIndex < formData[idx].selectedLanguages.length; langIndex += 1 ) {
347
+ const id = _.uniqueId();
348
+ if (formData[idx][formData[idx].selectedLanguages[langIndex]]) {
349
+ if (!formData[idx][formData[idx].selectedLanguages[langIndex]].tabKey) {
350
+ formData[idx][formData[idx].selectedLanguages[langIndex]].tabKey = id;
351
+ }
352
+ if (formData[idx].base) {
353
+ formData.base[formData.base.selectedLanguages[langIndex]].tabKey = id;
354
+ }
355
+ }
356
+ }
357
+ if (setFormTabKey) {
358
+ if (!formData[idx].activeTab) {
359
+ const baseLanguage = this.props.baseLanguage;
360
+
361
+ formData[idx].tabKey = formData[idx][baseLanguage].tabKey;
362
+ } else {
363
+ formData[idx].tabKey = formData[idx][formData[idx].activeTab].tabKey;
364
+ }
365
+ if (formData[idx].base) {
366
+ if (!formData.base.activeTab) {
367
+ const baseLanguage = this.props.baseLanguage;
368
+ formData.base.tabKey = formData.base[baseLanguage].tabKey;
369
+ } else {
370
+ formData.base.tabKey = formData.base[formData[idx].activeTab].tabKey;
371
+ }
372
+ }
373
+ }
374
+
375
+ if (formData[idx].base && formData.base.activeTab) {
376
+ // if (!formData.base.tabKey) {
377
+
378
+ formData.base.tabKey = formData[idx][formData[idx].activeTab].tabKey;
379
+ //}
380
+ baseIndex = idx;
381
+ }
382
+ } else if (formData[idx]) {
383
+ if (!formData[idx].tabKey) {
384
+ formData[idx].tabKey = _.uniqueId();
385
+ }
386
+ if (formData[idx].base) {
387
+ formData.base = formData[idx];
388
+ baseIndex = idx;
389
+ }
390
+ }
391
+ }
392
+
393
+ if ((formData.base && formData.base.tabKey && formData.base.tabKey !== '' && !changeDefaultTab) || (formData.base && this.state.tabKey !== formData.base.tabKey)) {
394
+ if (this.state.currentTab === 1 && !this.props.isNewVersionFlow) {
395
+ this.setState({tabKey: formData.base.tabKey});
396
+ } else if (this.props.isNewVersionFlow && this.state.tabKey !== formData[this.state.currentTab - 1].tabKey) {
397
+ this.setState({tabKey: formData[this.state.currentTab - 1].tabKey});
398
+ }
399
+ }
400
+ if (setFormTabKey) {
401
+ this.setState({tabKey: formData.base.tabKey});
402
+ }
403
+
404
+
405
+ if (changeDefaultTab) {
406
+ this.setState({formData}, () => {
407
+ this.props.onChange(formData, this.state.tabCount);
408
+ this.validateForm();
409
+ });
410
+ } else {
411
+ this.setState({formData, currentTab: baseIndex + 1}, () => {
412
+ this.props.onChange(formData, this.state.tabCount);
413
+ this.validateForm();
414
+ });
415
+ }
416
+ }
417
+ isValidExternalLink = ({obj, key}) => {
418
+ if (key in obj) {
419
+ const url = _.get(obj, key);
420
+ return (url && url !== "" && isUrl(url));
421
+ }
422
+ return true;
423
+ }
424
+ /* eslint-disable */
425
+ validateForm(tags, injectedTags, isSave, showMessages) {
426
+
427
+
428
+ let isValid = true;
429
+ const type = (this.props.location && this.props.location.query.type) ? this.props.location.query.type : 'full';
430
+ const currentModule = (this.props.location && this.props.location.query.module) ? this.props.location.query.module : 'default';
431
+ const errorData = _.cloneDeep(this.state.errorData);
432
+ if (this.props.schema.channel === 'SMS') {
433
+
434
+ for (let count = 0; count < this.state.tabCount; count += 1) {
435
+ if (_.isEmpty(errorData[count])) {
436
+ return;
437
+ }
438
+ const index = count + 1;
439
+ if (!this.state.formData[count]) {
440
+ continue;
441
+ }
442
+ const content = this.state.formData[count][`sms-editor${index > 1 ? index : ''}`];
443
+ const unicodeCheck = this.state.formData[count][`unicode-validity${index > 1 ? index : ''}`];
444
+ const ifUnicode = content && content !== '' ? checkUnicode(content) : false;
445
+
446
+ let tagValidationResponse = false;
447
+ if (content) {
448
+ tagValidationResponse = this.validateTags(content, tags, injectedTags);
449
+ }
450
+
451
+ if (tagValidationResponse.valid) {
452
+ errorData[count][`sms-editor${index > 1 ? index : ''}`] = false;
453
+ } else {
454
+
455
+ errorData[count][`sms-editor${index > 1 ? index : ''}`] = true;
456
+ isValid = false;
457
+ }
458
+ if(content !== '' && (ifUnicode && !unicodeCheck)) {
459
+ errorData[count][`unicode-validity${index > 1 ? index : ''}`] = true;
460
+ isValid = false;
461
+ } else if (content === '') {
462
+
463
+ errorData[count][`sms-editor${index > 1 ? index : ''}`] = true;
464
+ isValid = false;
465
+ } else {
466
+ errorData[count][`unicode-validity${index > 1 ? index : ''}`] = false;
467
+ }
468
+ }
469
+ if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
470
+ errorData['template-name'] = true;
471
+ isValid = false;
472
+ } else {
473
+ errorData['template-name'] = false;
474
+ }
475
+ }
476
+
477
+ //validation for LINE
478
+ if (this.props.schema.channel === 'LINE') {
479
+
480
+ if (this.state.formData['0']['message-editor'] !== undefined ) {
481
+ const content = this.state.formData['0']['message-editor'];
482
+
483
+ const tagValidationResponse = this.validateTags(content, tags, injectedTags);
484
+
485
+ if (tagValidationResponse.valid) {
486
+ errorData['0']['message-editor'] = false;
487
+ } else {
488
+
489
+ errorData['0']['message-editor'] = true;
490
+ isValid = false;
491
+ }
492
+ if (content.trim() === '') {
493
+
494
+ errorData['0']['message-editor'] = true;
495
+ isValid = false;
496
+ }
497
+ }
498
+
499
+ if ( (this.state.formData['0'].image !== undefined) && (this.state.formData['0'].imagePreview !== undefined)){
500
+ const imgContentLength = this.state.formData['0'].image.length;
501
+ const imgContentLengthPreview = this.state.formData['0'].imagePreview.length;
502
+ if ( (imgContentLength < 1) && (imgContentLengthPreview < 1) ) {
503
+
504
+ errorData['0'].image = true;
505
+ errorData['0'].imagePreview = true;
506
+ isValid = false;
507
+ }else{
508
+ errorData['0'].image = false;
509
+ errorData['0'].imagePreview = false;
510
+ }
511
+ }
512
+ if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
513
+ errorData['template-name'] = true;
514
+ isValid = false;
515
+ } else {
516
+ errorData['template-name'] = false;
517
+ }
518
+ }
519
+
520
+ if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'WECHAT') {
521
+
522
+ _.forEach(this.state.formData, (val, index) => {
523
+
524
+ if (index.indexOf('template') > -1 && this.state.formData[index] !== undefined) {
525
+ const content = this.state.formData[index];
526
+ if (content.trim() === '') {
527
+ errorData[index] = true;
528
+ isValid = false;
529
+ } else {
530
+ const tagValidationResponse = this.validateTags(content, tags, injectedTags);
531
+
532
+ if (tagValidationResponse.valid) {
533
+ errorData[index] = false;
534
+ } else {
535
+ errorData[index] = true;
536
+ isValid = false;
537
+ }
538
+ }
539
+ } else if (index === 'wechat-template') {
540
+ const content = this.state.formData[index];
541
+ if (content.trim() === '') {
542
+ errorData[index] = true;
543
+ isValid = false;
544
+ }
545
+ }
546
+ });
547
+
548
+ }
549
+ if(this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === "MOBILEPUSH"){
550
+ let androidValid = true, iosValid = true;
551
+ let isOnlyAndroid = false, isOnlyIos = false;
552
+
553
+ const androidData = {};
554
+ for(let data in this.state.formData[0]){
555
+ if(!!this.state.formData[0][data] && data !== "tabKey" && data !== "base"){
556
+ androidData[data] = this.state.formData[0][data];
557
+ }
558
+ }
559
+ if(_.isEmpty(androidData)){
560
+ isOnlyIos = true;
561
+ }
562
+ const iosData = {};
563
+ for(let data in this.state.formData[1]){
564
+ if(!!this.state.formData[1][data] && data !== "tabKey" && data !== "base"){
565
+ iosData[data] = this.state.formData[1][data];
566
+ }
567
+ }
568
+ if(_.isEmpty(iosData)){
569
+ isOnlyAndroid = true;
570
+ }
571
+ _.forEach(this.state.formData, (tab, index) => {
572
+ let isCurrentTabValid = true;
573
+ let skipValidation = false;
574
+ if (type.toLowerCase() === 'embedded' && ((isOnlyAndroid && parseInt(index) === 1) || (isOnlyIos && parseInt(index) === 0)) && isOnlyAndroid !== isOnlyIos) {
575
+ // skip validation of the tab which is not open in embedded mode
576
+ skipValidation = true;
577
+ }
578
+ if (!isNaN(index) && tab && !skipValidation) {
579
+ const selector = index > 0 ? `${Number(index) + 1}` : '';
580
+ let message = tab[`message-editor${selector}`];
581
+
582
+ if (errorData[parseInt(index)]) {
583
+ if (message) {
584
+ message = message.trim();
585
+
586
+ if (message === "") {
587
+ errorData[parseInt(index)][`message-editor${selector}`] = true;
588
+ isValid = false;
589
+ isCurrentTabValid = false;
590
+ } else {
591
+ errorData[parseInt(index)][`message-editor${selector}`] = false;
592
+ const tagValidationResponse = this.validateTags(message, tags, injectedTags);
593
+
594
+ if (tagValidationResponse.valid) {
595
+ errorData[parseInt(index)][`message-editor${selector}`] = false;
596
+ } else {
597
+ errorData[parseInt(index)][`message-editor${selector}`] = true;
598
+ errorData[parseInt(index)]['invalid-tags'] = tagValidationResponse.unsupportedTags;
599
+ isValid = false;
600
+ }
601
+ }
602
+
603
+ } else {
604
+ errorData[parseInt(index)][`message-editor${selector}`] = true;
605
+ isValid = false;
606
+ isCurrentTabValid = false;
607
+ }
608
+
609
+
610
+
611
+ let title = tab[`message-title${selector}`]
612
+ if(title){
613
+ title = title.trim();
614
+ if (title === "") {
615
+ errorData[parseInt(index)][`message-title${selector}`] = true;
616
+ isValid = false;
617
+ isCurrentTabValid = false;
618
+ } else {
619
+ errorData[parseInt(index)][`message-title${selector}`] = false;
620
+ const tagValidationResponse = this.validateTags(title, tags, injectedTags);
621
+
622
+ if (tagValidationResponse.valid) {
623
+ errorData[parseInt(index)][`message-title${selector}`] = false;
624
+ } else {
625
+ errorData[parseInt(index)][`message-title${selector}`] = true;
626
+ isValid = false;
627
+ }
628
+ }
629
+ } else {
630
+ errorData[parseInt(index)][`message-title${selector}`] = true;
631
+ isValid = false;
632
+ isCurrentTabValid = false;
633
+ }
634
+ // if(tab['primary-cta-link'].trim() === ""){
635
+ // errorData[parseInt(index)][`primary-cta-link`] = true;
636
+ // isValid = false;
637
+ // }else {
638
+ // errorData[parseInt(index)]['primary-cta-link'] = false;
639
+ // }
640
+ if(tab['cta-deeplink-select'] === ""){
641
+ errorData[parseInt(index)][`cta-deeplink-select`] = true;
642
+ isValid = false;
643
+ isCurrentTabValid = false;
644
+ }else {
645
+ errorData[parseInt(index)]['cta-deeplink-select'] = false;
646
+ }
647
+ if(tab['cta-deeplink2-select'] === ""){
648
+ errorData[parseInt(index)][`cta-deeplink2-select`] = true;
649
+ isValid = false;
650
+ isCurrentTabValid = false;
651
+ }else {
652
+ errorData[parseInt(index)]['cta-deeplink2-select'] = false;
653
+ }
654
+ // }
655
+ if(!this.isValidExternalLink({obj: tab, key: 'cta-deeplink-text'})){
656
+ errorData[parseInt(index)][`cta-deeplink-text`] = true;
657
+ isValid = false;
658
+ isCurrentTabValid = false;
659
+ }else {
660
+ errorData[parseInt(index)]['cta-deeplink-text'] = false;
661
+ }
662
+
663
+ if(!this.isValidExternalLink({obj: tab, key: 'cta-deeplink2-text'})){
664
+ errorData[parseInt(index)][`cta-deeplink2-text`] = true;
665
+ isValid = false;
666
+ isCurrentTabValid = false;
667
+ }else {
668
+ errorData[parseInt(index)]['cta-deeplink2-text'] = false;
669
+ }
670
+
671
+
672
+ if(tab['secondary-cta-0-link'] === ""){
673
+ errorData[parseInt(index)][`secondary-cta-0-link`] = true;
674
+ isValid = false;
675
+ isCurrentTabValid = false;
676
+ }else {
677
+ errorData[parseInt(index)]['secondary-cta-0-link'] = false;
678
+ }
679
+ if(tab['secondary-cta-0-label'] === ""){
680
+ errorData[parseInt(index)][`secondary-cta-0-label`] = true;
681
+ isValid = false;
682
+ isCurrentTabValid = false;
683
+ }else {
684
+ errorData[parseInt(index)]['secondary-cta-0-label'] = false;
685
+ }
686
+
687
+
688
+ if(!this.isValidExternalLink({obj: tab, key: 'cta-deeplink-secondary-cta-0-text'})){
689
+ errorData[parseInt(index)][`cta-deeplink-secondary-cta-0-text`] = true;
690
+ isValid = false;
691
+ isCurrentTabValid = false;
692
+ }else {
693
+ errorData[parseInt(index)]['cta-deeplink-secondary-cta-0-text'] = false;
694
+ }
695
+ if(tab['cta-deeplink-secondary-cta-0-select'] === ""){
696
+ errorData[parseInt(index)][`cta-deeplink-secondary-cta-0-select`] = true;
697
+ isValid = false;
698
+ isCurrentTabValid = false;
699
+ }else {
700
+ errorData[parseInt(index)]['cta-deeplink-secondary-cta-0-select'] = false;
701
+ }
702
+ if(tab['secondary-cta-1-label'] === ""){
703
+ errorData[parseInt(index)][`secondary-cta-1-label`] = true;
704
+ isValid = false;
705
+ isCurrentTabValid = false;
706
+ }else {
707
+ errorData[parseInt(index)]['secondary-cta-1-label'] = false;
708
+ }
709
+
710
+ if(!this.isValidExternalLink({obj: tab, key: 'cta-deeplink-secondary-cta-1-text'})){
711
+ errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-text`] = true;
712
+ isValid = false;
713
+ isCurrentTabValid = false;
714
+ }else {
715
+ errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-text'] = false;
716
+ }
717
+ if(tab['cta-deeplink-secondary-cta-1-select'] === ""){
718
+ errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-select`] = true;
719
+ isValid = false;
720
+ isCurrentTabValid = false;
721
+ }else {
722
+ errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-select'] = false;
723
+ }
724
+
725
+ if(!this.isValidExternalLink({obj: tab, key: 'cta-deeplink-secondary-cta-1-text2'})){
726
+ errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-text2`] = true;
727
+ isValid = false;
728
+ isCurrentTabValid = false;
729
+ }else {
730
+ errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-text2'] = false;
731
+ }
732
+ if(tab['cta-deeplink-secondary-cta-1-select2'] === ""){
733
+ errorData[parseInt(index)][`cta-deeplink-secondary-cta-1-select2`] = true;
734
+ isValid = false;
735
+ isCurrentTabValid = false;
736
+ }else {
737
+ errorData[parseInt(index)]['cta-deeplink-secondary-cta-1-select2'] = false;
738
+ }
739
+
740
+ if(typeof tab['image'] !== 'undefined' && tab['image'] === ""){
741
+ errorData[parseInt(index)]['image'] = true;
742
+ isValid = false;
743
+ isCurrentTabValid = false;
744
+ }else{
745
+ errorData[parseInt(index)]['image'] = false;
746
+ }
747
+ _.forEach(Object.keys(tab), (key) => {
748
+ if (key.indexOf('custom-value') > -1) {
749
+ if (tab[key] === "") {
750
+ errorData[parseInt(index)][key] = true;
751
+ isValid = false;
752
+ isCurrentTabValid = false;
753
+ }else {
754
+ errorData[parseInt(index)][key] = false;
755
+ }
756
+ }
757
+ });
758
+ }
759
+ }
760
+ if(index == 0){
761
+ androidValid = isCurrentTabValid;
762
+ } else if(index == 1){
763
+ iosValid = isCurrentTabValid;
764
+ }
765
+ });
766
+ if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
767
+ errorData['template-name'] = true;
768
+ isValid = false;
769
+ androidValid = false;
770
+ iosValid = false
771
+ } else {
772
+ errorData['template-name'] = false;
773
+ }
774
+ if(isSave && (androidValid || iosValid)){
775
+ const modal = this.state.modal;
776
+ const androidData = {};
777
+
778
+ for(let data in this.state.formData[0]){
779
+ if(!!this.state.formData[0][data] && data !== "tabKey" && data !== "base"){
780
+ androidData[data] = this.state.formData[0][data];
781
+ }
782
+ }
783
+ if(_.isEmpty(androidData) && this.state.currentTab === 2){
784
+ this.setState({androidValid, iosValid}, () => {
785
+ this.props.setModalContent('ios');
786
+ });
787
+ // modal.body = "Android template is not configured. Save without Android template";
788
+ // modal.id = "ios";
789
+ // modal.type = 'confirm';
790
+ return;
791
+ }
792
+ const iosData = {};
793
+ for(let data in this.state.formData[1]){
794
+ if(!!this.state.formData[1][data] && data !== "tabKey"){
795
+ iosData[data] = this.state.formData[1][data];
796
+ }
797
+ }
798
+ if(_.isEmpty(iosData) && this.state.currentTab === 1){
799
+ this.setState({androidValid, iosValid}, () => {
800
+ this.props.setModalContent('android');
801
+ });
802
+ // modal.body = "IOS template is not configured, Save without IOS template";
803
+ // modal.id = 'android';
804
+ // modal.type = 'confirm';
805
+ // this.setState({modal, showModal: true, androidValid, iosValid});
806
+ return;
807
+ }
808
+ }
809
+ if (!androidValid || !iosValid) {
810
+ this.setState({androidValid, iosValid});
811
+ }
812
+ if (isOnlyAndroid && androidValid) {
813
+ isValid = isValid && true;
814
+ } else if (isOnlyIos && iosValid) {
815
+ isValid = isValid && true;
816
+ } else if (!isOnlyIos && !isOnlyAndroid && androidValid && iosValid) {
817
+ isValid = isValid && true;
818
+ }
819
+ }
820
+
821
+ // Form Data Validation for Email Channel
822
+ if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === "EMAIL") {
823
+ // Validating Email By iterating all elements of FormBuilder
824
+ _.forEach(this.state.formData, (data, index) => {
825
+
826
+ if (!this.state.formData["template-subject"] && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline' || currentModule.toLowerCase() === 'library')) {
827
+ errorData["template-subject"] = true;
828
+ isValid = false;
829
+ }
830
+ // Check if template subject present in form data from Loyalty, DVS, Timeline
831
+ if (index === 'template-subject' && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline' || currentModule.toLowerCase() === 'library')) {
832
+ if (data && data.trim() === '') {
833
+ errorData[index] = true;
834
+ isValid = false;
835
+ } else {
836
+ errorData[index] = false;
837
+ }
838
+ }
839
+
840
+ // Check if Template name present in full mode
841
+ if(type !== 'embedded' && index === 'template-name' && data === '') {
842
+ errorData[index] = true;
843
+ isValid = false;
844
+ } else if(type !== 'embedded' && index === 'template-name' && data !== '') {
845
+ errorData[index] = false;
846
+ }
847
+
848
+ // Check formData if selected version present or not
849
+ if(index === 'template-version' && data === '') {
850
+ errorData[index] = true;
851
+ isValid = false;
852
+ } else if(index === 'template-version' && data !== '') {
853
+ errorData[index] = false;
854
+ }
855
+
856
+ // Check error for the versions
857
+ if (!isNaN(index) || index === 'base') {
858
+ if (errorData[index] === undefined) {
859
+ errorData[index] = {};
860
+ }
861
+ let errorString = "";
862
+ for (var i = 0; i < data.selectedLanguages.length; i+= 1) {
863
+ const currentLang = data.selectedLanguages[i];
864
+ const content = data[currentLang]['template-content'];
865
+ const tagValidationResponse = this.validateTags(content, tags, injectedTags);
866
+ if (errorData[index][currentLang] === undefined) {
867
+ errorData[index][currentLang] = {};
868
+ }
869
+
870
+ if (tagValidationResponse.valid) {
871
+ errorData[index][currentLang]['template-content'] = false;
872
+ } else {
873
+ errorData[index][currentLang]['template-content'] = true;
874
+ isValid = false;
875
+ if (showMessages && !isNaN(index)) {
876
+ if (tagValidationResponse.missingTags.length > 0 || tagValidationResponse.unsupportedTags.length > 0) {
877
+ errorString += `Content is not valid for language: ${currentLang}\n`;
878
+ }
879
+ if (tagValidationResponse.missingTags.length > 0) {
880
+ errorString += `Missing tags are: ${tagValidationResponse.missingTags.toString()}\n`;
881
+ }
882
+ if (tagValidationResponse.unsupportedTags.length > 0) {
883
+ errorString += `Unsupported tags are: ${tagValidationResponse.unsupportedTags.toString()}\n`;
884
+ }
885
+ }
886
+ }
887
+ }
888
+ if (errorString !== "") {
889
+ this.openNotificationWithIcon('error', errorString, "email-validation-error");
890
+ }
891
+ _.forEach(errorData[index], (versionData, key) => {
892
+ if (data.selectedLanguages.indexOf(key) === -1) {
893
+ delete errorData[index][key];
894
+ }
895
+ });
896
+ }
897
+ });
898
+ // for (let count = 0; count < this.state.tabCount; count += 1) {
899
+ // const index = count + 1;
900
+ // // const content = this.state.formData[count][`template-content${index > 1 ? index : ''}`];
901
+ // // const tagValidationResponse = this.validateTags(content, tags, injectedTags);
902
+ // //
903
+ // // if (tagValidationResponse.valid) {
904
+ // // errorData[count][`template-content${index > 1 ? index : ''}`] = false;
905
+ // // } else {
906
+ // // errorData[count][`template-content${index > 1 ? index : ''}`] = true;
907
+ // // isValid = false;
908
+ // // }
909
+ // }
910
+ // if (type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline')) {
911
+ // if (this.state.formData['template-subject'] && this.state.formData['template-subject'].trim() === '') {
912
+ // errorData['template-subject'] = true;
913
+ // isValid = false;
914
+ // }
915
+ // }
916
+ // if(type !== 'embedded' && (!this.state.formData['template-name'] || this.state.formData['template-name'] === '')) {
917
+ // errorData['template-name'] = true;
918
+ // isValid = false;
919
+ // } else {
920
+ // errorData['template-name'] = false;
921
+ // }
922
+ }
923
+ this.setState({isFormValid : isValid, errorData});
924
+
925
+ this.props.onFormValidityChange(isValid, errorData);
926
+ return isValid;
927
+ }
928
+
929
+ indexOfEnd(targetString, string) {
930
+ var io = targetString.indexOf(string);
931
+ return io == -1 ? -1 : io + string.length;
932
+ }
933
+ continueSaveForm = (id) => {
934
+
935
+ };
936
+ saveForm(saveForm) {
937
+
938
+ if (this.props.isNewVersionFlow && !saveForm) {
939
+ this.props.getValidationData();
940
+ return;
941
+ }
942
+ if (this.state.isFormValid) {
943
+ this.props.onSubmit(this.state.formData);
944
+ } else {
945
+ this.setState({checkValidation: true});
946
+ this.validateForm(null, null, true);
947
+ }
948
+ }
949
+
950
+ transformInjectedTags(tags) {
951
+ _.forEach(tags, (tag) => {
952
+ const temp = tag;
953
+ let subKey = '';
954
+ Object.keys(tag).map( (k) => {
955
+ if (k.indexOf("subtags") !== -1) {
956
+ subKey = k;
957
+ }
958
+ return true;
959
+ });
960
+ if (subKey !== '') {
961
+ temp['tag-header'] = true;
962
+ if (subKey !== 'subtags') {
963
+ temp.subtags = _.cloneDeep(temp[subKey]);
964
+ delete temp[subKey];
965
+ }
966
+ temp.subtags = this.transformInjectedTags(temp.subtags);
967
+ }
968
+ });
969
+ return tags;
970
+ }
971
+
972
+ checkIfSupportedTag(checkingTag, injectedTags) {
973
+ let result = false;
974
+ _.forEach(injectedTags, (tag, key) => {
975
+ if (tag.subtags) {
976
+ if (this.checkIfSupportedTag(checkingTag, tag.subtags)) {
977
+ result = true;
978
+ }
979
+ } else if (checkingTag === key) {
980
+ result = true;
981
+ }
982
+ });
983
+
984
+ return result;
985
+ }
986
+
987
+ skipTags(tag) {
988
+ const regexGroups = ["dynamic_expiry_date_after_\\d+_days.FORMAT_\\d", "unsubscribe\\(#[a-zA-Z\\d]{6}\\)","Link_to_[a-zA-z]","SURVEY.*.TOKEN"];
989
+
990
+ //const regexGroups = [];
991
+ let skipped = false;
992
+ _.forEach(regexGroups, (group) => {
993
+ //const groupRegex = /dynamic_expiry_date_after_\(\d+\)_days.FORMAT_\d/g;
994
+ const groupRegex = new RegExp(group, "g");
995
+ let match = groupRegex.exec(tag);
996
+ if (match !== null ) {
997
+ skipped = true;
998
+ return true;
999
+ }
1000
+ return true;
1001
+ });
1002
+ return skipped;
1003
+ }
1004
+
1005
+ validateTags(content, tagsParam, injectedTagsParams) {
1006
+ const type = (this.props.location && this.props.location.query.type) ? this.props.location.query.type : 'full';
1007
+ let currentModule = this.props.location.query.module ? this.props.location.query.module : 'default';
1008
+ if (this.props.tagModule) {
1009
+ currentModule = this.props.tagModule;
1010
+ }
1011
+ const tags = tagsParam ? tagsParam : this.props.tags;
1012
+ const injectedTags = this.transformInjectedTags(injectedTagsParams ? injectedTagsParams : this.props.injectedTags);
1013
+ const excludedTags = ['user_id_b64', 'outbox_id_b64'];
1014
+
1015
+
1016
+ const response = {};
1017
+ response.valid = true;
1018
+ response.missingTags = [];
1019
+ response.unsupportedTags = [];
1020
+ _.forEach(tags, (tag) => {
1021
+ _.forEach(tag.definition.supportedModules, (module) => {
1022
+ if (module.mandatory && (currentModule === module.context)) {
1023
+ if (content.indexOf(`{{${tag.definition.value}}}`) === -1) {
1024
+ response.valid = false;
1025
+ response.missingTags.push(tag.definition.value);
1026
+ }
1027
+ }
1028
+ });
1029
+ });
1030
+ const regex = /{{[(A-Z\w\(\)@!#$%^&*~.,/\\]+}}/g;
1031
+ let match = regex.exec(content);
1032
+ while (match !== null) {
1033
+ const tagValue = match[0].substring(this.indexOfEnd(match[0], '{{'), match[0].indexOf('}}'));
1034
+ match = regex.exec(content);
1035
+ let ifSupported = false;
1036
+ _.forEach(tags, (tag) => {
1037
+ if (tag.definition.value === tagValue) {
1038
+ ifSupported = true;
1039
+ }
1040
+ });
1041
+ const ifSkipped = this.skipTags(tagValue);
1042
+ if (ifSkipped) {
1043
+ ifSupported = true;
1044
+ let isUnsubscribeSkipped = tagValue.indexOf("unsubscribe") != -1 ;
1045
+ if (isUnsubscribeSkipped) {
1046
+ const missingTagIndex = response.missingTags.indexOf("unsubscribe");
1047
+ if(missingTagIndex != -1) { //skip regex tags for mandatory tags also
1048
+ response.missingTags.splice(missingTagIndex, 1);
1049
+ }
1050
+ }
1051
+ }
1052
+ ifSupported = ifSupported || this.checkIfSupportedTag(tagValue, injectedTags);
1053
+ if (!ifSupported) {
1054
+ response.unsupportedTags.push(tagValue);
1055
+ response.valid = false;
1056
+ }
1057
+ if (response.unsupportedTags.length == 0 && response.missingTags.length == 0 ) {
1058
+ response.valid = true;
1059
+ }
1060
+ }
1061
+ return response;
1062
+ }
1063
+ /* eslint-enable */
1064
+ initializeParentSection(section, formDataObj, isContainer, index, ifError) {
1065
+ let formData = formDataObj;
1066
+ _.forEach(section.childSections, (childSection) => {
1067
+ if (childSection.type === 'col-label') {
1068
+ formData = this.initializeColLabelSection(childSection, formData, isContainer, index, ifError);
1069
+ } else if (childSection.type === 'multicols') {
1070
+ formData = this.initializeMultiColSection(childSection, formData, isContainer, index, ifError);
1071
+ } else {
1072
+ formData = this.initializeParentSection(childSection, formData, isContainer, index, ifError);
1073
+ }
1074
+ });
1075
+ return formData;
1076
+ }
1077
+
1078
+ initializeEditErrorData(formData, tabCount) {
1079
+ const errorData = {};
1080
+ for (let idx = 0; idx < tabCount; idx += 1 ) {
1081
+ _.forEach(formData[0], (val, key) => {
1082
+ if (!errorData[idx]) {
1083
+ errorData[idx] = {};
1084
+ }
1085
+ if (key === 'tabKey' || key === 'base' || key === 'selectedLanguages') {
1086
+ return true;
1087
+ }
1088
+ if (this.props.isNewVersionFlow && formData[0].selectedLanguages.indexOf(key) > -1) {
1089
+ _.forEach(formData[0].selectedLanguages, (lang) => {
1090
+ if (errorData[idx] === undefined) {
1091
+ errorData[idx] = {};
1092
+ }
1093
+ if (errorData[idx][lang] === undefined) {
1094
+ errorData[idx][lang] = {};
1095
+ }
1096
+ errorData[idx][lang]['template-content'] = false;
1097
+ });
1098
+ } else {
1099
+ errorData[idx][key] = false;
1100
+ }
1101
+ return true;
1102
+ });
1103
+ }
1104
+ this.setState({errorData});
1105
+ }
1106
+
1107
+ initializeMultiColSection(section, formDataObj, isContainer, index, ifError) {
1108
+ const formData = _.cloneDeep(formDataObj);
1109
+ const newFormData = {};
1110
+ newFormData[index] = {};
1111
+ _.forEach(section.inputFields, (inputField) => {
1112
+ _.forEach(inputField.cols, (col) => {
1113
+ if (isContainer && !formData[index]) {
1114
+ formData[index] = {};
1115
+ }
1116
+ if (isContainer && this.props.isNewVersionFlow) {
1117
+ // if (formData[index] && formData[index].selectedLanguages && formData[index].selectedLanguages.length > 0) {
1118
+ // for (let i = 0; i < formData[index].selectedLanguages.length; i += 1 ) {
1119
+ // formData[index][formData[index].selectedLanguages[i]] = {};
1120
+ // }
1121
+ // } else {
1122
+ // formData[index][`${this.props.baseLanguage ? this.props.baseLanguage : 'en'}`] = {};
1123
+ // }
1124
+ _.forEach(this.props.supportedLanguages, (language) => {
1125
+ if (!formData[index][language.iso_code] && this.props.baseLanguage === language.iso_code) {
1126
+ formData[index][language.iso_code] = {};
1127
+ }
1128
+ });
1129
+ }
1130
+ // if (!ifError && (col.id.indexOf('template-label-') === -1 && col.id.indexOf('tagList-') === -1)) {
1131
+ // this.formElements.push(col.id);
1132
+ // }
1133
+ if (!col.onlyDisplay && !ifError) {
1134
+ if (col.id.indexOf('tagList-') === -1) {
1135
+ this.formElements.push(col.id);
1136
+ }
1137
+
1138
+ if (!this.props.isNewVersionFlow) {
1139
+ if (isContainer && formData[index][col.id] === undefined) {
1140
+ if (ifError) {
1141
+ formData[index][col.id] = false;
1142
+ } else if (isContainer && formData[index][col.id] === undefined && col.value) {
1143
+ formData[index][col.id] = col.value;
1144
+ } else {
1145
+ formData[index][col.id] = '';
1146
+ }
1147
+ } else if (!isContainer && ifError && formData[col.id] === undefined) {
1148
+ formData[col.id] = false;
1149
+ } else if (!isContainer && !ifError && formData[col.id] === undefined) {
1150
+ formData[col.id] = '';
1151
+ }
1152
+ } else if (!(col.id.indexOf('template-content') > -1 && col.id !== 'template-content')) {
1153
+ if (isContainer && formData[index] && formData[index][this.props.baseLanguage] && formData[index][this.props.baseLanguage][col.id] === undefined) {
1154
+ if (ifError) {
1155
+ formData[index][this.props.baseLanguage][col.id] = false;
1156
+ } else if (isContainer && formData[index][this.props.baseLanguage][col.id] === undefined && col.value) {
1157
+ formData[index][this.props.baseLanguage][col.id] = col.value;
1158
+ } else {
1159
+ formData[index][this.props.baseLanguage][col.id] = '';
1160
+ }
1161
+ } else if (!isContainer && ifError && formData[col.id] === undefined) {
1162
+ formData[col.id] = false;
1163
+ } else if (!isContainer && !ifError && formData[col.id] === undefined) {
1164
+ formData[col.id] = '';
1165
+ }
1166
+ }
1167
+ }
1168
+ if (col.type === 'checkbox') {
1169
+ if (isContainer && !formData[index][col.id]) {
1170
+ formData[index][col.id] = false;
1171
+ } else if (!isContainer && formData[col.id] === undefined) {
1172
+ formData[col.id] = false;
1173
+ }
1174
+ }
1175
+ });
1176
+ });
1177
+ return formData;
1178
+ }
1179
+
1180
+ initializeColLabelSection(section, formDataObj, isContainer, index, ifError) {
1181
+ const formData = formDataObj;
1182
+ _.forEach(section.inputFields, (inputField) => {
1183
+ if (isContainer && !formData[index]) {
1184
+ formData[index] = {};
1185
+ }
1186
+ if (!ifError && (inputField.id.indexOf('template-label-') === -1 && inputField.id.indexOf('tagList-') === -1)) {
1187
+ this.formElements.push(inputField.id);
1188
+ }
1189
+ if (!inputField.onlyDisplay) {
1190
+ if (isContainer && !this.props.isNewVersionFlow && formData[index][inputField.id] === undefined) {
1191
+ if (ifError) {
1192
+ formData[index][inputField.id] = false;
1193
+ } else {
1194
+ formData[index][inputField.id] = '';
1195
+ }
1196
+ } else if (isContainer && this.props.isNewVersionFlow && formData[index][this.props.baseLanguage][inputField.id] === undefined) {
1197
+ if (ifError) {
1198
+ formData[index][this.props.baseLanguage][inputField.id] = false;
1199
+ } else {
1200
+ formData[index][this.props.baseLanguage][inputField.id] = '';
1201
+ }
1202
+ } else if (!isContainer && ifError && this.state.formData[inputField.id] === undefined) {
1203
+ formData[inputField.id] = false;
1204
+ } else if (!isContainer && !ifError && this.state.formData[inputField.id] === undefined) {
1205
+ formData[inputField.id] = '';
1206
+ }
1207
+ }
1208
+ if (inputField.type === 'checkbox') {
1209
+ if (isContainer) {
1210
+ formData[index][inputField.id] = false;
1211
+ } else {
1212
+ formData[inputField.id] = false;
1213
+ }
1214
+ }
1215
+ });
1216
+ return formData;
1217
+ }
1218
+
1219
+ initializeStandAloneSections(schema, formDataObj, ifError) {
1220
+ let formData = _.cloneDeep(formDataObj);
1221
+ if (schema.standalone) {
1222
+ _.forEach(schema.standalone.sections, (section) => {
1223
+ if (section) {
1224
+ if (section.type === 'multicols') {
1225
+ formData = this.initializeMultiColSection(section, formData, false, -1, ifError);
1226
+ } else if (section.type === 'col-label') {
1227
+ formData = this.initializeColLabelSection(section, formData, false, -1, ifError);
1228
+ } else if (section.type === 'parent') {
1229
+ formData = this.initializeParentSection(section, formData, false, -1, ifError);
1230
+ }
1231
+ }
1232
+ });
1233
+ }
1234
+ return formData;
1235
+ }
1236
+
1237
+ initializeContainers(schema, formDataObj, ifError) {
1238
+ let formData = _.cloneDeep(formDataObj);
1239
+ if (this.props.isNewVersionFlow) {
1240
+ _.forEach(schema.containers, (val, index) => {
1241
+ if (val.type === 'tabs') {
1242
+ this.setState({usingTabContainer: true});
1243
+ _.forEach(val.panes, (pane, paneIndex) => {
1244
+ _.forEach(pane.sections, (section) => {
1245
+ if (section.type === 'multicols') {
1246
+ formData = this.initializeMultiColSection(section, formData, true, index, ifError, paneIndex);
1247
+ } else if (section.type === 'col-label') {
1248
+ formData = this.initializeColLabelSection(section, formData, true, index, ifError);
1249
+ } else if (section.type === 'parent') {
1250
+ formData = this.initializeParentSection(section, formData, true, index, ifError);
1251
+ }
1252
+ });
1253
+ });
1254
+ if (ifError) {
1255
+ formData[val.id] = false;
1256
+ }
1257
+ formData[val.id] = '';
1258
+ }
1259
+ if (val.type === 'checkbox') {
1260
+ formData[val.id] = false;
1261
+ }
1262
+ });
1263
+ } else {
1264
+ _.forEach(schema.containers, (val) => {
1265
+ if (val.type === 'tabs') {
1266
+ this.setState({usingTabContainer: true});
1267
+ _.forEach(val.panes, (pane, index) => {
1268
+ _.forEach(pane.sections, (section) => {
1269
+ if (section.type === 'multicols') {
1270
+ formData = this.initializeMultiColSection(section, formData, true, index, ifError);
1271
+ } else if (section.type === 'col-label') {
1272
+ formData = this.initializeColLabelSection(section, formData, true, index, ifError);
1273
+ } else if (section.type === 'parent') {
1274
+ formData = this.initializeParentSection(section, formData, true, index, ifError);
1275
+ }
1276
+ });
1277
+ });
1278
+ if (ifError) {
1279
+ formData[val.id] = false;
1280
+ }
1281
+ formData[val.id] = '';
1282
+ }
1283
+ if (val.type === 'checkbox') {
1284
+ formData[val.id] = false;
1285
+ }
1286
+ });
1287
+ }
1288
+ return formData;
1289
+ }
1290
+
1291
+ initialiseForm(schema, makeFormEmpty, resetTabKeys) {
1292
+ let formData = makeFormEmpty ? {} : _.cloneDeep(this.state.formData);
1293
+ let errorData = {};
1294
+ this.formElements = [];
1295
+ if (_.isEmpty(schema)) {
1296
+ return;
1297
+ }
1298
+ errorData = this.initializeStandAloneSections(schema, errorData, true);
1299
+ formData = this.initializeStandAloneSections(schema, formData);
1300
+ formData = this.initializeContainers(schema, formData);
1301
+ errorData = this.initializeContainers(schema, errorData, true);
1302
+
1303
+
1304
+ if (!this.props.isEdit) {
1305
+ if (!formData[0]) {
1306
+ formData[0] = {};
1307
+ }
1308
+ if (!errorData[0]) {
1309
+ errorData[0] = {};
1310
+ }
1311
+ formData[0].base = true;
1312
+ formData[0].tabKey = formData[0].tabKey ? formData[0].tabKey : _.uniqueId();
1313
+ errorData.base = errorData[0];
1314
+ formData.base = formData[0];
1315
+ if (this.state.currentTab === 1) {
1316
+ this.setState({tabKey: formData.base.tabKey});
1317
+ }
1318
+ }
1319
+ const tempFormData = _.cloneDeep(formData);
1320
+ if (!this.props.isNewVersionFlow) {
1321
+ _.forEach(formData, (element, key) => {
1322
+ if (typeof element !== 'object' && this.formElements.indexOf(key) === -1) {
1323
+ delete tempFormData[key];
1324
+ } else if (typeof element === "object") {
1325
+ _.forEach(element, (innerElement, innerKey) => {
1326
+ if (innerKey !== "tabKey" && innerKey !== "base" && innerKey !== 'name' && innerKey !== 'imagePreview' && this.formElements.indexOf(innerKey) === -1) {
1327
+ delete tempFormData[key][innerKey];
1328
+ }
1329
+ });
1330
+ }
1331
+ });
1332
+ }
1333
+ formData = _.cloneDeep(tempFormData);
1334
+ this.setState({formData, errorData}, () => {
1335
+ this.validateForm();
1336
+ if (this.props.isSchemaChanged || resetTabKeys) {
1337
+ this.resetTabKeys(formData, this.props.tabCount, true);
1338
+ }
1339
+ });
1340
+ }
1341
+
1342
+ cloneVersionData(ifError) {
1343
+ if (this.state.tabCount === 0) {
1344
+ this.initialiseForm(this.props.schema, true);
1345
+ return;
1346
+ }
1347
+ let formData = {};
1348
+ if (ifError) {
1349
+ formData = Object.assign({}, this.state.errorData);
1350
+ } else {
1351
+ formData = Object.assign({}, this.state.formData);
1352
+ }
1353
+ let newTabIndex = 0;
1354
+ if (ifError) {
1355
+ newTabIndex = this.state.tabCount - 1;
1356
+ } else {
1357
+ newTabIndex = this.state.tabCount;
1358
+ }
1359
+ formData[newTabIndex] = {};
1360
+
1361
+ const newTabCount = newTabIndex + 1;
1362
+ _.forEach(formData[0], (val, key) => {
1363
+ if (key === 'base') {
1364
+ return true;
1365
+ }
1366
+ if (key === 'tabKey') {
1367
+ return true;
1368
+ }
1369
+ if (typeof val === 'string') {
1370
+ if (ifError) {
1371
+ formData[newTabIndex][`${key}${newTabCount}`] = false;
1372
+ } else if (this.props.isNewVersionFlow) {
1373
+ if (key.indexOf('activeTab') > -1) {
1374
+ formData[newTabIndex][`${key}`] = this.props.baseLanguage;
1375
+ } else {
1376
+ formData[newTabIndex][`${key}${newTabCount}`] = '';
1377
+ }
1378
+ } else {
1379
+ formData[newTabIndex][`${key}${newTabCount}`] = '';
1380
+ }
1381
+ } else if (typeof val === 'boolean') {
1382
+ formData[newTabIndex][`${key}${newTabCount}`] = false;
1383
+ } else if (typeof val === 'object') {
1384
+ if (this.props.isNewVersionFlow) {
1385
+ if (key.indexOf('selectedLanguages') > -1) {
1386
+ formData[newTabIndex][key] = [this.props.baseLanguage];
1387
+ } else if (key === this.props.baseLanguage) {
1388
+ formData[newTabIndex][key] = {};
1389
+ _.forEach(val, (subVal, index) => {
1390
+ // if (subVal === 'is_drag_drop' || subVal === 'lang_id' || subVal === 'iso_code' === 'language') {
1391
+ //
1392
+ // formData[newTabIndex][key][index] = formData[0][this.props.baseLanguage][subVal];
1393
+ // } else {
1394
+ if (index === 'tabKey') {
1395
+ formData[newTabIndex][key][index] = _.uniqueId();
1396
+ } else if (index === 'template-content') {
1397
+ formData[newTabIndex][key][index] = "";
1398
+ } else {
1399
+ formData[newTabIndex][key][index] = _.cloneDeep(formData[0][key][index]);
1400
+ }
1401
+ // }
1402
+ });
1403
+ }
1404
+ } else {
1405
+ formData[newTabIndex][key] = {};
1406
+ _.forEach(val, (subVal, index) => {
1407
+ formData[newTabIndex][key][index] = '';
1408
+ });
1409
+ }
1410
+ }
1411
+ return true;
1412
+ });
1413
+ let id = (this.props.isNewVersionFlow && formData[newTabIndex][this.props.baseLanguage].tabKey) ? formData[newTabIndex][this.props.baseLanguage].tabKey : _.uniqueId();
1414
+
1415
+ if (!ifError) {
1416
+ let validId = false;
1417
+ while (!validId) {
1418
+ validId = true;
1419
+ for (let idx = 0; idx < this.state.tabCount; idx += 1) {
1420
+ if (id === formData[idx].tabKey) {
1421
+ validId = false;
1422
+ }
1423
+ }
1424
+ if (validId) {
1425
+ break;
1426
+ }
1427
+ id = _.uniqueId();
1428
+ }
1429
+ formData[newTabIndex].tabKey = id;
1430
+ }
1431
+ // if (!this.props.isEdit) {
1432
+ if (ifError) {
1433
+ this.setState({errorData: formData});
1434
+ } else {
1435
+ this.props.onChange(formData, newTabCount, newTabIndex + 1);
1436
+
1437
+ this.setState({tabCount: newTabCount, formData, currentTab: newTabIndex + 1, tabKey: id}, () => {
1438
+ this.cloneVersionData(true);
1439
+ });
1440
+ }
1441
+ }
1442
+
1443
+ changeVersionName(data) {
1444
+ const formData = _.cloneDeep(this.state.formData);
1445
+ if (formData[this.state.currentTab - 1]) {
1446
+ formData[this.state.currentTab - 1].name = data;
1447
+ this.setState({formData});
1448
+ }
1449
+ }
1450
+
1451
+ markFinalTabVersion() {
1452
+ const formData = _.cloneDeep(this.state.formData);
1453
+ if (this.state.usingTabContainer) {
1454
+ for (let count = 0; count < this.state.tabCount; count += 1) {
1455
+ if (parseInt(this.state.currentTab - 1, 10) !== count) {
1456
+ formData[count].base = false;
1457
+ } else {
1458
+ formData[count].base = true;
1459
+ formData.base = formData[count];
1460
+ }
1461
+ }
1462
+ this.setState({formData});
1463
+
1464
+ this.props.onChange(formData, this.state.tabCount);
1465
+ }
1466
+ }
1467
+
1468
+ resetState(isEdit, usingTabContainer) {
1469
+ this.setState({
1470
+ formData: {},
1471
+ currentTab: 1,
1472
+ usingTabContainer: usingTabContainer || false,
1473
+ tabCount: 1,
1474
+ errorData: {},
1475
+ tabKey: '',
1476
+ }, () => {
1477
+ if (!isEdit) {
1478
+ this.initialiseForm(this.props.schema, true);
1479
+ }
1480
+ });
1481
+ }
1482
+
1483
+ duplicateVersion(ifError, currentTab) {
1484
+ let formData = {};
1485
+ let tabCount = 0;
1486
+ if (ifError) {
1487
+ formData = _.cloneDeep(this.state.errorData);
1488
+ tabCount = this.state.tabCount - 1;
1489
+ } else {
1490
+ formData = _.cloneDeep(this.state.formData);
1491
+ tabCount = this.state.tabCount;
1492
+ }
1493
+ const newTabCount = tabCount + 1;
1494
+ _.forEach(formData[0], (val, key) => {
1495
+ if (!formData[tabCount]) {
1496
+ formData[tabCount] = {};
1497
+ }
1498
+ if (key === 'base') {
1499
+ formData[tabCount].base = false;
1500
+ return true;
1501
+ }
1502
+ if (key === 'tabKey') {
1503
+ let validId = false;
1504
+ let id = _.uniqueId();
1505
+ while (!validId) {
1506
+ validId = true;
1507
+ for (let idx = 0; idx < this.state.tabCount; idx += 1) {
1508
+ if (id === formData[idx].tabKey) {
1509
+ validId = false;
1510
+ }
1511
+ }
1512
+ if (validId) {
1513
+ break;
1514
+ }
1515
+ id = _.uniqueId();
1516
+ }
1517
+ formData[tabCount].tabKey = id;
1518
+ return true;
1519
+ }
1520
+ const tempTab = ifError ? currentTab : this.state.currentTab;
1521
+ if (typeof val === 'string') {
1522
+ if (this.props.isNewVersionFlow) {
1523
+ formData[tabCount][`${key}`] = formData[tempTab - 1][`${key}`];
1524
+ } else {
1525
+ formData[tabCount][`${key}${newTabCount}`] = formData[tempTab - 1][`${key}${parseInt(tempTab, 10) === 1 ? '' : tempTab}`];
1526
+ }
1527
+ } else if (typeof val === 'boolean') {
1528
+ if (this.props.isNewVersionFlow) {
1529
+ formData[tabCount][`${key}`] = formData[tempTab - 1][`${key}`];
1530
+ } else {
1531
+ formData[tabCount][`${key}${newTabCount}`] = formData[tempTab - 1][`${key}${parseInt(tempTab, 10) === 1 ? '' : tempTab}`];
1532
+ }
1533
+ }
1534
+ return true;
1535
+ });
1536
+ if (ifError) {
1537
+ this.setState({errorData: formData});
1538
+ } else {
1539
+ const tempTab = ifError ? currentTab : this.state.currentTab;
1540
+ const version = `Version ${this.state.currentTab}`;
1541
+ formData[tabCount].name = `Copy of ${formData[tempTab - 1].name ? formData[tempTab - 1].name : version}`;
1542
+ formData[tabCount].base = false;
1543
+ const initialTab = this.state.currentTab;
1544
+ this.setState({formData, tabCount: tabCount + 1, currentTab: tabCount + 1, tabKey: formData[tabCount].tabKey}, () => {
1545
+ this.duplicateVersion(true, initialTab);
1546
+ });
1547
+
1548
+ this.props.onChange(formData, tabCount + 1, tabCount + 1);
1549
+ }
1550
+ }
1551
+
1552
+ deleteVersion(ifError, currentTab) {
1553
+ if (!ifError && this.state.tabCount === 1) {
1554
+ return;
1555
+ }
1556
+ let formData = {};
1557
+ let finalCurrentTab = 0;
1558
+ let tabCount = 0;
1559
+ if (ifError) {
1560
+ formData = _.cloneDeep(this.state.errorData);
1561
+ tabCount = this.state.tabCount + 1;
1562
+ finalCurrentTab = currentTab;
1563
+ } else {
1564
+ formData = _.cloneDeep(this.state.formData);
1565
+ tabCount = this.state.tabCount;
1566
+ finalCurrentTab = this.state.currentTab;
1567
+ }
1568
+ // delete formData[this.state.currentTab - 1];
1569
+ let finalActiveTabKey = '';
1570
+ if (tabCount > 1 && currentTab !== tabCount) {
1571
+ finalActiveTabKey = formData[currentTab].tabKey;
1572
+ }
1573
+
1574
+ if (tabCount > 1 && currentTab === tabCount) {
1575
+ finalActiveTabKey = formData[currentTab - 2].tabKey;
1576
+ finalCurrentTab = currentTab - 1;
1577
+ }
1578
+ // if (this.state.tabCount > 1 && this.state.currentTab === 1) {
1579
+ // finalActiveTabKey = this.state.formData[1].tabKey;
1580
+ // }
1581
+ if (tabCount === 1) {
1582
+ finalActiveTabKey = '';
1583
+ }
1584
+ const initialFormData = _.cloneDeep(formData[0]);
1585
+ for (let count = currentTab - 1; count < tabCount - 1; count += 1) {
1586
+ delete formData[count];
1587
+ _.forEach(initialFormData, (val, key) => {
1588
+ if (!formData[count]) {
1589
+ formData[count] = {};
1590
+ }
1591
+ if (key === 'base') {
1592
+ formData[count].base = formData[count + 1].base ? formData[count + 1].base : false;
1593
+ return true;
1594
+ }
1595
+ if (key === 'tabKey') {
1596
+ formData[count].tabKey = formData[count + 1].tabKey;
1597
+ return true;
1598
+ }
1599
+ formData[count][`${key}${count === 0 ? '' : count + 1}`] = formData[count + 1][`${key}${count + 2}`];
1600
+ return true;
1601
+ });
1602
+ }
1603
+ delete formData[tabCount - 1];
1604
+ if (ifError) {
1605
+ this.setState({errorData: formData});
1606
+ } else {
1607
+ const initialTab = currentTab;
1608
+ if (this.props.isNewVersionFlow) {
1609
+ formData['template-version-options'].splice(`${currentTab - 1}`, 1);
1610
+ formData['template-version'] = formData['template-version-options'][0].value;
1611
+ }
1612
+ this.setState({formData, tabCount: tabCount - 1, tabKey: finalActiveTabKey, currentTab: finalCurrentTab}, () => {
1613
+ this.deleteVersion(true, initialTab);
1614
+ });
1615
+
1616
+ this.props.onChange(formData, tabCount - 1);
1617
+ }
1618
+ }
1619
+
1620
+ deleteLanguage = () => {
1621
+ // if (this.state.formData[`${this.state.currentTab - 1}`].activeTab === this.props.baseLanguage) {
1622
+
1623
+ // } else {
1624
+ if (this.state.formData[`${this.state.currentTab - 1}`].activeTab !== this.props.baseLanguage) {
1625
+ const formData = _.cloneDeep(this.state.formData);
1626
+ const currentTab = `${this.state.currentTab - 1}`;
1627
+ const currentLang = formData[`${this.state.currentTab - 1}`].activeTab;
1628
+ const deleteLanguageIndex = formData[currentTab].selectedLanguages.indexOf(currentLang);
1629
+ const baseLangTabKey = formData[currentTab][this.props.baseLanguage].tabKey;
1630
+
1631
+ delete formData[currentTab][currentLang];
1632
+ formData[currentTab].activeTab = this.props.baseLanguage;
1633
+ formData[currentTab].selectedLanguages.splice(deleteLanguageIndex, 1);
1634
+ formData[currentTab].tabKey = baseLangTabKey;
1635
+ if (formData[currentTab].base) {
1636
+ delete formData.base[currentLang];
1637
+ delete formData.base.selectedLanguages.splice(deleteLanguageIndex, 1);
1638
+ formData.base.tabKey = baseLangTabKey;
1639
+ formData.base.activeTab = this.props.baseLanguage;
1640
+ }
1641
+
1642
+ this.setState({formData, currentLangTab: this.props.baseLanguage, tabKey: baseLangTabKey}, () => {
1643
+ this.state.currentEvent.call(this.props.parent, formData, deleteLanguageIndex);
1644
+ this.setState({currentEvent: {}, currentEventData: {}});
1645
+ });
1646
+ }
1647
+ };
1648
+
1649
+ renameVersion(currentTab) {
1650
+ document.getElementById(`tab-header${currentTab > 1 ? currentTab : ''}`).contentEditable = "true";
1651
+ document.getElementById(`tab-header${currentTab > 1 ? currentTab : ''}`).focus();
1652
+ }
1653
+
1654
+ updateFormData(data, val, event) {
1655
+ const formData = _.cloneDeep(this.state.formData);
1656
+
1657
+ const tabIndex = this.state.currentTab - 1;
1658
+ let currentTab = _.cloneDeep(this.state.currentTab);
1659
+
1660
+ if (this.state.usingTabContainer && !val.standalone) {
1661
+ const data1 = data;
1662
+ if (event === "addLanguage") {
1663
+ const addLanguageType = this.props.addLanguageType;
1664
+ if (addLanguageType === '') {
1665
+ return;
1666
+ }
1667
+ const currentLang = formData[tabIndex].activeTab;
1668
+ let baseTab = _.cloneDeep(formData[tabIndex][currentLang]);
1669
+ let id = _.uniqueId();
1670
+ let validId = false;
1671
+ switch (addLanguageType) {
1672
+ case "upload":
1673
+ baseTab = _.cloneDeep(formData[tabIndex][currentLang]);
1674
+
1675
+ baseTab.iso_code = data.iso_code;
1676
+ baseTab.lang_id = data.lang_id;
1677
+ baseTab.language = data.language;
1678
+ while (!validId) {
1679
+ validId = true;
1680
+ for (let idx = 0; idx < formData[tabIndex].selectedLanguages.length; idx += 1) {
1681
+ if (!formData[tabIndex]) {
1682
+ continue;
1683
+ }
1684
+
1685
+ if (id === formData[tabIndex][formData[tabIndex].selectedLanguages[idx]].tabKey) {
1686
+ validId = false;
1687
+ }
1688
+ }
1689
+ if (validId) {
1690
+ break;
1691
+ }
1692
+ id = _.uniqueId();
1693
+ }
1694
+ baseTab.tabKey = id;
1695
+ //formData[tabIndex].selectedLanguages.push(data.iso_code);
1696
+ formData[tabIndex][data.iso_code] = baseTab;
1697
+
1698
+ formData[tabIndex].activeTab = data.iso_code;
1699
+ formData[tabIndex].tabKey = baseTab.tabKey;
1700
+ break;
1701
+ case "copyPrimaryLanguage":
1702
+ case "useEditor":
1703
+ baseTab = _.cloneDeep(formData[tabIndex][this.props.baseLanguage]);
1704
+
1705
+ //baseTab['template-content'] = '';
1706
+ baseTab.iso_code = data.iso_code;
1707
+ baseTab.lang_id = data.lang_id;
1708
+ baseTab.language = data.language;
1709
+ validId = false;
1710
+ while (!validId) {
1711
+ validId = true;
1712
+ for (let idx = 0; idx < formData[tabIndex].selectedLanguages.length; idx += 1) {
1713
+ if (!formData[idx]) {
1714
+ continue;
1715
+ }
1716
+ if (id === formData[tabIndex][formData[tabIndex].selectedLanguages[idx]].tabKey) {
1717
+ validId = false;
1718
+ }
1719
+ }
1720
+ if (validId) {
1721
+ break;
1722
+ }
1723
+ id = _.uniqueId();
1724
+ }
1725
+ baseTab.tabKey = id;
1726
+ formData[tabIndex].selectedLanguages.push(data.iso_code);
1727
+ formData[tabIndex][data.iso_code] = baseTab;
1728
+
1729
+ formData[tabIndex].activeTab = data.iso_code;
1730
+ formData[tabIndex].tabKey = baseTab.tabKey;
1731
+ break;
1732
+ case '':
1733
+ return;
1734
+ default:
1735
+ break;
1736
+ }
1737
+ const that = this;
1738
+ setTimeout(() => {
1739
+ that.setState({tabKey: baseTab.tabKey});
1740
+ }, 0);
1741
+ }
1742
+
1743
+ if (!this.props.isNewVersionFlow) {
1744
+ formData[tabIndex][val.id] = data1;
1745
+ } else if (this.props.isNewVersionFlow && event !== "addLanguage" && event !== "onContentChange") {
1746
+ formData[tabIndex][this.props.baseLanguage][val.id] = data1;
1747
+ }
1748
+
1749
+ if (formData[tabIndex].base) {
1750
+ if (!this.props.isNewVersionFlow) {
1751
+ formData.base[val.id] = data1;
1752
+ } else {
1753
+ formData.base[data1.iso_code] = formData[tabIndex][data1.iso_code];
1754
+ formData.base.tabKey = formData[tabIndex].tabKey;
1755
+ formData.base.activeTab = formData[tabIndex].activeTab;
1756
+ formData.base.selectedLanguages = formData[tabIndex].selectedLanguages;
1757
+ }
1758
+ }
1759
+ } else {
1760
+ formData[val.id] = data;
1761
+ }
1762
+
1763
+ if (this.props.isNewVersionFlow) {
1764
+ if (event === 'onSelect' && data === 'New Version') {
1765
+ this.callChildEvent(data, val, 'addVersion', event);
1766
+ } else if (event === 'onSelect' && data !== 'New Version') {
1767
+ currentTab = _.findIndex(this.state.formData['template-version-options'], { key: data}) + 1;
1768
+ this.setState({currentTab, tabKey: formData[`${currentTab - 1}`].tabKey}, () => {
1769
+ val.injectedEvents[event].call(this, this.state.formData['template-version-options'][currentTab - 1].key, formData, val);
1770
+ });
1771
+ }
1772
+
1773
+ if (event === 'onContentChange') {
1774
+
1775
+ // formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab]['template-content'] = data.editor.getData();
1776
+ // if (formData[`${this.state.currentTab - 1}`].tabKey === formData.base.tabKey) {
1777
+ // formData.base[formData[`${this.state.currentTab - 1}`].activeTab][`template-content`] = data.editor.getData();
1778
+ //}
1779
+ }
1780
+ }
1781
+
1782
+
1783
+ this.setState({formData}, () => {
1784
+ if (this.props.startValidation) {
1785
+ this.validateForm();
1786
+ }
1787
+ });
1788
+ if (event && val.injectedEvents[event]) {
1789
+ if (event === "onRowClick") {
1790
+ val.injectedEvents[event].call(this, data);
1791
+ } else if (this.props.isNewVersionFlow && event !== 'onSelect') {
1792
+ if (event === 'addLanguage') {
1793
+ val.injectedEvents[event].call(this, data, formData, val);
1794
+ this.setState({currentEventVal: {}, currentEvent: {}, currentEventData: {}});
1795
+ } else {
1796
+ val.injectedEvents[event].call(this, true, formData, val);
1797
+ }
1798
+ } else if (!this.props.isNewVersionFlow) {
1799
+ val.injectedEvents[event].call(this, true, formData, val);
1800
+ }
1801
+ } else if (val.injectedEvents && val.injectedEvents.onChange) {
1802
+ val.injectedEvents.onChange.call(this, true, formData, val);
1803
+ }
1804
+
1805
+ if (!((event === 'onSelect' && data === 'New Version') || event === 'onContentChange')) {
1806
+ this.props.onChange(formData, this.state.tabCount, currentTab, val);
1807
+ }
1808
+ }
1809
+
1810
+
1811
+ hasClass(element, className) {
1812
+ return (` ${element.className} `).indexOf(` ${className} `) > -1;
1813
+ }
1814
+ allowAddSecondaryCta = (val) => {
1815
+ if (val.fieldsCount > 0) {
1816
+ const errorData = _.cloneDeep(this.state.errorData);
1817
+ _.forEach(Object.keys(errorData), (key) => {
1818
+ if (typeof errorData[key] !== "object") {
1819
+ errorData[key] = false;
1820
+ } else {
1821
+ _.forEach(Object.keys(errorData[key]), (innerKey) => {
1822
+ errorData[key][innerKey] = false;
1823
+ });
1824
+ }
1825
+ });
1826
+ if (this.state.formData[this.state.currentTab - 1][`secondary-cta-${val.fieldsCount - 1}-label`] === "") {
1827
+ errorData[this.state.currentTab - 1][`secondary-cta-${val.fieldsCount - 1}-label`] = true;
1828
+ this.setState({errorData, checkValidation: true, isFormValid: false});
1829
+ return false;
1830
+ }
1831
+ if (this.state.formData[this.state.currentTab - 1][`cta-deeplink-secondary-cta-${val.fieldsCount - 1}`] === "") {
1832
+ errorData[this.state.currentTab - 1][`cta-deeplink-secondary-cta-${val.fieldsCount - 1}`] = true;
1833
+ this.setState({errorData, checkValidation: true, isFormValid: false});
1834
+ return false;
1835
+ }
1836
+ if (this.state.formData[this.state.currentTab - 1][`cta-deeplink-secondary-cta-${val.fieldsCount - 1}-select`] === "") {
1837
+ errorData[this.state.currentTab - 1][`cta-deeplink-secondary-cta--${val.fieldsCount - 1}-select`] = true;
1838
+ this.setState({errorData, checkValidation: true, isFormValid: false});
1839
+ return false;
1840
+ }
1841
+ }
1842
+ return true;
1843
+ };
1844
+ callChildEvent(data, val, event) {
1845
+ if (!event) {
1846
+ return;
1847
+ }
1848
+
1849
+ const tab = this.state.tabCount;
1850
+ // const parent = this._reactInternalInstance._currentElement._owner._instance;
1851
+ if (event === 'onTabChange') {
1852
+ const that = this;
1853
+ this.setState({tabKey: `${data}`});
1854
+ setTimeout(() => {
1855
+ if (this.props.isNewVersionFlow) {
1856
+ const formData = _.cloneDeep(this.state.formData);
1857
+ let activeTabIndex = '1';
1858
+ const elems = document.getElementsByClassName("ant-tabs-tab");
1859
+
1860
+ for (let i = 0; i < elems.length; i += 1) {
1861
+ if (elems.item(i).classList.contains("ant-tabs-tab-active")) {
1862
+ activeTabIndex = i + 1;
1863
+ }
1864
+ }
1865
+
1866
+ formData[(this.state.currentTab - 1)].activeTab = formData[(this.state.currentTab - 1)].selectedLanguages[activeTabIndex - 1];
1867
+ formData[(this.state.currentTab - 1)].tabKey = `${data}`;
1868
+ if (formData[(this.state.currentTab - 1)].base) {
1869
+ formData.base.activeTab = formData[(this.state.currentTab - 1)].selectedLanguages[activeTabIndex - 1];
1870
+ formData.base.tabKey = `${data}`;
1871
+ }
1872
+
1873
+ that.setState({formData, currentLangTab: formData[(this.state.currentTab - 1)].activeTab, tabKey: formData[(this.state.currentTab - 1)][formData[(this.state.currentTab - 1)].activeTab].tabKey}, () => {
1874
+ val.injectedEvents[event].call(that.props.parent, this.state.currentTab, formData);
1875
+ });
1876
+ } else {
1877
+ let activeTabIndex = '1';
1878
+ const elems = document.getElementsByClassName("ant-tabs-tab");
1879
+
1880
+ for (let i = 0; i < elems.length; i += 1) {
1881
+ if (elems.item(i).classList.contains("ant-tabs-tab-active")) {
1882
+ activeTabIndex = i + 1;
1883
+ }
1884
+ }
1885
+
1886
+ that.setState({currentTab: activeTabIndex});
1887
+ val.injectedEvents[event].call(that.props.parent, activeTabIndex);
1888
+ }
1889
+ }, 0);
1890
+ return;
1891
+ } else if (event === 'addVersion') {
1892
+ this.cloneVersionData();
1893
+ this.setState({ popoverVisible: false });
1894
+ const that = this;
1895
+ setTimeout(() => {
1896
+ val.injectedEvents[event].call(that.props.parent, tab);
1897
+ }, 0);
1898
+ return;
1899
+ } else if (event === 'onTagSelect') {
1900
+ val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab, val);
1901
+ return;
1902
+ } else if (event === 'markFinalVersion' || event === 'duplicateVersion' || event === 'deleteVersion' || event === 'renameVersion') {
1903
+ this.setState({ popoverVisible: false });
1904
+ if ((event !== 'deleteVersion' && !this.props.isNewVersionFlow) || ((event === 'deleteVersion') && this.props.schema.channel.toUpperCase() === 'EMAIL')) {
1905
+ val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab);
1906
+ } else {
1907
+ this.setState({currentEvent: val.injectedEvents[event], currentEventData: data});
1908
+ }
1909
+ if (event === 'markFinalVersion') {
1910
+ this.markFinalTabVersion();
1911
+ if (this.props.isNewVersionFlow) {
1912
+ val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab);
1913
+ }
1914
+ } else if (event === 'duplicateVersion') {
1915
+ if (this.props.schema.channel.toUpperCase() === 'EMAIL') {
1916
+ const formData = _.cloneDeep(this.state.formData);
1917
+ formData[this.state.tabCount] = _.cloneDeep(formData[`${this.state.currentTab - 1}`]);
1918
+ _.forEach(formData[this.state.tabCount].selectedLanguages, (lang) => {
1919
+ const tmptabData = formData[this.state.tabCount][lang];
1920
+ _.forEach(formData[this.state.tabCount][lang], (tabData, index) => {
1921
+ if (index === 'tabKey') {
1922
+ tmptabData.tabKey = _.uniqueId();
1923
+ }
1924
+ });
1925
+ });
1926
+ formData[this.state.tabCount].tabKey = formData[this.state.tabCount][formData[this.state.tabCount].activeTab].tabKey;
1927
+
1928
+ this.setState({formData, tabKey: formData[this.state.tabCount].tabKey}, () => {
1929
+ val.injectedEvents[event].call(this.props.parent, formData, this.state.currentTab);
1930
+ });
1931
+ } else {
1932
+ this.duplicateVersion();
1933
+ }
1934
+ } else if (event === 'deleteVersion') {
1935
+ if (this.props.schema.channel.toUpperCase() === 'EMAIL') {
1936
+ // this.deleteVersion(false, this.state.currentTab);
1937
+ this.setState({currentEvent: val.injectedEvents[event], currentEventData: data }, () => {
1938
+ this.props.setModalContent('delete-version');
1939
+ });
1940
+ } else {
1941
+ this.handleConfirmations();
1942
+ }
1943
+ } else if (event === 'renameVersion') {
1944
+ this.renameVersion(this.state.currentTab);
1945
+ }
1946
+ return;
1947
+ } else if (event === 'discardValues') {
1948
+ val.injectedEvents[event].call(this.props.parent, data);
1949
+ if (this.props.isEdit) {
1950
+ this.resetState(true, this.state.usingTabContainer);
1951
+ } else {
1952
+ this.resetState(false, this.state.usingTabContainer);
1953
+ }
1954
+ return;
1955
+ } else if (event === 'onChange') {
1956
+ if (val.id === 'tab-header') {
1957
+ val.injectedEvents[event].call(this.props.parent, data, this.state.currentTab);
1958
+ this.changeVersionName(data);
1959
+ }
1960
+ return;
1961
+ } else if (event === "addSecondaryCta") {
1962
+ if (!this.allowAddSecondaryCta(val)) {
1963
+ return;
1964
+ }
1965
+ } else if (event === "onContentChange") {
1966
+ val.injectedEvents[event].call(this.props.parent, data, val.id);
1967
+ return;
1968
+ } else if (event === 'deleteLanguage') {
1969
+ this.setState({currentEvent: val.injectedEvents[event], currentEventData: data }, () => {
1970
+ this.props.setModalContent('delete-language');
1971
+ });
1972
+ // const modalContent = {
1973
+ // title: "Alert",
1974
+ // body: "Do you really want to delete this language?",
1975
+ // type: 'confirm',
1976
+ // id: 'email-language-delete-modal',
1977
+ // };
1978
+ // debugger;
1979
+ // if (this.state.formData[`${this.state.currentTab - 1}`].activeTab === this.props.baseLanguage) {
1980
+ //
1981
+ // } else {
1982
+ // const formData = _.cloneDeep(this.state.formData);
1983
+ // const currentTab = `${this.state.currentTab - 1}`;
1984
+ // const currentLang = formData[`${this.state.currentTab - 1}`].activeTab;
1985
+ // const deleteLanguageIndex = formData[currentTab].selectedLanguages.indexOf(currentLang);
1986
+ //
1987
+ // delete formData[currentTab][currentLang];
1988
+ // formData[currentTab].activeTab = this.props.baseLanguage;
1989
+ // formData[currentTab].selectedLanguages.splice(deleteLanguageIndex, 1);
1990
+ //
1991
+ // this.setState({formData, currentLangTab: this.props.baseLanguage}, () => {
1992
+ // val.injectedEvents[event].call(this.props.parent, formData, deleteLanguageIndex);
1993
+ // });
1994
+ // }
1995
+ return;
1996
+ }
1997
+ console.log('Call Event ', event, data, this.props.parent);
1998
+ // val.injectedEvents[event].call(this.props.parent, data);
1999
+ val.injectedEvents[event].call(this.props.parent, data, val.id);
2000
+ }
2001
+ openFileDialog = (e, parentID) => {
2002
+ console.log("filedialog: ");
2003
+ document.querySelector(`#${parentID} #fileName`).click();
2004
+ };
2005
+ handleOk = (ev) => {
2006
+ const id = ev.target.id;
2007
+
2008
+ this.setState({showModal: false});
2009
+ if (id === "android" && this.state.androidValid) {
2010
+ this.props.onSubmit(this.state.formData);
2011
+ } else if (id === "ios" && this.state.iosValid) {
2012
+ this.props.onSubmit(this.state.formData);
2013
+ } else if (id === "sms-version-modal") {
2014
+ this.state.currentEvent.call(this.props.parent, this.state.currentEventData, this.state.currentTab);
2015
+ this.setState({currentEvent: {}, currentEventData: {}});
2016
+ this.deleteVersion(false, this.state.currentTab);
2017
+ } else if (id === 'template-back-confirm-modal') {
2018
+ const type = this.props.location.query.type;
2019
+ const response = {
2020
+ action: 'moveToTemplates',
2021
+ value: 'ok',
2022
+ };
2023
+ this.props.iframeParent.postMessage(JSON.stringify(response), '*');
2024
+ const isLanguageSupport = this.props.location.query.isLanguageSupport || false;
2025
+ const isEdmSupport = (this.props.location.query.isEdmSupport !== "false") || false;
2026
+ const module = this.props.location.query.module ? this.props.location.query.module : 'default';
2027
+ this.props.router.push({
2028
+ pathname: `/${this.props.schema.channel.toLowerCase()}/`,
2029
+ query: type === 'embedded' ? {type: 'embedded', module, isLanguageSupport, isEdmSupport} : {module, isLanguageSupport, isEdmSupport},
2030
+ });
2031
+ } else if (id === "email-language-delete-modal") {
2032
+ this.deleteLanguage();
2033
+ this.props.handleCancelModal();
2034
+ // this.setState({currentEvent: {}, currentEventData: {}});
2035
+ } else if (id === 'email-version-delete-modal') {
2036
+ this.deleteVersion(false, this.state.currentTab);
2037
+ } else if ( id === 'template-delete-confirm-modal') {
2038
+ this.props.handleDelete(this.props.modal);
2039
+ }
2040
+ };
2041
+ handleCancel = (ev) => {
2042
+ const id = ev.target.id;
2043
+ this.setState({showModal: false});
2044
+ if (id === 'template-back-confirm-modal') {
2045
+ const response = {
2046
+ action: 'moveToTemplate',
2047
+ value: 'cancel',
2048
+ };
2049
+ this.props.iframeParent.postMessage(JSON.stringify(response), '*');
2050
+ }
2051
+ if (this.props.handleCancelModal) {
2052
+ this.props.handleCancelModal();
2053
+ }
2054
+ };
2055
+ handleConfirmations = () => {
2056
+ this.setState({showModal: true});
2057
+ };
2058
+
2059
+ handleSetRadioValue = (formData, currentTab, val) => {
2060
+ if (formData[currentTab - 1] && formData[currentTab - 1][val.id] && formData[currentTab - 1][val.id] !== "") {
2061
+ return formData[currentTab - 1][val.id];
2062
+ } else if (formData[val.id]) {
2063
+ return formData[val.id];
2064
+ }
2065
+ return val.value;
2066
+ }
2067
+ uploadImages = (e, {files}, val) => {
2068
+ e.preventDefault();
2069
+ const _URL = window.URL || window.webkitURL;
2070
+ const file = files[0];
2071
+ if (val.supportedExtensions) {
2072
+ const allowedExtensions = /(\.bmp|\.jpeg|\.png|\.gif|\.jpg)$/i;
2073
+ if (!allowedExtensions.exec(file.name)) {
2074
+ this.callChildEvent({file, type: 'wrong file'}, val, val.submitAction);
2075
+ }
2076
+ }
2077
+ const img = new Image();
2078
+ img.src = _URL.createObjectURL(file);
2079
+ img.onload = () => {
2080
+ const fileParams = {
2081
+ width: this.width,
2082
+ height: this.height,
2083
+ error: file.size / (1e+6) > 3,
2084
+ };
2085
+ this.callChildEvent({file, type: 'image', fileParams}, val, val.submitAction);
2086
+ };
2087
+ const event = e;
2088
+ event.target.value = null;
2089
+ };
2090
+
2091
+ findBaseTab = () => {
2092
+ const activeTabKey = this.state.formData && this.state.formData.base ? this.state.formData.base.tabKey : -1;
2093
+ const formData = _.cloneDeep(this.state.formData);
2094
+ let baseTab = 0;
2095
+ for (let i = 0; i < this.state.tabCount; i += 1) {
2096
+ if (formData[i] && formData[i].tabKey === activeTabKey) {
2097
+ baseTab = i;
2098
+ }
2099
+ }
2100
+
2101
+ return baseTab;
2102
+ };
2103
+
2104
+ handleOnHoverItem = (isHovering, id) => {
2105
+ if (isHovering) {
2106
+ this.setState({hoveredItem: id});
2107
+ } else {
2108
+ this.setState({hoveredItem: ''});
2109
+ }
2110
+ }
2111
+
2112
+ handleOnItemClick = (isClicked, id) => {
2113
+ this.setState({clickedItem: id});
2114
+ }
2115
+
2116
+ populateTemplatesList(data) {
2117
+ if (!data) {
2118
+ return [];
2119
+ }
2120
+ const items = [];
2121
+ data.map( (template) => {
2122
+ //
2123
+ const temp = {};
2124
+ temp.id = template._id;
2125
+ if (this.props.schema.channel.toLowerCase() === 'email') {
2126
+ //
2127
+ const imgSrc = template && template.versions && template.versions.base ? template.versions.base.preview_http_url : '';
2128
+ // const ifPreviewGenerated = template && template.versions && template.versions.base ? template.versions.base.isPreviewGenerated : 0;
2129
+ const content = <img src={imgSrc || ''} alt="" />;
2130
+
2131
+ temp.content = (
2132
+ <div
2133
+ className="sms-template-content">
2134
+ <div className={`sms-text ${this.state.clickedItem === template._id ? 'sms-text-blurred' : ''}`}>
2135
+ {content}
2136
+ </div>
2137
+ {/*template._id === this.state.clickedItem ? <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> : ''*/}
2138
+ {/*template._id === this.state.clickedItem ? <CapButton onClick={() => this.handlePreviewClick(template)} className="preview-button" type="cancel">{this.props.intl.formatMessage(messages.previewButton)}</CapButton> : ''*/}
2139
+ </div>);
2140
+ }
2141
+ // temp.footer = (
2142
+ // <div className="footer-container">
2143
+ // <div className="card-title">
2144
+ // <span className="template-name" style={{ fontWeight: `${this.props.schema.channel.toLowerCase() === 'wechat' ? '400' : '600'}` }}>
2145
+ // { template && template.versions && template.versions.history && template.versions.history.length > 1 && this.props.schema.channel.toLowerCase() !== 'mobilepush' && <i style={{fontSize: '16px', margin: '0 8px 0 0', verticalAlign: 'middle'}} className="material-icons">filter_none</i>}
2146
+ // {template.name}
2147
+ // </span>
2148
+ // </div>
2149
+ // </div>
2150
+ // );
2151
+ items.push(temp);
2152
+ return true;
2153
+ });
2154
+ return items;
2155
+ }
2156
+
2157
+ handleAddLanguageFlow(data, val, event) {
2158
+ this.setState({currentEventData: data, currentEventVal: val, currentEvent: event, customPopoverVisible: false}, () => {
2159
+ this.props.setModalContent('add-language', data);
2160
+ });
2161
+ }
2162
+
2163
+ renderColLabelSection(section, childIndex) {
2164
+ // const schema = this.props.schema
2165
+ const fields = [];
2166
+ _.forEach(section.inputFields, (val) => {
2167
+ const row = [];
2168
+ const columns = [];
2169
+ const type = val.type;
2170
+ const styling = val.styling;
2171
+ if (!this.props.isNewVersionFlow && !val.standalone && !val.onlyDisplay && this.props.usingTabContainer && !this.state.formData[`${this.state.currentTab - 1}`]) {
2172
+ return true;
2173
+ }
2174
+ if (!val.onlyDisplay && !val.standalone && (!this.state.formData[`${this.state.currentTab - 1}`] || (!this.state.formData[`${this.state.currentTab - 1}`][val.id] && this.state.formData[`${this.state.currentTab - 1}`][val.id] === null))) {
2175
+ return true;
2176
+ }
2177
+ if (!val.onlyDisplay && !val.standalone && (!this.state.errorData[`${this.state.currentTab - 1}`] || (!this.state.errorData[`${this.state.currentTab - 1}`][val.id] && this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null))) {
2178
+ return true;
2179
+ }
2180
+ //
2181
+ columns.push(
2182
+ <CapColumn key="label" span={4}>
2183
+ <Label style={val.labelStyle ? val.labelStyle : {}}>{val.label}</Label>
2184
+ </CapColumn>
2185
+ );
2186
+ let ifError = false;
2187
+ const isVersionEnable = (this.state.usingTabContainer && !val.standalone);
2188
+ if (val.primitive) {
2189
+ if (val.id === "mark-final-version-label") {
2190
+ const baseTab = this.findBaseTab();
2191
+ if ((baseTab + 1) === childIndex) {
2192
+ return true;
2193
+ }
2194
+ }
2195
+ columns.push(
2196
+ <CapColumn key={val.id} span={val.width}>
2197
+ {this.renderPrimitiveElement(val, childIndex)}
2198
+ </CapColumn>
2199
+ );
2200
+ return true;
2201
+ }
2202
+ let content = "";
2203
+ let charList = {};
2204
+ switch (type) {
2205
+ case "input":
2206
+ if (styling === 'semantic') {
2207
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2208
+ const value = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id];
2209
+ columns.push(
2210
+ <CapColumn key={val.id} span={val.width} offset={val.offset}>
2211
+ <CapInput
2212
+ id={val.id}
2213
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2214
+ className={`input-primary chart-name-input${ifError ? ' error' : ''}`}
2215
+ // fluid={val.fluid}
2216
+ style={val.style ? val.style : {}}
2217
+ placeholder={val.placeholder}
2218
+ onChange={(e) => this.updateFormData(e.target.value, val)}
2219
+ defaultValue={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2220
+ value={value || ""}
2221
+ disabled={val.disabled}
2222
+ />
2223
+ </CapColumn>
2224
+ );
2225
+ }
2226
+ break;
2227
+ case "SmsEditor":
2228
+ columns.push(
2229
+ <CapColumn span={5} key="input">
2230
+ <SmsEditor
2231
+ id={val.id}
2232
+ content={this.state.formData[val.id]}
2233
+ onDataChange={(data) => this.updateFormData(data.value, val)}
2234
+ />
2235
+ </CapColumn>
2236
+ );
2237
+ break;
2238
+ case "textarea":
2239
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2240
+ const value = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id];
2241
+ if (styling === 'semantic') {
2242
+ columns.push(
2243
+ <CapColumn key="input" span={val.width}>
2244
+ <TextArea
2245
+ id={val.id}
2246
+ className={`${ifError ? 'error' : ''}`}
2247
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2248
+ label={val.label}
2249
+ autosize={val.autosize ? val.autosizeParams : false}
2250
+ onChange={(e) => this.updateFormData(e.target.value, val)}
2251
+ style={val.style ? val.style : {}}
2252
+ defaultValue={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2253
+ value={value || ""}
2254
+ rows={20}
2255
+ disabled={val.disabled}
2256
+ cols={20}
2257
+ />
2258
+ </CapColumn>
2259
+ );
2260
+ }
2261
+ break;
2262
+ case "contentPreview":
2263
+ content = isVersionEnable ? this.state.formData[this.state.currentTab - 1]['sms-editor'] : this.state.formData['sms-editor'];
2264
+ charList = updateCharCount(content).char_list;
2265
+ columns.push(<CapColumn id={val.id} className={"preview-chars"} span={val.width}>
2266
+ {charList.map((char) => char)}
2267
+ </CapColumn>);
2268
+ break;
2269
+ case "checkbox":
2270
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2271
+ if (styling === 'semantic') {
2272
+ columns.push(
2273
+ <CapColumn key="input" span={val.width} offset={val.offset}>
2274
+ <CapCheckbox
2275
+ className={`${ifError ? 'error' : ''}`}
2276
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2277
+ style={val.style ? val.style : {}}
2278
+ onChange={(e) => this.updateFormData(e, val)}
2279
+ checked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2280
+ defaultChecked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2281
+ disabled={val.disabled}
2282
+ />
2283
+ </CapColumn>
2284
+ );
2285
+ }
2286
+ break;
2287
+ case "tag-list":
2288
+ columns.push(
2289
+ <CapColumn key={`input-${val.id}`} span={10} offset={val.offset}>
2290
+ <TagList
2291
+ key={`input-${val.id}`}
2292
+ moduleFilterEnabled={this.props.location && this.props.location.query && this.props.location.query.type !== 'embedded'}
2293
+ label={val.label ? val.label : ''}
2294
+ onTagSelect={(data) => this.callChildEvent(data, val, 'onTagSelect')}
2295
+ onContextChange={this.props.onContextChange}
2296
+ location={this.props.location}
2297
+ tags={this.props.tags ? this.props.tags : []}
2298
+ injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
2299
+ className={val.className ? val.className : ''}
2300
+ id={val.id}
2301
+ userLocale={this.props.userLocale}
2302
+ />
2303
+ </CapColumn>
2304
+ );
2305
+ break;
2306
+ case "tabs":
2307
+ columns.push(
2308
+ <CapColumn key="input" span={10}>
2309
+ <TagList
2310
+ onTagSelect={(data) => this.callChildEvent(data, val, 'onTagSelect')}
2311
+ />
2312
+ </CapColumn>
2313
+ );
2314
+ break;
2315
+ case "sms-preview": {
2316
+ if (this.state.usingTabContainer && !this.state.formData[`${this.state.currentTab - 1}`]) {
2317
+ return true;
2318
+ }
2319
+ content = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`sms-editor${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData[val.id];
2320
+ const unicodeEnabled = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`unicode-validity${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData['unicode-validity'];
2321
+ columns.push(
2322
+ <CapColumn key="input" span={10}>
2323
+ <TemplatePreview
2324
+ channel={val.channel ? val.channel : 'SMS'}
2325
+ content={content}
2326
+ charCounterEnabled={val.charCounterEnabled}
2327
+ unicodeEnabled={unicodeEnabled}
2328
+ >
2329
+ </TemplatePreview>
2330
+ </CapColumn>
2331
+ );
2332
+ break;
2333
+ }
2334
+ case "popover":
2335
+ columns.push(
2336
+ <CapPopover
2337
+ trigger={val.trigger}
2338
+ placement={val.placement}
2339
+ visible={this.state.popoverVisible && (this.props.isNewVersionFlow || this.state.currentTab === childIndex || !childIndex)}
2340
+ onVisibleChange={this.handleVisibleChange}
2341
+ content={
2342
+ _.forEach(val.content.sections, (contentSection) => {
2343
+ this.renderSection(contentSection);
2344
+ })
2345
+ }
2346
+ >
2347
+ {
2348
+ _.forEach(val.value.sections, (popoverSection) => {
2349
+ this.renderSection(popoverSection);
2350
+ })
2351
+ }
2352
+ </CapPopover>
2353
+ );
2354
+ break;
2355
+ case "select": {
2356
+ const options = (this.state.formData[`${val.id}-options`]) ? (this.state.formData[`${val.id}-options`]) : val.options;
2357
+ columns.push(
2358
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width}>
2359
+ <CapSelect
2360
+ id={val.id}
2361
+ placeholder={val.placeholder ? val.placeholder : ''}
2362
+ options={options}
2363
+ style={val.style ? val.style : {}}
2364
+ onSelect={(data) => this.updateFormData(data, val, 'onSelect')}
2365
+ value={(this.state.formData[val.id] && this.state.formData[val.id] !== '' ? this.state.formData[val.id] : undefined)}
2366
+ disabled={val.disabled}
2367
+ />
2368
+ </CapColumn>
2369
+ );
2370
+ }
2371
+ break;
2372
+ case "ckeditor":
2373
+
2374
+ columns.push(
2375
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width}>
2376
+ <CKEditor
2377
+ id={val.id}
2378
+ content={(this.state.formData[`${this.state.currentTab - 1}`][val.id] ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : '')}
2379
+ events={val.events}
2380
+ getEditorInstanse={val.getEditorInstanse}
2381
+ // this.callChildEvent(data, val, 'addVersion', event);
2382
+ handleContentChange={(event) => this.callChildEvent(event, val, 'onContentChange')}
2383
+ />
2384
+ </CapColumn>
2385
+ );
2386
+ break;
2387
+ case "edmeditor": {
2388
+ // if (!this.state.formData[`${this.state.currentTab - 1}`]) {
2389
+ // return true;
2390
+ // }
2391
+ let langTab = 1;
2392
+ if (val.id.match(/edmeditor/g)) {
2393
+ if (val.length > 9 && val.id.charAt(9)) {
2394
+ langTab = val.id.charAt(9);
2395
+ }
2396
+ }
2397
+ const edmSrc = this.state.formData[`${this.state.currentTab - 1}`][this.state.currentLangTab][`edmeditor${langTab > 1 ? langTab : ''}src`];
2398
+
2399
+ if (!edmSrc) {
2400
+ return false;
2401
+ }
2402
+
2403
+ columns.push(
2404
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width}>
2405
+ <EDMEditor
2406
+ id={val.id}
2407
+ getEditorInstanse={this.getEditorInstanse}
2408
+ edmSrc={edmSrc}
2409
+ />
2410
+ </CapColumn>
2411
+ );
2412
+ }
2413
+ break;
2414
+ default:
2415
+ break;
2416
+ }
2417
+ row.push(
2418
+ <CapRow>
2419
+ {
2420
+ _.forEach(columns, (value) => {
2421
+ if (value) {
2422
+ return value;
2423
+ }
2424
+ return value;
2425
+ })
2426
+ }
2427
+ </CapRow>
2428
+ );
2429
+
2430
+ fields.push(row);
2431
+ return true;
2432
+ });
2433
+ _.forEach(section.actionFields, (val) => {
2434
+ const row = [];
2435
+ const columns = [];
2436
+ const type = val.type;
2437
+ const styling = val.styling;
2438
+ switch (type) {
2439
+ case "button":
2440
+ if (styling === 'semantic' && val.metaType === 'submit-button') {
2441
+ columns.push(
2442
+ <CapColumn>
2443
+ <CapButton
2444
+ onClick={(data) => this.callChildEvent(data, val, val.submitAction)}>
2445
+ {val.value}
2446
+ </CapButton>
2447
+ </CapColumn>
2448
+ );
2449
+ }
2450
+ break;
2451
+ default:
2452
+ break;
2453
+ }
2454
+ row.push(columns);
2455
+ fields.push(row);
2456
+ });
2457
+ return fields;
2458
+ }
2459
+
2460
+ renderParentSection(section, childIndex) {
2461
+ const cols = [];
2462
+ section.childSections.map( (childSection) => {
2463
+ const renderedChildSection = this.renderSection(childSection, childIndex);
2464
+ cols.push(<CapColumn style={childSection.colStyle ? childSection.colStyle : {}}offset={childSection.offset} span={childSection.width}>{renderedChildSection}</CapColumn>);
2465
+ return true;
2466
+ });
2467
+ const row = (<CapRow style={section.rowStyle ? section.rowStyle : {}}>
2468
+ {
2469
+ _.forEach(cols, (value) => {
2470
+ if (value) {
2471
+ return value;
2472
+ }
2473
+ return value;
2474
+ })
2475
+ }
2476
+ </CapRow>);
2477
+ return row;
2478
+ }
2479
+
2480
+ renderSection(section, childIndex) {
2481
+ switch (section.type) {
2482
+ case "col-label":
2483
+ return this.renderColLabelSection(section, childIndex);
2484
+ case "multicols":
2485
+ return this.renderMultiColSection(section, childIndex);
2486
+ case "parent":
2487
+ return this.renderParentSection(section, childIndex);
2488
+ default:
2489
+ break;
2490
+ }
2491
+ return null;
2492
+ }
2493
+
2494
+ renderPrimitiveElement(val, childIndex) {
2495
+ const type = val.type;
2496
+ const tabName = this.state.formData[childIndex - 1] && this.state.formData[childIndex - 1].name ? this.state.formData[childIndex - 1].name : `${val.value} ${childIndex}`;
2497
+ const value = val.dynamicTab ? tabName : val.value;
2498
+ switch (type) {
2499
+ case "span":
2500
+ return <span id={`${val.id}${childIndex > 1 ? childIndex : ''}`}>{val.dynamicTab ? tabName : val.value}</span>;
2501
+ case "div":
2502
+ let children = _.get(this.state, `formData[${this.state.currentTab - 1}][${val.id}]`) || value;
2503
+ if (_.isEmpty(value) && !_.isEmpty(val.value)) {
2504
+ children = val.value;
2505
+ }
2506
+ const ref = _.get(this, `props.refs[${val.id}]`);
2507
+ return (<div
2508
+ ref={ref}
2509
+ className={val.className ? val.className : ''}
2510
+ id={`${val.id}${childIndex > 1 ? childIndex : ''}`}
2511
+ onClick={(data) => this.callChildEvent(data, val, val.submitAction)}
2512
+ style={val.style ? val.style : {}}
2513
+ onInput={(e) => { e.stopPropagation(); this.callChildEvent(e.target.textContent, val, 'onChange'); }}
2514
+ >{children}</div>);
2515
+ default:
2516
+ return '';
2517
+ }
2518
+ }
2519
+
2520
+ renderMultiColSection(section, childIndex) {
2521
+ const fields = [];
2522
+ let contentSections = [];
2523
+ let popoverSections = [];
2524
+ const self = this;
2525
+ _.forEach(section.inputFields, (field) => {
2526
+ const columns = [];
2527
+ _.forEach(field.cols, (val) => {
2528
+ const type = val.type;
2529
+ const styling = val.styling;
2530
+ const isVersionEnable = (this.state.usingTabContainer && !val.standalone);
2531
+
2532
+
2533
+ if (!this.props.isNewVersionFlow && !val.standalone && !val.onlyDisplay && isVersionEnable && !this.state.formData[`${this.state.currentTab - 1}`]) {
2534
+ return true;
2535
+ }
2536
+ if (!val.standalone && !val.onlyDisplay &&
2537
+ (!this.state.formData[`${this.state.currentTab - 1}`] ||
2538
+ (!this.props.isNewVersionFlow && !this.state.formData[`${this.state.currentTab - 1}`] &&
2539
+ this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null)) &&
2540
+ (this.props.isNewVersionFlow && !this.state.formData[`${this.state.currentTab - 1}`] &&
2541
+ this.state.errorData[`${this.state.currentTab - 1}`] && this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null)) {
2542
+ return true;
2543
+ }
2544
+ if (!val.onlyDisplay && !val.standalone &&
2545
+ (!this.props.isNewVersionFlow && (!this.state.errorData[`${this.state.currentTab - 1}`] ||
2546
+ (!this.state.errorData[`${this.state.currentTab - 1}`] &&
2547
+ this.state.errorData[`${this.state.currentTab - 1}`][val.id] === null)))) {
2548
+ return true;
2549
+ }
2550
+
2551
+ let ifError = false;
2552
+ if (val.primitive) {
2553
+ if (val.id === "mark-final-version-label") {
2554
+ const baseTab = this.findBaseTab();
2555
+ if ((baseTab + 1) === childIndex) {
2556
+ return true;
2557
+ }
2558
+ }
2559
+ columns.push(
2560
+ <CapColumn style={val.colStyle ? val.colStyle : {}} offset={val.offset} key={val.id} span={val.width}>
2561
+ {this.renderPrimitiveElement(val, childIndex)}
2562
+ </CapColumn>
2563
+ );
2564
+ return true;
2565
+ }
2566
+
2567
+ switch (type) {
2568
+ case "input":
2569
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2570
+ const value = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id];
2571
+ if (styling === 'semantic') {
2572
+ columns.push(
2573
+ <CapColumn key={val.id} span={val.width} offset={val.offset}>
2574
+ <CapInput
2575
+ id={val.id}
2576
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2577
+ label={val.label}
2578
+ className={`input-primary chart-name-input${ifError ? ' error' : ''}`}
2579
+ // fluid={val.fluid}
2580
+ style={val.style ? val.style : {}}
2581
+ placeholder={val.placeholder}
2582
+ onChange={(e) => this.updateFormData(e.target.value, val)}
2583
+ value={value || ""}
2584
+ defaultValue={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2585
+ disabled={val.disabled}
2586
+ />
2587
+ </CapColumn>
2588
+ );
2589
+ }
2590
+ break;
2591
+ case "SmsEditor":
2592
+ columns.push(
2593
+ <CapColumn span={5} key="input">
2594
+ <SmsEditor
2595
+ id={val.id}
2596
+ content={this.state.formData[val.id]}
2597
+ onDataChange={(data) => this.updateFormData(data.value, val)}
2598
+ />
2599
+ </CapColumn>
2600
+ );
2601
+ break;
2602
+ case "textarea":
2603
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2604
+ const textValue = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id];
2605
+ if (styling === 'semantic') {
2606
+ columns.push(
2607
+ <CapColumn key="input" span={val.width} offset={val.offset}>
2608
+ <TextArea
2609
+ id={val.id}
2610
+ placeholder={val.placeholder ? val.placeholder : ''}
2611
+ disabled={val.disabled}
2612
+ className={`${ifError ? 'error' : ''}`}
2613
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2614
+ label={val.label}
2615
+ autosize={val.autosize ? val.autosizeParams : false}
2616
+ onChange={(e) => this.updateFormData(e.target.value, val)}
2617
+ style={val.style ? val.style : {}}
2618
+ defaultValue={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2619
+ value={textValue || ""}
2620
+ rows={10}
2621
+ cols={2}
2622
+ />
2623
+ </CapColumn>
2624
+ );
2625
+ }
2626
+ break;
2627
+ case "checkbox":
2628
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2629
+ if (styling === 'semantic') {
2630
+ columns.push(
2631
+ <CapColumn key="input" span={val.width} offset={val.offset}>
2632
+ <CapCheckbox
2633
+ key={val.id}
2634
+ className={`${ifError ? 'error' : ''}`}
2635
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2636
+ onChange={(e) => this.updateFormData(e.target.checked, val, val.submitAction)}
2637
+ checked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2638
+ defaultChecked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2639
+ style={val.style ? val.style : {}}
2640
+ disabled={val.disabled}
2641
+ inductiveText={val.inductiveText}
2642
+ >
2643
+ {val.label}
2644
+ </CapCheckbox>
2645
+ </CapColumn>
2646
+ );
2647
+ }
2648
+ break;
2649
+ case "radio":
2650
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2651
+ if (styling === 'semantic') {
2652
+ columns.push(
2653
+ <CapColumn key={`input-${val.id}`} span={val.width} offset={val.offset}>
2654
+ <CapRadio
2655
+ className={`${ifError ? 'error' : ''}`}
2656
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2657
+ onChange={(e) => this.updateFormData(e.target.checked, val)}
2658
+ checked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2659
+ defaultChecked={isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][val.id] : this.state.formData[val.id]}
2660
+ style={val.style ? val.style : {}}
2661
+ >
2662
+ {val.label}
2663
+ </CapRadio>
2664
+ </CapColumn>
2665
+ );
2666
+ }
2667
+ break;
2668
+ case 'radioGroup':
2669
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2670
+ if (styling === 'semantic') {
2671
+ columns.push(
2672
+ <CapColumn key={`input-${val.id}`} span={val.width} offset={val.offset}>
2673
+ <CapRadioGroup
2674
+ key={`${val.id}-radio-group`}
2675
+ className={`form-builder-radio-group ${ifError ? 'error' : ''}`}
2676
+ errorMessage={val.errorMessage && ifError ? val.errorMessage : ''}
2677
+ onChange={(e) => this.updateFormData(e.target.value, val)}
2678
+ style={val.style ? val.style : {}}
2679
+ value={this.handleSetRadioValue(this.state.formData, self.state.currentTab, val)}
2680
+ name={val.name ? val.name : `${val.id}-name`}
2681
+ disabled={val.disabled}
2682
+ >
2683
+ {val.options.map((option, index) => <CapRadio value={option} inductiveText={val.inductiveText && val.inductiveText[index]}>{option}</CapRadio>) }
2684
+
2685
+ </CapRadioGroup>
2686
+ {/*{ifError ?*/}
2687
+ {/*<div className="error"> {val.errorMessage}</div>*/}
2688
+ {/*:*/}
2689
+ {/*""*/}
2690
+ {/*}*/}
2691
+ </CapColumn>
2692
+ );
2693
+ }
2694
+ break;
2695
+ case 'image':
2696
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2697
+ columns.push(
2698
+ <CapColumn key={`input-${val.id}${self.state.currentTab - 1}`} style={val.style} span={val.width} offset={val.offset}>
2699
+ <div>
2700
+ <div className={`image-container ${ifError ? 'error' : ''}`}>
2701
+ {self.state && !!self.state.formData[`${self.state.currentTab - 1}`].image ?
2702
+ <img src={self.state.formData[`${self.state.currentTab - 1}`].image} alt={val.alt} style={val.style}/>
2703
+ :
2704
+ <div style={{width: "100%", textAlign: "center"}}><span className="image-placeholder">{val.placeholder}</span></div>
2705
+ }
2706
+ </div>
2707
+ {ifError && <span className="error">{val.errorMessage}</span>}
2708
+ </div>
2709
+ </CapColumn>
2710
+ );
2711
+ break;
2712
+ case 'upload':
2713
+ ifError = (this.state.checkValidation || this.props.startValidation) && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2714
+ const ImageComponent = (props) => (
2715
+ <div key={`${val.id}-${this.state.currentTab}`}>
2716
+ <div className={`image-container ${props.ifError ? 'error' : ''}`}>
2717
+ {self.state && !!self.state.formData[`${self.state.currentTab - 1}`].image ?
2718
+ <img src={self.state.formData[`${self.state.currentTab - 1}`].image} alt={props.alt} style={props.style}/>
2719
+ :
2720
+ <div style={{width: "100%", textAlign: "center"}}><span className="image-placeholder">{props.placeholder}</span></div>
2721
+ }
2722
+ </div>
2723
+ </div>
2724
+ );
2725
+ const WithLabel = LabelHOC(ImageComponent);
2726
+ const {errorMessage, ...rest} = val.previewProps || {};
2727
+ columns.push(
2728
+ <CapColumn span={val.width} offset={val.offset} style={val.style}>
2729
+ {val.showPreview && <WithLabel key={`${val.id}-with-label`} {...rest} errorMessage={ifError && errorMessage} ifError={ifError}/>}
2730
+ <form encType="multipart/form-data" id={val.id}>
2731
+ <input key={val.id} style={{ display: 'none'}} id="fileName" type="file" onChange={(e) => this.uploadImages(e, {files: e.target.files}, val)} accept={val.supportedExtensions ? val.supportedExtensions : "image/*"} />
2732
+ <CapButton disabled={val.disabled ? val.disabled : false} type="secondary" onClick={(e) => this.openFileDialog(e, val.id)} style={{float: 'right'}}>
2733
+ {val.label}
2734
+ </CapButton>
2735
+ </form>
2736
+ </CapColumn>
2737
+ );
2738
+ break;
2739
+
2740
+ case "table":
2741
+ columns.push(
2742
+ <CapTable dataSource={self.props.iosCtasData} loading={self.props.iosCtasData ? !self.props.iosCtasData.length : true} onRowClick={(row) => this.updateFormData(row, val, "onRowClick" )} pagination={val.pagination}>
2743
+ {_.map(val.columns, (col) => <Column {...col}/>)}
2744
+ </CapTable>
2745
+ );
2746
+ break;
2747
+ case "tag-list":
2748
+ columns.push(
2749
+ <CapColumn key={`input-${val.id}`} offset={val.offset} span={val.width ? val.width : ''} style={val.style ? val.style : {marginBottom: '16px'}}>
2750
+ <TagList
2751
+ key={`input-${val.id}`}
2752
+ moduleFilterEnabled={this.props.location && this.props.location.query && this.props.location.query.type !== 'embedded'}
2753
+ label={val.label ? val.label : ''}
2754
+ onTagSelect={(data) => this.callChildEvent(data, val, 'onTagSelect')}
2755
+ onContextChange={this.props.onContextChange}
2756
+ location={this.props.location}
2757
+ tags={this.props.tags ? this.props.tags : []}
2758
+ injectedTags={this.props.injectedTags ? this.props.injectedTags : {}}
2759
+ className={val.className ? val.className : ''}
2760
+ id={val.id}
2761
+ userLocale={this.props.userLocale}
2762
+ />
2763
+ </CapColumn>
2764
+ );
2765
+ break;
2766
+ case "button":
2767
+ if (styling === 'semantic' && val.metaType === 'submit-button') {
2768
+ columns.push(
2769
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width} offset={val.offset}>
2770
+ <CapButton
2771
+ type={val.buttonType}
2772
+ icon={val.icon}
2773
+ disabled={val.disabled ? val.disabled : false}
2774
+ onClick={(data) => this.callChildEvent(data, val, val.submitAction)}>
2775
+ {val.value}
2776
+ </CapButton>
2777
+ </CapColumn>
2778
+ );
2779
+ }
2780
+ break;
2781
+
2782
+ case "sms-preview": {
2783
+ let content = "";
2784
+ if (this.state.usingTabContainer && !this.state.formData[`${this.state.currentTab - 1}`]) {
2785
+ return true;
2786
+ }
2787
+ content = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`sms-editor${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData[val.id];
2788
+ const unicodeEnabled = isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`unicode-validity${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData['unicode-validity'];
2789
+ columns.push(
2790
+ <CapColumn key="input" span={23} offset={1}>
2791
+ <TemplatePreview
2792
+ key={val.id}
2793
+ style={val.customStyling ? val.customStyling : {}}
2794
+ channel={val.channel ? val.channel : 'SMS'}
2795
+ content={content}
2796
+ charCounterEnabled={val.charCounterEnabled}
2797
+ unicodeEnabled={unicodeEnabled}
2798
+ >
2799
+ </TemplatePreview>
2800
+ </CapColumn>
2801
+ );
2802
+ }
2803
+ break;
2804
+ case "line-preview": {
2805
+ const content = {
2806
+ bodyText: isVersionEnable ? this.state.formData[`${this.state.currentTab - 1}`][`message-editor${this.state.currentTab > 1 ? this.state.currentTab : ''}`] : this.state.formData[val.id],
2807
+ bodyImage: this.state.formData[`${this.state.currentTab - 1}`].imagePreview,
2808
+ };
2809
+ if (!this.state.formData[`${this.state.currentTab - 1}`]) {
2810
+ return true;
2811
+ }
2812
+
2813
+ columns.push(
2814
+ <CapColumn key="input" span={23} offset={1}>
2815
+ <TemplatePreview
2816
+ key={val.id}
2817
+ style={val.customStyling ? val.customStyling : {}}
2818
+ channel={val.channel}
2819
+ content={content}
2820
+ >
2821
+ </TemplatePreview>
2822
+ </CapColumn>
2823
+ );
2824
+ }
2825
+ break;
2826
+ case "mobile-push-preview":
2827
+ if (!this.state.formData[`${this.state.currentTab - 1}`]) {
2828
+ return true;
2829
+ }
2830
+ columns.push(
2831
+ <CapColumn key="input" span={23} offset={1}>
2832
+ <TemplatePreview
2833
+ key={val.id}
2834
+ device={val.device ? val.device : 'android'}
2835
+ style={val.customStyling ? val.customStyling : {}}
2836
+ channel={val.channel}
2837
+ content={{
2838
+ header: this.state.formData[`${this.state.currentTab - 1}`][val.content.title],
2839
+ bodyText: this.state.formData[`${this.state.currentTab - 1}`][val.content.message],
2840
+ bodyImage: this.state.formData[`${this.state.currentTab - 1}`].image,
2841
+ actions: [
2842
+ {label: this.state.formData[`${this.state.currentTab - 1}`][val.content.secondaryCta1]},
2843
+ {label: this.state.formData[`${this.state.currentTab - 1}`][val.content.secondaryCta2]},
2844
+ ],
2845
+ appName: val.content.appName,
2846
+ }}
2847
+ >
2848
+ </TemplatePreview>
2849
+ </CapColumn>
2850
+ );
2851
+ break;
2852
+ case "popover":
2853
+ contentSections = val.content.sections.map( (contentSection) => {
2854
+ const result = this.renderSection(contentSection, childIndex);
2855
+ return result;
2856
+ });
2857
+ popoverSections = val.value.sections.map( (popoverSection) => {
2858
+ const result = this.renderSection(popoverSection, childIndex);
2859
+ return result;
2860
+ });
2861
+ columns.push(
2862
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width} offset={val.offset}>
2863
+ <CapPopover
2864
+ trigger={val.trigger}
2865
+ placement={val.placement}
2866
+ visible={this.state.popoverVisible && (this.props.isNewVersionFlow || this.state.currentTab === childIndex || !childIndex)}
2867
+ onVisibleChange={this.handleVisibleChange}
2868
+ content={
2869
+ _.forEach(contentSections, (contentSection) => {
2870
+ if (contentSection) {
2871
+ return contentSection;
2872
+ }
2873
+ return contentSection;
2874
+ })
2875
+ }
2876
+ >
2877
+ {
2878
+ _.forEach(popoverSections, (popoverSection) => {
2879
+ if (popoverSection) {
2880
+ return popoverSection;
2881
+ }
2882
+ return popoverSection;
2883
+ })
2884
+ }
2885
+ </CapPopover>
2886
+ </CapColumn>
2887
+ );
2888
+ break;
2889
+
2890
+ case "icon":
2891
+ if (val.id === "base-version-icon") {
2892
+ const baseTab = this.findBaseTab();
2893
+ if ((baseTab + 1) !== childIndex) {
2894
+ return true;
2895
+ }
2896
+ }
2897
+ columns.push(
2898
+ <CapColumn
2899
+ key={`icon-${val.id}`}
2900
+ id={val.id}
2901
+ offset={val.offset}
2902
+ width={val.width ? val.width : 1}
2903
+ onClick={(data) => this.callChildEvent(data, val, val.submitAction)}
2904
+ className={val.className ? val.className : ''}
2905
+ style={val.colStyle ? val.colStyle : {}}
2906
+ >
2907
+ <i style={val.style ? val.style : {}} className="material-icons">{val.value ? val.value : '&#xE313;'}</i>
2908
+ </CapColumn>
2909
+ );
2910
+ break;
2911
+ case "select": {
2912
+ ifError = this.state.checkValidation && (isVersionEnable ? this.state.errorData[`${this.state.currentTab - 1}`][val.id] : this.state.errorData[val.id]);
2913
+ const options = (this.state.formData[`${val.id}-options`]) ? (this.state.formData[`${val.id}-options`]) : val.options;
2914
+ columns.push(
2915
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width} offset={val.offset}>
2916
+ <CapSelect
2917
+ id={val.id}
2918
+ options={options}
2919
+ placeholder={val.placeholder ? val.placeholder : ''}
2920
+ style={val.style ? val.style : {}}
2921
+ onSelect={(data) => this.updateFormData(data, val, 'onSelect')}
2922
+ value={isVersionEnable ? this.state.formData[this.state.currentTab - 1][val.id] : this.state.formData[val.id]}
2923
+ disabled={val.disabled}
2924
+ />
2925
+ {ifError && val.errorMessage &&
2926
+ <span className={'error'}>{val.errorMessage}</span>
2927
+ }
2928
+ </CapColumn>
2929
+ );
2930
+ }
2931
+ break;
2932
+ case "ckeditor": {
2933
+ if (this.props.schema && this.props.schema.channel && this.props.schema.channel.toLowerCase() === 'wechat' ) {
2934
+ const content = !_.isEmpty(this.state.formData) && this.state.formData['content-value'] ? this.state.formData['content-value'] : '';
2935
+ columns.push(
2936
+ <CKEditor
2937
+ id={val.id}
2938
+ content={content}
2939
+ events={val.events}
2940
+ getEditorInstanse={(evt, id) => val.injectedEvents.getEditorInstanse.call(this, evt, id)}
2941
+ handleContentChange={(event) => this.callChildEvent(event, val, 'onContentChange')}
2942
+ channel="wechat"
2943
+ onFocusOut={(event) => this.callChildEvent(event, val, 'onFocusOut')}
2944
+ onFocusIn={(event) => this.callChildEvent(event, val, 'onFocusIn')}
2945
+ /> );
2946
+ } else {
2947
+ if (_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`])) {
2948
+ return true;
2949
+ }
2950
+ let langIndex = 0;
2951
+ if (val.id.indexOf('template-content') > -1 && val.id !== 'template-content') {
2952
+ langIndex = parseInt(val.id.replace('template-content', ''), 10) - 1;
2953
+ }
2954
+ console.log('CKEditor Data 2', this.state.formData, this.state.formData[`${this.state.currentTab - 1}`], val, this.state.currentTab, this.state.currentLangTab, langIndex);
2955
+ const currentLang = (!_.isEmpty(this.state.formData) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`]) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages) && this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex]) ? this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex] : this.props.baseLanguage;
2956
+ const content = (!_.isEmpty(this.state.formData) && this.state.formData[`${this.state.currentTab - 1}`][currentLang]['template-content'] ? this.state.formData[`${this.state.currentTab - 1}`][currentLang]['template-content'] : '');
2957
+ console.log('ckeditor current lang', currentLang, content);
2958
+ if (this.state.formData[`${this.state.currentTab - 1}`][currentLang].is_drag_drop) {
2959
+ // content = "";
2960
+ }
2961
+ columns.push(
2962
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width}>
2963
+ <CKEditor
2964
+ id={val.id}
2965
+ content={content}
2966
+ events={val.events}
2967
+ getEditorInstanse={(evt, id) => val.injectedEvents.getEditorInstanse.call(this, evt, id)}
2968
+ handleContentChange={(event) => this.callChildEvent(event, val, 'onContentChange')}
2969
+ />
2970
+ </CapColumn>
2971
+ );
2972
+ }
2973
+ }
2974
+ break;
2975
+ case "edmeditor": {
2976
+ // if (!this.state.formData[`${this.state.currentTab - 1}`]) {
2977
+ // return true;
2978
+ // }
2979
+ let langTab = 1;
2980
+ if (val.id.match(/edmeditor/g)) {
2981
+ if (val.id.length > 9 && val.id.charAt(9)) {
2982
+ langTab = val.id.charAt(9);
2983
+ }
2984
+ }
2985
+ const supportedLanguages = this.state.formData[this.state.currentTab - 1].selectedLanguages;
2986
+ // let langIndex = 0;
2987
+ // if (val.id.indexOf('edmeditor') > -1 && val.id !== 'edmeditorsrc') {
2988
+ // const test = val.id.replace('src', '');
2989
+ // langIndex = parseInt(test.replace('edmeditor', ''), 10) - 1;
2990
+ // }
2991
+ // const currentLang = (!_.isEmpty(this.state.formData) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`]) && !_.isEmpty(this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages) && this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex]) ? this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages[langIndex] : this.props.baseLanguage;
2992
+ const currentLang = supportedLanguages[langTab - 1];
2993
+ const edmSrc = this.state.formData[`${this.state.currentTab - 1}`][currentLang] && this.state.formData[`${this.state.currentTab - 1}`][currentLang][`edmeditor${this.state.currentTab > 1 ? this.state.currentTab : ''}src`];
2994
+
2995
+
2996
+ if (!edmSrc) {
2997
+ return false;
2998
+ }
2999
+
3000
+
3001
+ columns.push(
3002
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width}>
3003
+ <EDMEditor
3004
+ id={val.id}
3005
+ getEditorInstanse={this.getEditorInstanse}
3006
+ edmSrc={edmSrc}
3007
+ />
3008
+ </CapColumn>
3009
+ );
3010
+ }
3011
+ break;
3012
+ case "customPopover": {
3013
+ if (!this.state.formData[`${this.state.currentTab - 1}`]) {
3014
+ return true;
3015
+ }
3016
+ columns.push(
3017
+ <CapColumn style={val.colStyle ? val.colStyle : {}} span={val.width}>
3018
+ <CustomPopOver
3019
+ id={val.id}
3020
+ popOverList={this.props.supportedLanguages}
3021
+ excludeList={this.state.formData[`${this.state.currentTab - 1}`].selectedLanguages}
3022
+ handlePopOverClick={(data) => this.handleAddLanguageFlow(data, val, "addLanguage")}
3023
+ visible={this.state.customPopoverVisible}
3024
+ onVisibleChange={this.handleCustomPopoverVisibleChange}
3025
+ />
3026
+ </CapColumn>
3027
+ );
3028
+ }
3029
+ break;
3030
+ default:
3031
+ break;
3032
+ }
3033
+ return true;
3034
+ });
3035
+ const row = (
3036
+ <CapRow style={field.rowStyle ? field.rowStyle : {}} className={field.rowClassName ? field.rowClassName : ''}>
3037
+ {
3038
+ _.forEach(columns, (value) => {
3039
+ if (value) {
3040
+ return value;
3041
+ }
3042
+ return value;
3043
+ })
3044
+ }
3045
+ </CapRow>
3046
+ );
3047
+ fields.push(row);
3048
+ });
3049
+
3050
+ _.forEach(section.actionFields, (field) => {
3051
+ const columns = [];
3052
+ _.forEach(field.cols, (val) => {
3053
+ const type = val.type;
3054
+ const styling = val.styling;
3055
+ switch (type) {
3056
+ case "button":
3057
+ if (styling === 'semantic' && val.metaType === 'submit-button') {
3058
+ columns.push(
3059
+ <CapColumn span={3}>
3060
+ <CapButton
3061
+ type={val.buttonType}
3062
+ icon={val.icon}
3063
+ disabled={val.disabled ? val.disabled : false}
3064
+ onClick={(data) => val.id === 'save-button' ? this.saveForm() : this.callChildEvent(data, val, val.submitAction)}>
3065
+ {val.value}
3066
+ </CapButton>
3067
+ </CapColumn>
3068
+ );
3069
+ }
3070
+ break;
3071
+ default:
3072
+ break;
3073
+ }
3074
+ });
3075
+ const row = (
3076
+ <CapRow>
3077
+ {
3078
+ _.forEach(columns, (value) => {
3079
+ if (value) {
3080
+ return value;
3081
+ }
3082
+ return value;
3083
+ })
3084
+ }
3085
+ </CapRow>
3086
+ );
3087
+ fields.push(row);
3088
+ });
3089
+ return fields;
3090
+ }
3091
+
3092
+ renderContainer(container) {
3093
+ const containerType = container.type;
3094
+ const renderedPanes = [];
3095
+ let renderedSections = [];
3096
+ let renderedContentSections = [];
3097
+ let paneIndex = 1;
3098
+ let panes = [];
3099
+ let result = [];
3100
+ let extraActionSections = [];
3101
+ let activeTabKey;
3102
+ let paneTabKey;
3103
+ let stateTabKey = '';
3104
+ switch (containerType) {
3105
+ case "tabs":
3106
+ panes = container.panes;
3107
+ _.forEach(panes, (pane, index) => {
3108
+ renderedSections = pane.sections.map((section) => {
3109
+ result = this.renderSection(section, paneIndex);
3110
+ return result;
3111
+ });
3112
+
3113
+ const sectionHeadeers = pane.sectionsHeaders ? pane.sectionsHeaders : container.tabContent && container.tabContent.sections;
3114
+ renderedContentSections = sectionHeadeers.map( (tabContentSection) => {
3115
+ result = this.renderSection(tabContentSection, paneIndex);
3116
+ return result;
3117
+ });
3118
+ // let newTabKey = `${_.uniqueId()}`;
3119
+ if (!this.state.formData[this.state.currentTab - 1]) {
3120
+ return;
3121
+ }
3122
+ activeTabKey = this.state.formData.tabKey;
3123
+ if (this.props.isNewVersionFlow) {
3124
+ activeTabKey = this.state.tabKey;
3125
+ }
3126
+ paneTabKey = this.state.formData[paneIndex - 1] && this.state.formData[paneIndex - 1].tabKey;
3127
+ if (this.props.isNewVersionFlow) {
3128
+ const currentLang = this.state.formData[this.state.currentTab - 1].selectedLanguages[index];
3129
+ paneTabKey = this.state.formData[this.state.currentTab - 1] && this.state.formData[this.state.currentTab - 1][currentLang] && this.state.formData[this.state.currentTab - 1][currentLang].tabKey;
3130
+ }
3131
+ const isPaneSupported = typeof pane.isSupported === "boolean" ? pane.isSupported : true; // pane.isSupported field exists only in mpush schema, in other channels it is not
3132
+ if (isPaneSupported) {
3133
+ renderedPanes.push(
3134
+ <TabPane
3135
+ forceRender
3136
+ tab={
3137
+ <div className="form-tab-header" onInput={(e) => e.stopPropagation()}>
3138
+ {
3139
+ _.forEach(renderedContentSections, (value) => {
3140
+ if (value) {
3141
+ return value;
3142
+ }
3143
+ return value;
3144
+ })
3145
+ }
3146
+ </div>
3147
+ }
3148
+ key={paneTabKey && paneTabKey !== '' ? `${paneTabKey}` : index}>
3149
+ {
3150
+ _.forEach(renderedSections, (value) => {
3151
+ if (value) {
3152
+ return value;
3153
+ }
3154
+ return value;
3155
+ })
3156
+ }
3157
+ </TabPane>);
3158
+ paneIndex += 1;
3159
+ }
3160
+ });
3161
+ extraActionSections = container.tabBarExtraContent && container.tabBarExtraContent.sections ? container.tabBarExtraContent.sections.map((section) => {
3162
+ result = this.renderSection(section);
3163
+ return result;
3164
+ }) : {};
3165
+ stateTabKey = this.state.tabKey;
3166
+ if (stateTabKey && stateTabKey !== '') {
3167
+ activeTabKey = stateTabKey;
3168
+ }
3169
+ return (
3170
+ <Tabs
3171
+ className={`cap-tabs-${container.id}`}
3172
+ activeKey={activeTabKey && activeTabKey !== '' ? `${activeTabKey}` : '1'}
3173
+ defaultActiveKey={activeTabKey && activeTabKey !== '' ? `${activeTabKey}` : '1'}
3174
+ onChange={(data, e) => { this.callChildEvent(data, container, 'onTabChange', e); }}
3175
+ onEdit={(data, e) => this.onEdit(data, e)}
3176
+ style={{width: '100%'}}
3177
+ tabBarExtraContent={
3178
+ !_.isEmpty(extraActionSections) && _.forEach(extraActionSections, (value) => {
3179
+ if (value) {
3180
+ return value;
3181
+ }
3182
+ return value;
3183
+ })
3184
+ }>
3185
+ {
3186
+ _.forEach(renderedPanes, (value) => {
3187
+ if (value) {
3188
+ return value;
3189
+ }
3190
+ return value;
3191
+ })
3192
+ }
3193
+ </Tabs>
3194
+ );
3195
+
3196
+ default:
3197
+ break;
3198
+ }
3199
+ return null;
3200
+ }
3201
+
3202
+ renderForm() {
3203
+ const schema = this.props.schema;
3204
+ const allElements = [];
3205
+ let renderedStandAloneSections;
3206
+ let renderedContainers;
3207
+ if (schema.standalone) {
3208
+ const sections = schema.standalone.sections;
3209
+ renderedStandAloneSections = sections.map((section) => {
3210
+ const result = this.renderSection(section);
3211
+ return result;
3212
+ });
3213
+ allElements.push(renderedStandAloneSections);
3214
+ }
3215
+ if (schema.containers) {
3216
+ renderedContainers = schema.containers.map((container) => {
3217
+ if (container.isActive === undefined || (container.isActive)) {
3218
+ const result = this.renderContainer(container);
3219
+ return result;
3220
+ }
3221
+ return null;
3222
+ });
3223
+
3224
+ allElements.push(renderedContainers);
3225
+ }
3226
+ const modal = this.getModal();
3227
+ allElements.push(modal);
3228
+ return allElements;
3229
+ }
3230
+
3231
+ render() {
3232
+ const cmsTemplateSelectionContent = (
3233
+ <CardGrid
3234
+ className={""}
3235
+ listItem={this.populateTemplatesList(this.props.cmsTemplates)}
3236
+ // filterContent={filterContent}
3237
+ onHoverItem={this.handleOnHoverItem}
3238
+ onItemClick={this.props.handleEdmDefaultTemplateSelection}
3239
+ colNumber={2}
3240
+ >
3241
+ </CardGrid>
3242
+ );
3243
+
3244
+
3245
+ return (
3246
+ <CapRow>
3247
+ {
3248
+ this.props.schema ? this.renderForm() : ''
3249
+ }
3250
+ <SlideBox
3251
+ header={(<h3>Layout Selection</h3>)}
3252
+ width={60}
3253
+ content={cmsTemplateSelectionContent}
3254
+ show={this.props.showEdmEmailTemplates}
3255
+ handleClose={this.props.toggleEdmEmailTemplateSelection}
3256
+ loadingText={"Loading EDM Templates"}
3257
+ isLoading={this.props.getCmsTemplatesInProgress}
3258
+ />
3259
+ </CapRow>
3260
+ );
3261
+ }
3262
+ }
3263
+
3264
+ FormBuilder.defaultProps = {
3265
+ isNewVersionFlow: false,
3266
+ userLocale: 'en',
3267
+ };
3268
+
3269
+ FormBuilder.propTypes = {
3270
+ schema: PropTypes.object.isRequired,
3271
+ onSubmit: PropTypes.func,
3272
+ formData: PropTypes.object,
3273
+ onChange: PropTypes.func,
3274
+ isEdit: PropTypes.bool,
3275
+ usingTabContainer: PropTypes.bool,
3276
+ parent: PropTypes.object,
3277
+ iframeParent: PropTypes.object,
3278
+ location: PropTypes.object,
3279
+ tags: PropTypes.array,
3280
+ injectedTags: PropTypes.object,
3281
+ onFormValidityChange: PropTypes.func,
3282
+ checkValidation: PropTypes.bool,
3283
+ onContextChange: PropTypes.func,
3284
+ tabCount: PropTypes.number,
3285
+ isSchemaChanged: PropTypes.bool,
3286
+ modal: PropTypes.object,
3287
+ isNewVersionFlow: PropTypes.bool,
3288
+ baseLanguage: PropTypes.string,
3289
+ supportedLanguages: PropTypes.array,
3290
+ router: PropTypes.object,
3291
+ currentTab: PropTypes.number,
3292
+ showModal: PropTypes.bool,
3293
+ handleCancelModal: PropTypes.func,
3294
+ cmsTemplates: PropTypes.array,
3295
+ getCmsTemplatesInProgress: PropTypes.bool,
3296
+ showEdmEmailTemplates: PropTypes.bool,
3297
+ toggleEdmEmailTemplateSelection: PropTypes.func,
3298
+ handleEdmDefaultTemplateSelection: PropTypes.func,
3299
+ userLocale: PropTypes.string,
3300
+ setModalContent: PropTypes.func,
3301
+ addLanguageType: PropTypes.string,
3302
+ getValidationData: PropTypes.func,
3303
+ startValidation: PropTypes.bool,
3304
+ // saveForm: PropTypes.bool,
3305
+ stopValidation: PropTypes.func,
3306
+ handleDelete: PropTypes.func,
3307
+ };
3308
+
3309
+ export default FormBuilder;