@capillarytech/creatives-library 0.0.6 → 0.0.8
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.
- package/components/FormBuilder/index.js +61 -7
- package/containers/Email/actions.js +2 -1
- package/containers/Email/index.js +178 -62
- package/containers/Email/reducer.js +4 -1
- package/containers/Email/sagas.js +5 -5
- package/containers/Sms/Edit/index.js +5 -5
- package/containers/Templates/index.js +7 -1
- package/package.json +1 -1
- package/routes.js +1 -1
- package/services/api.js +4 -4
- package/utils/smscharcount.js +320 -300
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import React, { PropTypes } from 'react';
|
|
9
9
|
import { Label } from 'semantic-ui-react';
|
|
10
10
|
import _ from 'lodash';
|
|
11
|
-
import { Tabs, Row, Col, Table, Modal} from 'antd';
|
|
11
|
+
import { Tabs, Row, Col, Table, Modal, notification} from 'antd';
|
|
12
12
|
import { CapButton, CapInput, CapPopover, CapTextArea, CapCheckbox, CapRadio, CapRadioGroup, CapSelect, CapTable} from '@capillarytech/cap-react-ui-library';
|
|
13
13
|
import TemplatePreview from '../../components/TemplatePreview';
|
|
14
14
|
// import { CapCheckbox } from '@capillarytech/cap-react-ui-library/basic/checkbox';
|
|
@@ -101,6 +101,19 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
101
101
|
if (this.state.usingTabContainer && nextProps.tabCount !== this.props.tabCount) {
|
|
102
102
|
this.setState({tabCount: nextProps.tabCount});
|
|
103
103
|
}
|
|
104
|
+
if (nextProps.startValidation && nextProps.startValidation !== false && this.props.startValidation !== nextProps.startValidation) {
|
|
105
|
+
this.setState({checkValidation: true});
|
|
106
|
+
const ifValid = this.validateForm(null, null, null, true);
|
|
107
|
+
console.log('validation final', ifValid);
|
|
108
|
+
if (ifValid) {
|
|
109
|
+
this.saveForm(true);
|
|
110
|
+
} else {
|
|
111
|
+
this.props.stopValidation();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// if (nextProps.saveForm && this.props.saveForm !== nextProps.saveForm) {
|
|
115
|
+
// this.saveForm(saveForm);
|
|
116
|
+
// }
|
|
104
117
|
if (nextProps.isEdit) {
|
|
105
118
|
console.log('Edit mode form data ', nextProps.formData, this.state.formData);
|
|
106
119
|
if (!_.isEqual(nextProps.formData, this.state.formData) && !_.isEmpty(nextProps.formData)) {
|
|
@@ -199,7 +212,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
199
212
|
console.log('outgoing have to reset tab keys');
|
|
200
213
|
this.resetTabKeys(nextProps.formData, nextProps.tabCount, false, true);
|
|
201
214
|
}
|
|
202
|
-
if (type === 'embedded') {
|
|
215
|
+
if (type === 'embedded' || this.props.schema.channel.toUpperCase() === 'EMAIL') {
|
|
203
216
|
this.validateForm();
|
|
204
217
|
}
|
|
205
218
|
if ((this.props.schema && this.props.schema.channel && this.props.schema.channel.toUpperCase() === 'MOBILEPUSH')) {
|
|
@@ -308,6 +321,15 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
308
321
|
return modal;
|
|
309
322
|
};
|
|
310
323
|
|
|
324
|
+
openNotificationWithIcon = (type, message) => {
|
|
325
|
+
const dur = (type === 'error' || type === 'warning') ? null : 5;
|
|
326
|
+
notification[type]({
|
|
327
|
+
message: (`${type.toUpperCase()} ! ! ! `),
|
|
328
|
+
description: message, //'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
|
|
329
|
+
duration: dur,
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
311
333
|
handleCloseModal = (data, e) => {
|
|
312
334
|
console.log('handle close modal', data, e);
|
|
313
335
|
const event = this.state.currentEvent;
|
|
@@ -421,7 +443,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
421
443
|
}
|
|
422
444
|
|
|
423
445
|
/* eslint-disable */
|
|
424
|
-
validateForm(tags, injectedTags, isSave) {
|
|
446
|
+
validateForm(tags, injectedTags, isSave, showMessages) {
|
|
425
447
|
console.log('validating form', this.state.formData);
|
|
426
448
|
let isValid = true;
|
|
427
449
|
const type = (this.props.location && this.props.location.query.type) ? this.props.location.query.type : 'full';
|
|
@@ -737,6 +759,13 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
737
759
|
if (!androidValid || !iosValid) {
|
|
738
760
|
this.setState({androidValid, iosValid});
|
|
739
761
|
}
|
|
762
|
+
if (isOnlyAndroid && androidValid) {
|
|
763
|
+
isValid = true;
|
|
764
|
+
} else if (isOnlyIos && iosValid) {
|
|
765
|
+
isValid = true;
|
|
766
|
+
} else if (!isOnlyIos && !isOnlyAndroid && androidValid && iosValid) {
|
|
767
|
+
isValid = true;
|
|
768
|
+
}
|
|
740
769
|
}
|
|
741
770
|
|
|
742
771
|
// Form Data Validation for Email Channel
|
|
@@ -744,12 +773,12 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
744
773
|
// Validating Email By iterating all elements of FormBuilder
|
|
745
774
|
_.forEach(this.state.formData, (data, index) => {
|
|
746
775
|
console.log("Form Iteration Data ", data, index);
|
|
747
|
-
if (!this.state.formData["template-subject"]) {
|
|
776
|
+
if (!this.state.formData["template-subject"] && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline' || currentModule.toLowerCase() === 'library')) {
|
|
748
777
|
errorData["template-subject"] = true;
|
|
749
778
|
isValid = false;
|
|
750
779
|
}
|
|
751
780
|
// Check if template subject present in form data from Loyalty, DVS, Timeline
|
|
752
|
-
if (index === 'template-subject' && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline')) {
|
|
781
|
+
if (index === 'template-subject' && type.toLowerCase() === 'embedded' && (currentModule.toLowerCase() === 'loyalty' || currentModule.toLowerCase() === 'dvs' || currentModule.toLowerCase() === 'timeline' || currentModule.toLowerCase() === 'library')) {
|
|
753
782
|
if (data.trim() === '') {
|
|
754
783
|
errorData[index] = true;
|
|
755
784
|
isValid = false;
|
|
@@ -779,6 +808,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
779
808
|
if (errorData[index] === undefined) {
|
|
780
809
|
errorData[index] = {};
|
|
781
810
|
}
|
|
811
|
+
let errorString = "";
|
|
782
812
|
for (var i = 0; i < data.selectedLanguages.length; i+= 1) {
|
|
783
813
|
const currentLang = data.selectedLanguages[i];
|
|
784
814
|
const content = data[currentLang]['template-content'];
|
|
@@ -792,8 +822,22 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
792
822
|
} else {
|
|
793
823
|
errorData[index][currentLang]['template-content'] = true;
|
|
794
824
|
isValid = false;
|
|
825
|
+
if (showMessages && !isNaN(index)) {
|
|
826
|
+
if (tagValidationResponse.missingTags.length > 0 || tagValidationResponse.unsupportedTags.length > 0) {
|
|
827
|
+
errorString += `Content is not valid for language: ${currentLang}\n`;
|
|
828
|
+
}
|
|
829
|
+
if (tagValidationResponse.missingTags.length > 0) {
|
|
830
|
+
errorString += `Missing tags are: ${tagValidationResponse.missingTags.toString()}\n`;
|
|
831
|
+
}
|
|
832
|
+
if (tagValidationResponse.unsupportedTags.length > 0) {
|
|
833
|
+
errorString += `Unsupported tags are: ${tagValidationResponse.unsupportedTags.toString()}\n`;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
795
836
|
}
|
|
796
837
|
}
|
|
838
|
+
if (errorString !== "") {
|
|
839
|
+
this.openNotificationWithIcon('error', errorString);
|
|
840
|
+
}
|
|
797
841
|
_.forEach(errorData[index], (versionData, key) => {
|
|
798
842
|
if (data.selectedLanguages.indexOf(key) === -1) {
|
|
799
843
|
delete errorData[index][key];
|
|
@@ -829,6 +873,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
829
873
|
this.setState({isFormValid : isValid, errorData});
|
|
830
874
|
console.log('final validity', this.state.formData, this.state, isValid);
|
|
831
875
|
this.props.onFormValidityChange(isValid);
|
|
876
|
+
return isValid;
|
|
832
877
|
}
|
|
833
878
|
|
|
834
879
|
indexOfEnd(targetString, string) {
|
|
@@ -838,8 +883,12 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
838
883
|
continueSaveForm = (id) => {
|
|
839
884
|
|
|
840
885
|
};
|
|
841
|
-
saveForm() {
|
|
842
|
-
console.log('Is Form Valid ', this.state.isFormValid);
|
|
886
|
+
saveForm(saveForm) {
|
|
887
|
+
console.log('Is Form Valid ', this.state.isFormValid, saveForm);
|
|
888
|
+
if (this.props.isNewVersionFlow && !saveForm) {
|
|
889
|
+
this.props.getValidationData();
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
843
892
|
if (this.state.isFormValid) {
|
|
844
893
|
this.props.onSubmit(this.state.formData);
|
|
845
894
|
} else {
|
|
@@ -1891,6 +1940,7 @@ class FormBuilder extends React.Component { // eslint-disable-line react/prefer-
|
|
|
1891
1940
|
}
|
|
1892
1941
|
} else if (event === "onContentChange") {
|
|
1893
1942
|
val.injectedEvents[event].call(this.props.parent, data, val.id);
|
|
1943
|
+
return;
|
|
1894
1944
|
} else if (event === 'deleteLanguage') {
|
|
1895
1945
|
this.setState({currentEvent: val.injectedEvents[event], currentEventData: data }, () => {
|
|
1896
1946
|
this.props.setModalContent('delete-language');
|
|
@@ -3133,6 +3183,10 @@ FormBuilder.propTypes = {
|
|
|
3133
3183
|
userLocale: PropTypes.string,
|
|
3134
3184
|
setModalContent: PropTypes.func,
|
|
3135
3185
|
addLanguageType: PropTypes.string,
|
|
3186
|
+
getValidationData: PropTypes.func,
|
|
3187
|
+
startValidation: PropTypes.bool,
|
|
3188
|
+
// saveForm: PropTypes.bool,
|
|
3189
|
+
stopValidation: PropTypes.func,
|
|
3136
3190
|
};
|
|
3137
3191
|
|
|
3138
3192
|
export default FormBuilder;
|
|
@@ -41,11 +41,12 @@ export function getCmsSetting(cmsType, projectId, cmsMode, langId) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
export function getCmsData(cmsType, projectId) {
|
|
44
|
+
export function getCmsData(cmsType, projectId, langId) {
|
|
45
45
|
return {
|
|
46
46
|
type: types.GET_CMS_EDITOR_DATA_REQUEST,
|
|
47
47
|
cmsType,
|
|
48
48
|
projectId,
|
|
49
|
+
langId,
|
|
49
50
|
};
|
|
50
51
|
}
|
|
51
52
|
|
|
@@ -587,6 +587,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
587
587
|
isFormValid: true,
|
|
588
588
|
injectedTags: {},
|
|
589
589
|
checkValidation: false,
|
|
590
|
+
saveEdmDataMode: 'save',
|
|
590
591
|
tabKey: '',
|
|
591
592
|
showEmailPreview: false,
|
|
592
593
|
device: "desktop",
|
|
@@ -601,12 +602,15 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
601
602
|
totalCount: 0,
|
|
602
603
|
searchText: '',
|
|
603
604
|
saveCount: 0,
|
|
605
|
+
cmsDataCount: 0,
|
|
604
606
|
targetSaveCount: 0,
|
|
605
607
|
saveObj: {},
|
|
606
608
|
showEdmEmailTemplates: false,
|
|
607
609
|
editDataSet: false,
|
|
608
610
|
languageDataSet: false,
|
|
609
611
|
addLanguageType: '',
|
|
612
|
+
startValidation: false,
|
|
613
|
+
saveForm: false,
|
|
610
614
|
};
|
|
611
615
|
|
|
612
616
|
this.isTagLoaded = false;
|
|
@@ -757,19 +761,21 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
757
761
|
const newSchema = this.injectEvents(nextProps.metaEntities.layouts[0].definition);
|
|
758
762
|
console.log('Schema test 1 ', newSchema);
|
|
759
763
|
this.setState({schema: newSchema});
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
764
|
+
if (this.props.location.query.module !== 'library') {
|
|
765
|
+
const query = {
|
|
766
|
+
layout: 'EMAIL',
|
|
767
|
+
type: 'TAG',
|
|
768
|
+
context: this.props.location.query.type === 'embedded' ? this.props.location.query.module : 'default',
|
|
769
|
+
embedded: this.props.location.query.type === 'embedded' ? this.props.location.query.type : 'full',
|
|
770
|
+
};
|
|
771
|
+
this.props.globalActions.fetchSchemaForEntity(query);
|
|
772
|
+
}
|
|
766
773
|
setTimeout(() => {
|
|
767
774
|
this.showSubject();
|
|
768
775
|
}, 0);
|
|
769
|
-
this.props.globalActions.fetchSchemaForEntity(query);
|
|
770
776
|
}
|
|
771
777
|
if (nextProps.location.query.module === 'library' && nextProps.isGetFormData) {
|
|
772
|
-
|
|
778
|
+
this.getFormData();
|
|
773
779
|
}
|
|
774
780
|
if (nextProps.Global.currentOrgDetails && nextProps.Global.currentOrgDetails.basic_details && !_.isEmpty(nextProps.Global.currentOrgDetails.basic_details) && _.isEmpty(this.state.formData)) {
|
|
775
781
|
const formData = this.initFormData(nextProps);
|
|
@@ -790,7 +796,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
790
796
|
//const that = this;
|
|
791
797
|
this.setState({formData}, () => {
|
|
792
798
|
// setTimeout(() => {
|
|
793
|
-
//
|
|
799
|
+
// this.getFormData();
|
|
794
800
|
// that.startTemplateCreation();
|
|
795
801
|
// }, 15000);
|
|
796
802
|
});
|
|
@@ -939,7 +945,14 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
939
945
|
}
|
|
940
946
|
if (!nextProps.Email.fetchingCmsData && !_.isEqual(nextProps.Email.cmsData, this.props.Email.cmsData)) {
|
|
941
947
|
const formData = _.cloneDeep(this.state.formData);
|
|
942
|
-
if (
|
|
948
|
+
if (nextProps.Email.langId) {
|
|
949
|
+
console.log('setting template content', nextProps.Email.cmsData, decodeURIComponent(nextProps.Email.cmsData));
|
|
950
|
+
const langId = nextProps.Email.langId;
|
|
951
|
+
formData[`${this.state.currentTab - 1}`][langId]['template-content'] = decodeURIComponent(nextProps.Email.cmsData);
|
|
952
|
+
if (formData[`${this.state.currentTab - 1}`].base) {
|
|
953
|
+
formData.base[langId]['template-content'] = decodeURIComponent(nextProps.Email.cmsData);
|
|
954
|
+
}
|
|
955
|
+
} else if (this.state.gettingPreviewData) {
|
|
943
956
|
this.setState({gettingPreviewData: false});
|
|
944
957
|
formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab]['template-content'] = decodeURIComponent(nextProps.Email.cmsData);
|
|
945
958
|
if (formData[`${this.state.currentTab - 1}`].base) {
|
|
@@ -972,8 +985,12 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
972
985
|
}
|
|
973
986
|
console.log('ckeditor trying to set ckeditor data');
|
|
974
987
|
}
|
|
975
|
-
|
|
976
|
-
this.setState({ formData })
|
|
988
|
+
console.log('setting template content final', formData);
|
|
989
|
+
this.setState({ formData }, () => {
|
|
990
|
+
if (nextProps.Email.langId) {
|
|
991
|
+
this.shouldStartValidation();
|
|
992
|
+
}
|
|
993
|
+
});
|
|
977
994
|
}
|
|
978
995
|
|
|
979
996
|
if (nextProps.metaEntities && nextProps.metaEntities.tags && nextProps.metaEntities.tags.custom && !_.isEqual(this.props.metaEntities.tags, nextProps.metaEntities.tags)) {
|
|
@@ -1064,19 +1081,19 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
1064
1081
|
onChange = (evt, id) => {
|
|
1065
1082
|
const formData = _.cloneDeep(this.state.formData);
|
|
1066
1083
|
console.log('oncontentchange onChange ', evt, evt.editor.getData());
|
|
1067
|
-
if (evt.editor.name.indexOf('editor') === -1) {
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
}
|
|
1084
|
+
//if (evt.editor.name.indexOf('editor') === -1) {
|
|
1085
|
+
_.forEach(window.CKEDITOR.instances, (winInstance) => {
|
|
1086
|
+
const temp = winInstance;
|
|
1087
|
+
if (winInstance.name === evt.editor.name) {
|
|
1088
|
+
console.log('setting instance name after loading', winInstance, name);
|
|
1089
|
+
// setTimeout(() => {
|
|
1090
|
+
// //temp.name = id;
|
|
1091
|
+
// }, 1000);
|
|
1092
|
+
temp.name = id;
|
|
1093
|
+
console.log('setting instance name after loading 2', winInstance, name);
|
|
1094
|
+
}
|
|
1095
|
+
});
|
|
1096
|
+
//}
|
|
1080
1097
|
if (!formData[this.state.currentTab - 1][formData[`${this.state.currentTab - 1}`].activeTab].is_drag_drop) {
|
|
1081
1098
|
formData[`${this.state.currentTab - 1}`][formData[`${this.state.currentTab - 1}`].activeTab][`template-content`] = _.cloneDeep(evt.editor.getData());
|
|
1082
1099
|
if (formData[`${this.state.currentTab - 1}`].tabKey === formData.base.tabKey) {
|
|
@@ -1149,6 +1166,22 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
1149
1166
|
});
|
|
1150
1167
|
}
|
|
1151
1168
|
|
|
1169
|
+
getValidationData = () => {
|
|
1170
|
+
console.log('all data save getting validation data');
|
|
1171
|
+
const that = this;
|
|
1172
|
+
const formData = _.cloneDeep(this.state.formData);
|
|
1173
|
+
_.forEach(formData, (val, index) => {
|
|
1174
|
+
if (!isNaN(index)) {
|
|
1175
|
+
_.forEach(val.selectedLanguages, (language) => {
|
|
1176
|
+
console.log('all data save language', language, val[language]);
|
|
1177
|
+
if (val[language].is_drag_drop) {
|
|
1178
|
+
that.props.actions.getCmsData('edm', val[language].drag_drop_id, language);
|
|
1179
|
+
}
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
}
|
|
1184
|
+
|
|
1152
1185
|
setNewLanguageContent = (data) => {
|
|
1153
1186
|
const content = _.cloneDeep(data);
|
|
1154
1187
|
const formData = _.cloneDeep(this.state.formData);
|
|
@@ -1184,19 +1217,22 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
1184
1217
|
}
|
|
1185
1218
|
|
|
1186
1219
|
getFormData = (e, value) => {
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
this.
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1220
|
+
this.setState({getFormDataValue: value, gettingFormData: true}, () => {
|
|
1221
|
+
this.saveValidationData();
|
|
1222
|
+
});
|
|
1223
|
+
// console.log('posting final result', this.state.formData);
|
|
1224
|
+
// const response = {
|
|
1225
|
+
// action: "getFormData",
|
|
1226
|
+
// postAction: value || 'next',
|
|
1227
|
+
// value: this.transformFormData(this.state.formData),
|
|
1228
|
+
// validity: this.state.isFormValid,
|
|
1229
|
+
// };
|
|
1230
|
+
// console.log('Get Data', response);
|
|
1231
|
+
// this.setState({checkValidation: true});
|
|
1232
|
+
// if (e) {
|
|
1233
|
+
// e.source.postMessage(JSON.stringify(response), e.origin);
|
|
1234
|
+
// }
|
|
1235
|
+
// return response;
|
|
1200
1236
|
}
|
|
1201
1237
|
|
|
1202
1238
|
setFormValidity = (isFormValid) => {
|
|
@@ -1415,6 +1451,49 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
1415
1451
|
this.setState({ modalContent, showModal: true});
|
|
1416
1452
|
};
|
|
1417
1453
|
|
|
1454
|
+
shouldStartValidation = () => {
|
|
1455
|
+
this.setState((prevState) => ({ cmsDataCount: prevState.cmsDataCount + 1}), () => {
|
|
1456
|
+
console.log('all data save count validating', this.state.saveCount, this.state.cmsDataCount);
|
|
1457
|
+
if (this.state.targetSaveCount === this.state.cmsDataCount) {
|
|
1458
|
+
console.log('validation final starting edm validation');
|
|
1459
|
+
this.setState({startValidation: true});
|
|
1460
|
+
}
|
|
1461
|
+
});
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
stopValidation = () => {
|
|
1465
|
+
this.setState({startValidation: false});
|
|
1466
|
+
}
|
|
1467
|
+
saveValidationData = () => {
|
|
1468
|
+
let saveCount = 0;
|
|
1469
|
+
this.setState({saveEdmDataMode: 'validation', saveCount: 0, cmsDataCount: 0}, () => {
|
|
1470
|
+
_.forEach(this.state.formData, (newdata, index) => {
|
|
1471
|
+
if (!isNaN(index)) {
|
|
1472
|
+
_.forEach(newdata.selectedLanguages, (language) => {
|
|
1473
|
+
if (newdata[language].is_drag_drop && ((parseInt(index, 10) + 1) === this.state.currentTab)) {
|
|
1474
|
+
console.log('all data 4');
|
|
1475
|
+
saveCount += 1;
|
|
1476
|
+
}
|
|
1477
|
+
});
|
|
1478
|
+
}
|
|
1479
|
+
});
|
|
1480
|
+
if (saveCount === 0) {
|
|
1481
|
+
this.setState({startValidation: true});
|
|
1482
|
+
return;
|
|
1483
|
+
}
|
|
1484
|
+
this.setState({targetSaveCount: saveCount, mode: "save", saveCount: 0, cmsDataCount: 0}, () => {
|
|
1485
|
+
const data = this.state.formData[this.state.currentTab - 1];
|
|
1486
|
+
_.forEach(data.selectedLanguages, (language, langIndex) => {
|
|
1487
|
+
if (data[language].is_drag_drop) {
|
|
1488
|
+
console.log('saving edm template', document.getElementById("edmeditor"), `edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`);
|
|
1489
|
+
const win = document.getElementById(`edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`).contentWindow;
|
|
1490
|
+
win.postMessage("saveProject", '*');
|
|
1491
|
+
}
|
|
1492
|
+
});
|
|
1493
|
+
});
|
|
1494
|
+
});
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1418
1497
|
resetStateValue = () => {
|
|
1419
1498
|
this.setState({
|
|
1420
1499
|
formData: {},
|
|
@@ -1805,7 +1884,11 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
1805
1884
|
this.setState((prevState) => ({ saveCount: prevState.saveCount + 1}), () => {
|
|
1806
1885
|
console.log('all data save count', this.state.saveCount);
|
|
1807
1886
|
if (this.state.targetSaveCount === this.state.saveCount) {
|
|
1808
|
-
|
|
1887
|
+
if (this.state.saveEdmDataMode === 'validation') {
|
|
1888
|
+
this.getValidationData();
|
|
1889
|
+
} else if (this.state.saveEdmDataMode === 'save') {
|
|
1890
|
+
this.props.actions.createTemplate(this.state.saveObj);
|
|
1891
|
+
}
|
|
1809
1892
|
}
|
|
1810
1893
|
});
|
|
1811
1894
|
} else if (this.state.mode === 'preview' || this.state.mode === 'switchEditor') {
|
|
@@ -2417,7 +2500,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2417
2500
|
this.removeStandAlone();
|
|
2418
2501
|
}
|
|
2419
2502
|
if (type === 'embedded' && (this.props.route.name === 'EmailView' || (this.props.location.query.module && (this.props.location.query.module.toLowerCase() === 'loyalty' || this.props.location.query.module.toLowerCase() === 'dvs' || this.props.location.query.module.toLowerCase() === 'timeline')))) {
|
|
2420
|
-
if (this.props.route.name === "EmailEdit" && this.props.location.query.module === "dvs") {
|
|
2503
|
+
if ((this.props.route.name === "EmailEdit" || this.props.route.name === "EmailCreate") && this.props.location.query.module === "dvs") {
|
|
2421
2504
|
return;
|
|
2422
2505
|
}
|
|
2423
2506
|
const response = {
|
|
@@ -2757,6 +2840,28 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2757
2840
|
// if (!isValidated) {
|
|
2758
2841
|
// return;
|
|
2759
2842
|
// }
|
|
2843
|
+
//if (!this.state.startValidation) {
|
|
2844
|
+
// this.saveValidationData();
|
|
2845
|
+
// return;
|
|
2846
|
+
//}
|
|
2847
|
+
console.log('save form data', passedData, this.state.gettingFormData, this.state.startValidation, this.state);
|
|
2848
|
+
if (this.state.gettingFormData) {
|
|
2849
|
+
console.log('posting final result', passedData);
|
|
2850
|
+
const response = {
|
|
2851
|
+
action: "getFormData",
|
|
2852
|
+
postAction: this.state.getFormDataValue || 'next',
|
|
2853
|
+
value: this.transformFormData(passedData),
|
|
2854
|
+
validity: this.state.isFormValid,
|
|
2855
|
+
};
|
|
2856
|
+
console.log('Get Data', response);
|
|
2857
|
+
this.setState({checkValidation: true});
|
|
2858
|
+
if (this.props.location.query.module === 'library' && this.props.isGetFormData) {
|
|
2859
|
+
this.props.getFormSubscriptionData(response);
|
|
2860
|
+
}
|
|
2861
|
+
parent.postMessage(JSON.stringify(response), "*");
|
|
2862
|
+
this.setState({gettingFormData: false, startValidation: false});
|
|
2863
|
+
return;
|
|
2864
|
+
}
|
|
2760
2865
|
const formData = _.cloneDeep(passedData);
|
|
2761
2866
|
console.log('Saving form data', JSON.stringify(formData), this.state.tabCount);
|
|
2762
2867
|
const obj = {};
|
|
@@ -2770,7 +2875,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2770
2875
|
obj.type = 'EMAIL';
|
|
2771
2876
|
const baseLanguage = this.props.Global.currentOrgDetails.basic_details.base_language;
|
|
2772
2877
|
let baseKey = -1;
|
|
2773
|
-
let saveCount = 0;
|
|
2878
|
+
//let saveCount = 0;
|
|
2774
2879
|
console.log('all data', this.state.currentTab);
|
|
2775
2880
|
_.forEach(formData, (data, index) => {
|
|
2776
2881
|
const newdata = data;
|
|
@@ -2783,11 +2888,11 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2783
2888
|
baseKey = baseLangTabKey;
|
|
2784
2889
|
}
|
|
2785
2890
|
_.forEach(newdata.selectedLanguages, (language) => {
|
|
2786
|
-
console.log('all data 3', newdata[language], language, this.state.currentTab, index, (index + 1), (index + 1) === this.state.currentTab, newdata[language].is_drag_drop);
|
|
2787
|
-
if (newdata[language].is_drag_drop && ((parseInt(index, 10) + 1) === this.state.currentTab)) {
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
}
|
|
2891
|
+
// console.log('all data 3', newdata[language], language, this.state.currentTab, index, (index + 1), (index + 1) === this.state.currentTab, newdata[language].is_drag_drop);
|
|
2892
|
+
// if (newdata[language].is_drag_drop && ((parseInt(index, 10) + 1) === this.state.currentTab)) {
|
|
2893
|
+
// console.log('all data 4');
|
|
2894
|
+
// saveCount += 1;
|
|
2895
|
+
// }
|
|
2791
2896
|
if (newdata[language].is_drag_drop) {
|
|
2792
2897
|
delete newdata[language].edmeditorsrc;
|
|
2793
2898
|
}
|
|
@@ -2795,7 +2900,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2795
2900
|
obj.versions.history.push(newdata);
|
|
2796
2901
|
}
|
|
2797
2902
|
});
|
|
2798
|
-
const data = formData[`${this.state.currentTab - 1}`];
|
|
2903
|
+
//const data = formData[`${this.state.currentTab - 1}`];
|
|
2799
2904
|
obj.name = formData['template-name'];
|
|
2800
2905
|
obj.versions.base = formData.base;
|
|
2801
2906
|
obj.versions.base.tabKey = baseKey;
|
|
@@ -2806,20 +2911,20 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2806
2911
|
}
|
|
2807
2912
|
});
|
|
2808
2913
|
console.log('obj', obj);
|
|
2809
|
-
if (saveCount === 0) {
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
} else {
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
}
|
|
2914
|
+
// if (saveCount === 0) {
|
|
2915
|
+
console.log('final save obj', obj);
|
|
2916
|
+
this.props.actions.createTemplate(obj);
|
|
2917
|
+
// } else {
|
|
2918
|
+
// this.setState({saveObj: obj, targetSaveCount: saveCount, mode: "save", saveEdmDataMode: 'save'}, () => {
|
|
2919
|
+
// _.forEach(data.selectedLanguages, (language, langIndex) => {
|
|
2920
|
+
// if (data[language].is_drag_drop) {
|
|
2921
|
+
// console.log('saving edm template', document.getElementById("edmeditor"), `edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`);
|
|
2922
|
+
// const win = document.getElementById(`edmeditor${(langIndex + 1) > 1 ? (langIndex + 1) : ''}`).contentWindow;
|
|
2923
|
+
// win.postMessage("saveProject", '*');
|
|
2924
|
+
// }
|
|
2925
|
+
// });
|
|
2926
|
+
// });
|
|
2927
|
+
// }
|
|
2823
2928
|
}
|
|
2824
2929
|
|
|
2825
2930
|
handleOk = () => {
|
|
@@ -2973,6 +3078,10 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
2973
3078
|
if (this.props.Email.assetUploading) {
|
|
2974
3079
|
loaderText = this.props.intl.formatMessage(messages.uploadingImage);
|
|
2975
3080
|
}
|
|
3081
|
+
let tags = this.props.metaEntities && this.props.metaEntities.tags ? this.props.metaEntities.tags.standard : [];
|
|
3082
|
+
if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'library') {
|
|
3083
|
+
tags = this.props.supportedTags;
|
|
3084
|
+
}
|
|
2976
3085
|
return (
|
|
2977
3086
|
<div className="email-container">
|
|
2978
3087
|
<Helmet
|
|
@@ -3018,7 +3127,7 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
3018
3127
|
formData={_.cloneDeep(this.state.formData)}
|
|
3019
3128
|
location={this.props.location}
|
|
3020
3129
|
tabKey={this.state.tabKey}
|
|
3021
|
-
tags={
|
|
3130
|
+
tags={tags}
|
|
3022
3131
|
injectedTags={this.state.injectedTags ? this.state.injectedTags : {}}
|
|
3023
3132
|
onFormValidityChange={this.setFormValidity}
|
|
3024
3133
|
handleCancelModal={this.handleCancelModal}
|
|
@@ -3042,6 +3151,10 @@ export class Email extends React.Component { // eslint-disable-line react/prefer
|
|
|
3042
3151
|
handleEdmDefaultTemplateSelection={this.handleEdmDefaultTemplateSelection}
|
|
3043
3152
|
setModalContent={this.setModalContent}
|
|
3044
3153
|
addLanguageType={this.state.addLanguageType}
|
|
3154
|
+
startValidation={this.state.startValidation}
|
|
3155
|
+
getValidationData={this.saveValidationData}
|
|
3156
|
+
saveForm={this.state.saveForm}
|
|
3157
|
+
stopValidation={this.stopValidation}
|
|
3045
3158
|
/> : ''}
|
|
3046
3159
|
</Col>
|
|
3047
3160
|
</Row>
|
|
@@ -3081,6 +3194,9 @@ Email.propTypes = {
|
|
|
3081
3194
|
templatesActions: PropTypes.object,
|
|
3082
3195
|
route: PropTypes.object,
|
|
3083
3196
|
templateData: PropTypes.object,
|
|
3197
|
+
isGetFormData: PropTypes.bool,
|
|
3198
|
+
getFormSubscriptionData: PropTypes.func,
|
|
3199
|
+
supportedTags: PropTypes.array,
|
|
3084
3200
|
};
|
|
3085
3201
|
|
|
3086
3202
|
const mapStateToProps = createStructuredSelector({
|
|
@@ -14,6 +14,7 @@ const initialState = fromJS({
|
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
function emailReducer(state = initialState, action) {
|
|
17
|
+
console.log('email reducer', action);
|
|
17
18
|
switch (action.type) {
|
|
18
19
|
case types.CREATE_TEMPLATE_REQUEST:
|
|
19
20
|
return state
|
|
@@ -76,11 +77,13 @@ function emailReducer(state = initialState, action) {
|
|
|
76
77
|
return state
|
|
77
78
|
.set('fetchingCmsData', true)
|
|
78
79
|
.set('cmsData', '')
|
|
80
|
+
.set('langId', undefined)
|
|
79
81
|
.set('fetchingCmsDataFailed', false);
|
|
80
82
|
case types.GET_CMS_EDITOR_DATA_SUCCESS:
|
|
81
83
|
return state
|
|
82
84
|
.set('fetchingCmsData', false)
|
|
83
|
-
.set('cmsData', action.data)
|
|
85
|
+
.set('cmsData', action.data)
|
|
86
|
+
.set('langId', action.langId);
|
|
84
87
|
case types.GET_CMS_EDITOR_DATA_FAILURE:
|
|
85
88
|
return state
|
|
86
89
|
.set('fetchingCmsData', false)
|
|
@@ -49,11 +49,11 @@ export function* getCmsSetting({cmsType, projectId, cmsMode, langId}) {
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export function* getCmsData({cmsType, projectId}) {
|
|
52
|
+
export function* getCmsData({cmsType, projectId, langId}) {
|
|
53
53
|
try {
|
|
54
|
-
const result = yield call(Api.getCmsTemplateData, cmsType, projectId);
|
|
55
|
-
console.log('CMS Data ', result);
|
|
56
|
-
yield put({ type: types.GET_CMS_EDITOR_DATA_SUCCESS, data: result.data.response.data });
|
|
54
|
+
const result = yield call(Api.getCmsTemplateData, cmsType, projectId, langId);
|
|
55
|
+
console.log('CMS Data sagas', result);
|
|
56
|
+
yield put({ type: types.GET_CMS_EDITOR_DATA_SUCCESS, data: result.data.response.data, langId: result.data.response.langId });
|
|
57
57
|
} catch (error) {
|
|
58
58
|
yield put({ type: types.GET_CMS_EDITOR_DATA_FAILURE, error });
|
|
59
59
|
}
|
|
@@ -93,7 +93,7 @@ function* watchGetCmsSetting() {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
function* watchGetCmsData() {
|
|
96
|
-
const watcher = yield
|
|
96
|
+
const watcher = yield takeEvery(types.GET_CMS_EDITOR_DATA_REQUEST, getCmsData);
|
|
97
97
|
yield take(LOCATION_CHANGE);
|
|
98
98
|
yield cancel(watcher);
|
|
99
99
|
}
|
|
@@ -88,7 +88,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
|
|
|
88
88
|
this.props.globalActions.fetchSchemaForEntity(query);
|
|
89
89
|
}
|
|
90
90
|
componentDidMount() {
|
|
91
|
-
if (this.props.location.query && this.props.location.query.module === '
|
|
91
|
+
if (this.props.location.query && this.props.location.query.module === 'library') {
|
|
92
92
|
this.props.actions.setTemplateDetails(this.props.templateData);
|
|
93
93
|
} else {
|
|
94
94
|
this.props.actions.getTemplateDetails(this.props.params.id);
|
|
@@ -104,10 +104,10 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
|
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
componentWillReceiveProps(nextProps) {
|
|
107
|
-
if (nextProps.location.query.module === '
|
|
107
|
+
if (nextProps.location.query.module === 'library' && nextProps.isGetFormData) {
|
|
108
108
|
nextProps.getFormSubscriptionData(this.getFormData());
|
|
109
109
|
}
|
|
110
|
-
if ( nextProps.location.query.module === '
|
|
110
|
+
if ( nextProps.location.query.module === 'library' && nextProps.subscriptionTemplateDetails && nextProps.subscriptionTemplateDetails.name && _.isEmpty(this.state.editData) && !_.isEmpty(this.state.schema)) {
|
|
111
111
|
this.setEditState(nextProps.subscriptionTemplateDetails);
|
|
112
112
|
}
|
|
113
113
|
if (nextProps.templateDetails && nextProps.templateDetails.name && _.isEmpty(this.state.editData) && !_.isEmpty(this.state.schema)) {
|
|
@@ -117,7 +117,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
|
|
|
117
117
|
this.setState({schema: nextProps.metaEntities.layouts[0].definition}, () => {
|
|
118
118
|
this.injectEvents(nextProps.metaEntities.layouts[0].definition);
|
|
119
119
|
});
|
|
120
|
-
if (this.props.location.query.module !== '
|
|
120
|
+
if (this.props.location.query.module !== 'library') {
|
|
121
121
|
const query = {
|
|
122
122
|
layout: 'SMS',
|
|
123
123
|
type: 'TAG',
|
|
@@ -1372,7 +1372,7 @@ export class Edit extends React.Component { // eslint-disable-line react/prefer-
|
|
|
1372
1372
|
tipText = this.props.Edit && ("editTemplateInProgress" in this.props.Edit && this.props.Edit.editTemplateInProgress) ? this.props.intl.formatMessage(messages.saveTemplateLoader) : '';
|
|
1373
1373
|
const spinning = this.state.loading || (this.props.Edit && (("getTemplateDetailsInProgress" in this.props.Edit && this.props.Edit.getTemplateDetailsInProgress) || ("editTemplateInProgress" in this.props.Edit && this.props.Edit.editTemplateInProgress)));
|
|
1374
1374
|
let tags = this.props.metaEntities && this.props.metaEntities.tags ? this.props.metaEntities.tags.standard : [];
|
|
1375
|
-
if (this.props.location.query.type === 'embedded' && this.props.location.query.module === '
|
|
1375
|
+
if (this.props.location.query.type === 'embedded' && this.props.location.query.module === 'library') {
|
|
1376
1376
|
tags = this.props.supportedTags;
|
|
1377
1377
|
}
|
|
1378
1378
|
return (
|