@capillarytech/creatives-library 7.10.8 → 7.10.10
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/app.js +4 -2
- package/package.json +1 -1
- package/routes.js +19 -0
- package/services/api.js +18 -5
- package/utils/common.js +7 -0
- package/v2Containers/App/constants.js +2 -0
- package/v2Containers/Cap/index.js +9 -4
- package/v2Containers/Cap/reducer.js +4 -1
- package/v2Containers/Cap/sagas.js +32 -21
- package/v2Containers/CreativesContainer/SlideBoxContent.js +16 -4
- package/v2Containers/CreativesContainer/SlideBoxHeader.js +6 -4
- package/v2Containers/CreativesContainer/index.js +53 -8
- package/v2Containers/SmsTrai/Create/constants.js +23 -21
- package/v2Containers/SmsTrai/Create/index.js +26 -18
- package/v2Containers/SmsTrai/Edit/index.js +200 -76
- package/v2Containers/SmsTrai/Edit/messages.js +14 -0
- package/v2Containers/SmsWrapper/index.js +14 -10
- package/v2Containers/Templates/index.js +12 -7
- package/v2Containers/TemplatesV2/index.js +2 -1
|
@@ -18,7 +18,6 @@ import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
|
|
|
18
18
|
import Papa from 'papaparse';
|
|
19
19
|
import cloneDeep from 'lodash/cloneDeep';
|
|
20
20
|
import {
|
|
21
|
-
CAP_SPACE_12,
|
|
22
21
|
CAP_SPACE_16,
|
|
23
22
|
CAP_SPACE_24,
|
|
24
23
|
CAP_SPACE_32,
|
|
@@ -48,7 +47,13 @@ import messages from './messages';
|
|
|
48
47
|
import withCreatives from '../../../hoc/withCreatives';
|
|
49
48
|
|
|
50
49
|
export const SmsTraiCreate = (props) => {
|
|
51
|
-
const {
|
|
50
|
+
const {
|
|
51
|
+
intl,
|
|
52
|
+
actions,
|
|
53
|
+
onCreateComplete,
|
|
54
|
+
isFullMode,
|
|
55
|
+
onShowTemplates,
|
|
56
|
+
} = props;
|
|
52
57
|
const { formatMessage } = intl;
|
|
53
58
|
const [files, setFiles] = useState([]);
|
|
54
59
|
const [errorText, setErrorText] = useState('');
|
|
@@ -90,13 +95,13 @@ export const SmsTraiCreate = (props) => {
|
|
|
90
95
|
const numbersOnly = /^\d+$/;
|
|
91
96
|
let isError = false;
|
|
92
97
|
senderIdString.split(',').forEach((value) => {
|
|
93
|
-
|
|
94
|
-
if (
|
|
95
|
-
if (
|
|
98
|
+
const _value = value.trim();
|
|
99
|
+
if (_value) {
|
|
100
|
+
if (_value.length !== 6) {
|
|
96
101
|
isError = true;
|
|
97
102
|
return;
|
|
98
103
|
}
|
|
99
|
-
if (!(lettersOnly.test(
|
|
104
|
+
if (!(lettersOnly.test(_value) || numbersOnly.test(_value))) {
|
|
100
105
|
isError = true;
|
|
101
106
|
}
|
|
102
107
|
}
|
|
@@ -114,7 +119,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
114
119
|
APPROVAL_STATUS,
|
|
115
120
|
);
|
|
116
121
|
|
|
117
|
-
for (let row = 1; row < transformedResults.length; row
|
|
122
|
+
for (let row = 1; row < transformedResults.length; row += 1) {
|
|
118
123
|
const errorArray = [];
|
|
119
124
|
const headerErrorArray = [];
|
|
120
125
|
const approvalErrorArray = [];
|
|
@@ -204,7 +209,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
204
209
|
return;
|
|
205
210
|
}
|
|
206
211
|
//one of the mandatory template id alias should be available.
|
|
207
|
-
for (let i = 0; i < TEMPLATE_ID_ALIASES.length; i
|
|
212
|
+
for (let i = 0; i < TEMPLATE_ID_ALIASES.length; i += 1) {
|
|
208
213
|
if (cols.includes(TEMPLATE_ID_ALIASES[i])) {
|
|
209
214
|
templateIdAliasPresent.push(TEMPLATE_ID_ALIASES[i]);
|
|
210
215
|
}
|
|
@@ -218,7 +223,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
218
223
|
return;
|
|
219
224
|
}
|
|
220
225
|
//one of the mandatory template message alias should be available.
|
|
221
|
-
for (let i = 0; i < TEMPLATE_MESSAGE_ALIASES.length; i
|
|
226
|
+
for (let i = 0; i < TEMPLATE_MESSAGE_ALIASES.length; i += 1) {
|
|
222
227
|
if (cols.includes(TEMPLATE_MESSAGE_ALIASES[i])) {
|
|
223
228
|
templateMessageAliasPresent.push(TEMPLATE_MESSAGE_ALIASES[i]);
|
|
224
229
|
}
|
|
@@ -306,7 +311,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
306
311
|
});
|
|
307
312
|
}
|
|
308
313
|
//adding validated rejection reason column to original results
|
|
309
|
-
for (let i = 0; i < validatedResults.length; i
|
|
314
|
+
for (let i = 0; i < validatedResults.length; i += 1) {
|
|
310
315
|
results.data[i].push(validatedResults[i][6]);
|
|
311
316
|
}
|
|
312
317
|
updateSaveTemplate(true);
|
|
@@ -356,7 +361,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
356
361
|
|
|
357
362
|
if (rejectionIndex !== -1) {
|
|
358
363
|
tempArray.push(fileData[0]);
|
|
359
|
-
for (let row = 1; row < fileData.length; row
|
|
364
|
+
for (let row = 1; row < fileData.length; row += 1) {
|
|
360
365
|
if (fileData[row][rejectionIndex]) {
|
|
361
366
|
tempArray.push(fileData[row]);
|
|
362
367
|
}
|
|
@@ -392,16 +397,15 @@ export const SmsTraiCreate = (props) => {
|
|
|
392
397
|
tempArray.push(fileData[0]);
|
|
393
398
|
|
|
394
399
|
// filter out non rejected rows
|
|
395
|
-
for (let row = 1; row < fileData.length; row
|
|
400
|
+
for (let row = 1; row < fileData.length; row += 1) {
|
|
396
401
|
if (!fileData[row][rejectionIndex]) {
|
|
397
402
|
tempArray.push(fileData[row]);
|
|
398
403
|
}
|
|
399
404
|
}
|
|
400
|
-
|
|
401
405
|
// Filter out the columns index that needs to save
|
|
402
406
|
const cols = getAllColumnNames(tempArray[0]);
|
|
403
407
|
const indexArray = [];
|
|
404
|
-
for (let i = 0; i < cols.length; i
|
|
408
|
+
for (let i = 0; i < cols.length; i += 1) {
|
|
405
409
|
if (
|
|
406
410
|
SAVED_COLUMNS.includes(cols[i]) ||
|
|
407
411
|
HEADER_ALIASES.includes(cols[i]) ||
|
|
@@ -418,7 +422,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
418
422
|
transformedResults.push(
|
|
419
423
|
indexArray.map((i) => {
|
|
420
424
|
if (key === '0') {
|
|
421
|
-
return MAPPED_SAVED_COLUMN[tempArray[key][i]];
|
|
425
|
+
return MAPPED_SAVED_COLUMN[tempArray[key][i]?.toUpperCase()];
|
|
422
426
|
}
|
|
423
427
|
return tempArray[key][i];
|
|
424
428
|
}),
|
|
@@ -452,7 +456,11 @@ export const SmsTraiCreate = (props) => {
|
|
|
452
456
|
{ templates: savedData },
|
|
453
457
|
(resp, errorMessage) => {
|
|
454
458
|
createCallback({ errorMessage });
|
|
455
|
-
|
|
459
|
+
if (isFullMode) {
|
|
460
|
+
onCreateComplete();
|
|
461
|
+
} else {
|
|
462
|
+
onShowTemplates();
|
|
463
|
+
}
|
|
456
464
|
},
|
|
457
465
|
);
|
|
458
466
|
};
|
|
@@ -530,7 +538,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
530
538
|
{previewFileIndex !== null && (
|
|
531
539
|
<>
|
|
532
540
|
<CapRow span={24} className="upload-type-group-create-container">
|
|
533
|
-
|
|
541
|
+
<>
|
|
534
542
|
<CapDivider
|
|
535
543
|
type="horizontal"
|
|
536
544
|
className="upload-file-preview-divider-1"
|
|
@@ -635,7 +643,7 @@ export const SmsTraiCreate = (props) => {
|
|
|
635
643
|
className="upload-file-preview-divider-2"
|
|
636
644
|
/>
|
|
637
645
|
{errorText && <CapError>{errorText}</CapError>}
|
|
638
|
-
|
|
646
|
+
</>
|
|
639
647
|
</CapRow>
|
|
640
648
|
</>
|
|
641
649
|
)}
|
|
@@ -13,6 +13,8 @@ import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
|
|
|
13
13
|
import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
|
|
14
14
|
import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
|
|
15
15
|
import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
|
|
16
|
+
import CapError from '@capillarytech/cap-ui-library/CapError';
|
|
17
|
+
import CapCheckbox from '@capillarytech/cap-ui-library/CapCheckbox';
|
|
16
18
|
import {
|
|
17
19
|
CAP_SPACE_16,
|
|
18
20
|
CAP_SPACE_12,
|
|
@@ -24,12 +26,13 @@ import {
|
|
|
24
26
|
} from '@capillarytech/cap-ui-library/styled/variables';
|
|
25
27
|
import { makeSelectTemplateDetailsResponse } from '../../Sms/Edit/selectors';
|
|
26
28
|
import { makeSelectMetaEntities, setInjectedTags } from '../../Cap/selectors';
|
|
27
|
-
import * as
|
|
29
|
+
import * as smsEditActions from '../../Sms/Edit/actions';
|
|
28
30
|
import messages from './messages';
|
|
29
31
|
import TagList from '../../TagList';
|
|
30
32
|
import TemplatePreview from '../../../v2Components/TemplatePreview';
|
|
31
33
|
import withCreatives from '../../../hoc/withCreatives';
|
|
32
|
-
|
|
34
|
+
import { validateTags } from '../../../utils/tagValidations';
|
|
35
|
+
import { updateCharCount } from '../../../utils/smsCharCountV2';
|
|
33
36
|
import {
|
|
34
37
|
CHARLIMIT,
|
|
35
38
|
SMS,
|
|
@@ -41,9 +44,13 @@ import {
|
|
|
41
44
|
ALL,
|
|
42
45
|
LIBRARY,
|
|
43
46
|
} from './constants';
|
|
47
|
+
|
|
44
48
|
let varMap = {};
|
|
49
|
+
let traiData = {};
|
|
50
|
+
let tagValidationResponse = {};
|
|
45
51
|
const { TextArea } = CapInput;
|
|
46
52
|
const { CapLabelInline } = CapLabel;
|
|
53
|
+
|
|
47
54
|
export const SmsTraiEdit = (props) => {
|
|
48
55
|
const {
|
|
49
56
|
intl,
|
|
@@ -58,6 +65,9 @@ export const SmsTraiEdit = (props) => {
|
|
|
58
65
|
metaEntities,
|
|
59
66
|
injectedTags,
|
|
60
67
|
onCreateComplete,
|
|
68
|
+
isFullMode,
|
|
69
|
+
getFormSubscriptionData,
|
|
70
|
+
templateData = {},
|
|
61
71
|
} = props || {};
|
|
62
72
|
const { formatMessage } = intl;
|
|
63
73
|
const [loading, updateLoading] = useState(true);
|
|
@@ -66,7 +76,9 @@ export const SmsTraiEdit = (props) => {
|
|
|
66
76
|
const [tags, updateTags] = useState([]);
|
|
67
77
|
const [textAreaId, updateTextAreaId] = useState();
|
|
68
78
|
const [isValidationError, updateIsValidationError] = useState(false);
|
|
69
|
-
|
|
79
|
+
const [isTagValidationError, updateIsTagValidationError] = useState(false);
|
|
80
|
+
const [totalMessageLength, setTotalMessageLength] = useState(0);
|
|
81
|
+
const [isUnicodeAllowed, updateIsUnicodeAllowed] = useState(false);
|
|
70
82
|
const SMSTraiFooter = styled.div`
|
|
71
83
|
background-color: ${CAP_WHITE};
|
|
72
84
|
position: fixed;
|
|
@@ -85,32 +97,38 @@ export const SmsTraiEdit = (props) => {
|
|
|
85
97
|
margin-right: ${CAP_SPACE_12};
|
|
86
98
|
}
|
|
87
99
|
`;
|
|
100
|
+
|
|
88
101
|
useEffect(() => {
|
|
102
|
+
//fetching tags
|
|
103
|
+
const { type, module } = location.query || {};
|
|
104
|
+
const isEmbedded = type === EMBEDDED;
|
|
105
|
+
const query = {
|
|
106
|
+
layout: SMS,
|
|
107
|
+
type: TAG,
|
|
108
|
+
context: isEmbedded ? module : DEFAULT,
|
|
109
|
+
embedded: isEmbedded ? type : FULL,
|
|
110
|
+
};
|
|
111
|
+
if (getDefaultTags) {
|
|
112
|
+
query.context = getDefaultTags;
|
|
113
|
+
}
|
|
114
|
+
globalActions.fetchSchemaForEntity(query);
|
|
115
|
+
//fetching template data in fullmode
|
|
89
116
|
const { id } = params || {};
|
|
90
117
|
if (id) {
|
|
91
118
|
actions.getTemplateDetails(id);
|
|
92
|
-
//fetching tags
|
|
93
|
-
const query = {
|
|
94
|
-
layout: SMS,
|
|
95
|
-
type: TAG,
|
|
96
|
-
context:
|
|
97
|
-
location.query.type === EMBEDDED ? location.query.module : DEFAULT,
|
|
98
|
-
embedded: location.query.type === EMBEDDED ? location.query.type : FULL,
|
|
99
|
-
};
|
|
100
|
-
if (getDefaultTags) {
|
|
101
|
-
query.context = getDefaultTags;
|
|
102
|
-
}
|
|
103
|
-
globalActions.fetchSchemaForEntity(query);
|
|
104
119
|
}
|
|
120
|
+
//cleanup code
|
|
105
121
|
return () => {
|
|
106
122
|
actions.resetEditTemplate();
|
|
123
|
+
varMap = {};
|
|
107
124
|
};
|
|
108
125
|
}, []);
|
|
109
126
|
|
|
110
127
|
//computing placeholder array for mapping values and rendering dynamic form
|
|
111
128
|
useEffect(() => {
|
|
112
|
-
|
|
113
|
-
|
|
129
|
+
traiData = isFullMode ? templateDetails : templateData;
|
|
130
|
+
if (traiData && !isEmpty(traiData)) {
|
|
131
|
+
let msg = get(traiData, `versions.base.sms-editor`);
|
|
114
132
|
const templateMessageArray = [];
|
|
115
133
|
//converting sms-editor string to an array split at '{#var#}'
|
|
116
134
|
//split and push string before '{#var#}[0 to index]', push '{#var#}',
|
|
@@ -126,44 +144,57 @@ export const SmsTraiEdit = (props) => {
|
|
|
126
144
|
break;
|
|
127
145
|
}
|
|
128
146
|
}
|
|
129
|
-
|
|
130
147
|
const filteredTemplateMessageArray = templateMessageArray.filter(
|
|
131
148
|
(i) => i.trim() !== '',
|
|
132
149
|
);
|
|
133
150
|
updateTempMsgArray(filteredTemplateMessageArray);
|
|
151
|
+
//updating unicode-validity
|
|
152
|
+
updateIsUnicodeAllowed(
|
|
153
|
+
get(traiData, `versions.base.unicode-validity`, false),
|
|
154
|
+
);
|
|
134
155
|
//stop spinner
|
|
135
156
|
updateLoading(false);
|
|
136
157
|
}
|
|
137
|
-
}, [templateDetails]);
|
|
158
|
+
}, [templateDetails || templateData]);
|
|
138
159
|
|
|
160
|
+
//compute/get varMapped and updated-sms-editor
|
|
139
161
|
useEffect(() => {
|
|
140
162
|
if (tempMsgArray.length !== 0) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
163
|
+
const traiBase = traiData?.versions?.base || {};
|
|
164
|
+
const {
|
|
165
|
+
'var-mapped': varMapped = {},
|
|
166
|
+
'updated-sms-editor': traiSmsEditor = '',
|
|
167
|
+
} = traiBase;
|
|
168
|
+
//if varMap and updated-sms-editor is already present on non first edits,use those values
|
|
169
|
+
if (!isEmpty(varMapped)) {
|
|
170
|
+
varMap = cloneDeep(varMapped);
|
|
171
|
+
if (isFullMode) {
|
|
172
|
+
setUpdatedSmsEditor(traiSmsEditor);
|
|
173
|
+
} else {
|
|
174
|
+
computeUpdatedSmsEditor();
|
|
175
|
+
}
|
|
147
176
|
} else {
|
|
148
|
-
//computing varMap for first edit
|
|
177
|
+
//computing and setting varMap for first edit
|
|
149
178
|
let counter = 1;
|
|
150
|
-
for (let i = 0; i < tempMsgArray.length; i
|
|
179
|
+
for (let i = 0; i < tempMsgArray.length; i += 1) {
|
|
151
180
|
if (tempMsgArray[i] === SMS_TRAI_VAR) {
|
|
152
181
|
const nextElem =
|
|
153
182
|
tempMsgArray[i === tempMsgArray.length - 1 ? 0 : i + 1];
|
|
154
183
|
if (tempMsgArray[i] !== nextElem) {
|
|
155
|
-
varMap[`${tempMsgArray[i]}_${i - counter + 1}`] = {
|
|
184
|
+
varMap[`${tempMsgArray[i]}_${(i - counter) + 1}`] = {
|
|
156
185
|
data: '',
|
|
157
186
|
count: counter,
|
|
158
187
|
};
|
|
159
188
|
counter = 1;
|
|
160
189
|
} else {
|
|
161
|
-
counter
|
|
190
|
+
counter += 1;
|
|
162
191
|
}
|
|
163
192
|
}
|
|
164
193
|
}
|
|
165
194
|
setUpdatedSmsEditor(tempMsgArray);
|
|
166
195
|
}
|
|
196
|
+
// calcaulate message length here
|
|
197
|
+
calculateTotalMessageLength();
|
|
167
198
|
}
|
|
168
199
|
}, [tempMsgArray]);
|
|
169
200
|
|
|
@@ -176,6 +207,43 @@ export const SmsTraiEdit = (props) => {
|
|
|
176
207
|
}
|
|
177
208
|
}, []);
|
|
178
209
|
|
|
210
|
+
//performs tag validation
|
|
211
|
+
useEffect(() => {
|
|
212
|
+
if (
|
|
213
|
+
!isFullMode &&
|
|
214
|
+
updatedSmsEditor?.length > 0 &&
|
|
215
|
+
!updatedSmsEditor.includes(SMS_TRAI_VAR)
|
|
216
|
+
) {
|
|
217
|
+
tagValidationResponse =
|
|
218
|
+
validateTags({
|
|
219
|
+
content: updatedSmsEditor.join(''),
|
|
220
|
+
tagsParam: tags,
|
|
221
|
+
injectedTagsParams: injectedTags,
|
|
222
|
+
location,
|
|
223
|
+
tagModule: getDefaultTags,
|
|
224
|
+
}) || {};
|
|
225
|
+
updateIsTagValidationError(
|
|
226
|
+
tagValidationResponse.unsupportedTags.length > 0,
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
}, [updatedSmsEditor, tags]);
|
|
230
|
+
|
|
231
|
+
const computeUpdatedSmsEditor = () => {
|
|
232
|
+
const updatedSmsArray = [...tempMsgArray];
|
|
233
|
+
for (const key in varMap) {
|
|
234
|
+
const index = Number(key.slice(8)); //Eg: -> extracting index 1 from keys like {#var# } _1
|
|
235
|
+
for (let i = 0; i < varMap[key].count; i += 1) {
|
|
236
|
+
//when multiple "#var#" come continuously ,it is considered as 1 textbox
|
|
237
|
+
if (i === 0) {
|
|
238
|
+
updatedSmsArray[index] = varMap[key].data; //data for first #var# of the textbox
|
|
239
|
+
} else {
|
|
240
|
+
updatedSmsArray[index + i] = ''; //"" for remaining #var# of a textbox
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
setUpdatedSmsEditor(updatedSmsArray);
|
|
245
|
+
};
|
|
246
|
+
|
|
179
247
|
//Saving on done start
|
|
180
248
|
const onUpdateTemplateComplete = (editResponse, errorMsg) => {
|
|
181
249
|
if (editResponse?.templateId) {
|
|
@@ -191,16 +259,30 @@ export const SmsTraiEdit = (props) => {
|
|
|
191
259
|
}
|
|
192
260
|
};
|
|
193
261
|
const onDoneCallback = () => {
|
|
194
|
-
if (updatedSmsEditor.includes(SMS_TRAI_VAR)) {
|
|
262
|
+
if (updatedSmsEditor.includes(SMS_TRAI_VAR) && !isFullMode) {
|
|
195
263
|
//during save textbox should not be empty
|
|
196
264
|
updateIsValidationError(true);
|
|
197
265
|
} else {
|
|
198
266
|
//start spinner
|
|
199
267
|
updateLoading(true);
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
268
|
+
const traiVersions = traiData.versions || {};
|
|
269
|
+
traiVersions.base = {
|
|
270
|
+
...traiVersions.base,
|
|
271
|
+
'var-mapped': varMap,
|
|
272
|
+
'updated-sms-editor': updatedSmsEditor,
|
|
273
|
+
'unicode-validity': isUnicodeAllowed,
|
|
274
|
+
};
|
|
275
|
+
traiVersions.history = [traiVersions.base];
|
|
276
|
+
if (isFullMode) {
|
|
277
|
+
actions.editTemplate(traiData, onUpdateTemplateComplete);
|
|
278
|
+
} else {
|
|
279
|
+
getFormSubscriptionData({
|
|
280
|
+
value: traiData.versions,
|
|
281
|
+
_id: params && params.id,
|
|
282
|
+
validity: true,
|
|
283
|
+
type: SMS,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
204
286
|
}
|
|
205
287
|
};
|
|
206
288
|
//Saving on done end
|
|
@@ -209,17 +291,16 @@ export const SmsTraiEdit = (props) => {
|
|
|
209
291
|
useEffect(() => {
|
|
210
292
|
let tag =
|
|
211
293
|
metaEntities && metaEntities.tags ? metaEntities.tags.standard : [];
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
location.query.module === LIBRARY &&
|
|
215
|
-
!getDefaultTags
|
|
216
|
-
) {
|
|
294
|
+
const { type, module } = location.query || {};
|
|
295
|
+
if (type === EMBEDDED && module === LIBRARY && !getDefaultTags) {
|
|
217
296
|
tag = supportedTags;
|
|
218
297
|
}
|
|
219
298
|
updateTags(tag);
|
|
220
299
|
}, [metaEntities]);
|
|
221
300
|
|
|
222
301
|
const handleOnTagsContextChange = (data) => {
|
|
302
|
+
const { type } = location.query || {};
|
|
303
|
+
const isEmbedded = type === EMBEDDED;
|
|
223
304
|
const query = {
|
|
224
305
|
layout: SMS,
|
|
225
306
|
type: TAG,
|
|
@@ -227,7 +308,7 @@ export const SmsTraiEdit = (props) => {
|
|
|
227
308
|
(data || '').toLowerCase() === ALL
|
|
228
309
|
? DEFAULT
|
|
229
310
|
: (data || '').toLowerCase(),
|
|
230
|
-
embedded:
|
|
311
|
+
embedded: isEmbedded ? type : FULL,
|
|
231
312
|
};
|
|
232
313
|
globalActions.fetchSchemaForEntity(query);
|
|
233
314
|
};
|
|
@@ -240,7 +321,7 @@ export const SmsTraiEdit = (props) => {
|
|
|
240
321
|
for (
|
|
241
322
|
let i = 0;
|
|
242
323
|
i < varMap[`${SMS_TRAI_VAR}_${textAreaId}`].count;
|
|
243
|
-
i
|
|
324
|
+
i += 1
|
|
244
325
|
) {
|
|
245
326
|
tempArr[textAreaId + i] = '';
|
|
246
327
|
}
|
|
@@ -259,23 +340,24 @@ export const SmsTraiEdit = (props) => {
|
|
|
259
340
|
|
|
260
341
|
// on change event of Text Area
|
|
261
342
|
const textAreaValueChange = ({ target: { value, id } }) => {
|
|
262
|
-
|
|
343
|
+
const _id = Number(id);
|
|
263
344
|
const arr = [...updatedSmsEditor];
|
|
264
|
-
varMap[`${SMS_TRAI_VAR}_${
|
|
345
|
+
varMap[`${SMS_TRAI_VAR}_${_id}`].data = value;
|
|
265
346
|
if (value === '') {
|
|
266
|
-
for (let i = 0; i < varMap[`${SMS_TRAI_VAR}_${
|
|
267
|
-
arr[
|
|
347
|
+
for (let i = 0; i < varMap[`${SMS_TRAI_VAR}_${_id}`].count; i += 1) {
|
|
348
|
+
arr[_id + i] = SMS_TRAI_VAR;
|
|
268
349
|
}
|
|
269
350
|
} else {
|
|
270
|
-
for (let i = 0; i < varMap[`${SMS_TRAI_VAR}_${id}`].count; i
|
|
351
|
+
for (let i = 0; i < varMap[`${SMS_TRAI_VAR}_${id}`].count; i += 1) {
|
|
271
352
|
if (i === 0) {
|
|
272
|
-
arr[
|
|
353
|
+
arr[_id] = varMap[`${SMS_TRAI_VAR}_${_id}`].data;
|
|
273
354
|
} else {
|
|
274
|
-
arr[
|
|
355
|
+
arr[_id + i] = '';
|
|
275
356
|
}
|
|
276
357
|
}
|
|
277
358
|
}
|
|
278
359
|
setUpdatedSmsEditor(arr);
|
|
360
|
+
calculateTotalMessageLength();
|
|
279
361
|
};
|
|
280
362
|
|
|
281
363
|
const textAreaValue = (idValue) => {
|
|
@@ -285,9 +367,8 @@ export const SmsTraiEdit = (props) => {
|
|
|
285
367
|
updatedSmsEditor[idValue] !== SMS_TRAI_VAR
|
|
286
368
|
) {
|
|
287
369
|
return updatedSmsEditor[idValue];
|
|
288
|
-
} else {
|
|
289
|
-
return '';
|
|
290
370
|
}
|
|
371
|
+
return '';
|
|
291
372
|
}
|
|
292
373
|
return '';
|
|
293
374
|
};
|
|
@@ -308,19 +389,19 @@ export const SmsTraiEdit = (props) => {
|
|
|
308
389
|
</CapHeading>
|
|
309
390
|
);
|
|
310
391
|
}
|
|
392
|
+
return <></>;
|
|
311
393
|
};
|
|
312
394
|
|
|
313
395
|
const renderedContent = () => {
|
|
314
396
|
const renderArray = [];
|
|
315
397
|
if (tempMsgArray?.length !== 0) {
|
|
316
398
|
let varCount = 0;
|
|
317
|
-
tempMsgArray.
|
|
399
|
+
tempMsgArray.forEach((elem, index) => {
|
|
318
400
|
let prevElem = '';
|
|
319
401
|
if (elem.includes(SMS_TRAI_VAR)) {
|
|
320
402
|
prevElem =
|
|
321
403
|
tempMsgArray[[index === 0 ? tempMsgArray.length - 1 : index - 1]];
|
|
322
|
-
varCount
|
|
323
|
-
totalVarCount++;
|
|
404
|
+
varCount += 1;
|
|
324
405
|
if (prevElem !== SMS_TRAI_VAR) {
|
|
325
406
|
renderArray.push(
|
|
326
407
|
<TextArea
|
|
@@ -371,42 +452,77 @@ export const SmsTraiEdit = (props) => {
|
|
|
371
452
|
return renderArray;
|
|
372
453
|
};
|
|
373
454
|
|
|
455
|
+
const smsLengthForVar = () => (
|
|
456
|
+
<CapHeading type="h5" style={{ marginTop: CAP_SPACE_04, float: 'right' }}>
|
|
457
|
+
{formatMessage(messages.totalCharacters, {
|
|
458
|
+
smsCount: Math.ceil(totalMessageLength / 160),
|
|
459
|
+
number: totalMessageLength,
|
|
460
|
+
})}
|
|
461
|
+
</CapHeading>
|
|
462
|
+
);
|
|
463
|
+
|
|
374
464
|
// to compute the length of the message
|
|
375
|
-
//30 characters is blocked per'{#var#}'
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
465
|
+
//30 characters is blocked per'{#var#}' if textbox is empty otherwise it will be textbox length
|
|
466
|
+
// and the remaining string length is added to it
|
|
467
|
+
const calculateTotalMessageLength = () => {
|
|
468
|
+
const msgLenWithoutVar = tempMsgArray
|
|
469
|
+
?.filter((i) => i !== SMS_TRAI_VAR)
|
|
470
|
+
.join('');
|
|
471
|
+
const charDetails = updateCharCount(msgLenWithoutVar, false);
|
|
472
|
+
const varLen = calculateLenForTextBox();
|
|
473
|
+
const totalMsgLen = charDetails.chars_used + varLen;
|
|
474
|
+
setTotalMessageLength(totalMsgLen);
|
|
475
|
+
};
|
|
476
|
+
|
|
477
|
+
const calculateLenForTextBox = () => {
|
|
478
|
+
let countVarChar = 0;
|
|
479
|
+
Object.keys(varMap).forEach((i) => {
|
|
480
|
+
if (varMap[i].data) {
|
|
481
|
+
const charDetails = updateCharCount(varMap[i].data, false);
|
|
482
|
+
countVarChar += charDetails.chars_used;
|
|
483
|
+
} else {
|
|
484
|
+
countVarChar += varMap[i].count * CHARLIMIT;
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
return countVarChar;
|
|
488
|
+
};
|
|
489
|
+
const tagValidationErrorMessage = () => {
|
|
490
|
+
const { unsupportedTags = [] } = tagValidationResponse;
|
|
491
|
+
let tagError = '';
|
|
492
|
+
if (unsupportedTags.length > 0) {
|
|
493
|
+
tagError = formatMessage(messages.unsupportedTagsValidationError, {
|
|
494
|
+
unsupportedTags,
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
return <CapError>{tagError}</CapError>;
|
|
498
|
+
};
|
|
499
|
+
|
|
500
|
+
const unicodeHandler = ({ target: { checked } }) => {
|
|
501
|
+
updateIsUnicodeAllowed(checked);
|
|
388
502
|
};
|
|
389
503
|
|
|
390
504
|
return (
|
|
391
505
|
<>
|
|
392
506
|
<CapSpin spinning={loading}>
|
|
393
507
|
<CapRow>
|
|
394
|
-
{
|
|
508
|
+
{traiData && !isEmpty(traiData) && (
|
|
395
509
|
<TraiEditTemplateDetails>
|
|
396
510
|
<CapLabelInline type="label1">
|
|
397
511
|
{formatMessage(messages.templateLabel)}
|
|
398
512
|
</CapLabelInline>
|
|
399
513
|
<CapLabelInline type="label2">
|
|
400
|
-
{
|
|
514
|
+
{traiData.versions.base.template_name}
|
|
401
515
|
</CapLabelInline>
|
|
516
|
+
|
|
402
517
|
<CapLabelInline type="label1">
|
|
403
518
|
{formatMessage(messages.traiEditSeperator)}
|
|
404
519
|
</CapLabelInline>
|
|
520
|
+
|
|
405
521
|
<CapLabelInline type="label1">
|
|
406
522
|
{formatMessage(messages.senderIdlabel)}
|
|
407
523
|
</CapLabelInline>
|
|
408
524
|
<CapLabelInline type="label2">
|
|
409
|
-
{
|
|
525
|
+
{traiData.versions.base.header.join(', ')}
|
|
410
526
|
</CapLabelInline>
|
|
411
527
|
</TraiEditTemplateDetails>
|
|
412
528
|
)}
|
|
@@ -437,17 +553,27 @@ export const SmsTraiEdit = (props) => {
|
|
|
437
553
|
{renderedContent()}
|
|
438
554
|
</CapRow>
|
|
439
555
|
<CapRow>{smsLengthForVar()}</CapRow>
|
|
556
|
+
{isTagValidationError && tagValidationErrorMessage()}
|
|
557
|
+
<CapCheckbox onChange={unicodeHandler} checked={isUnicodeAllowed}>
|
|
558
|
+
{formatMessage(messages.unicodeLabel)}
|
|
559
|
+
</CapCheckbox>
|
|
440
560
|
<div style={{ marginBottom: '100px' }} />
|
|
441
561
|
</CapColumn>
|
|
442
562
|
<CapColumn span={10}>
|
|
443
563
|
<TemplatePreview
|
|
444
564
|
channel={SMS}
|
|
445
|
-
content={
|
|
565
|
+
content={updatedSmsEditor.join('')}
|
|
566
|
+
unicodeEnabled={isUnicodeAllowed}
|
|
567
|
+
charCounterEnabled={true}
|
|
446
568
|
/>
|
|
447
569
|
</CapColumn>
|
|
448
570
|
</CapRow>
|
|
449
571
|
<SMSTraiFooter>
|
|
450
|
-
<CapButton
|
|
572
|
+
<CapButton
|
|
573
|
+
onClick={onDoneCallback}
|
|
574
|
+
className="create-msg"
|
|
575
|
+
disabled={isTagValidationError}
|
|
576
|
+
>
|
|
451
577
|
<FormattedMessage {...messages.saveButtonLabel} />
|
|
452
578
|
</CapButton>
|
|
453
579
|
<CapButton
|
|
@@ -469,11 +595,9 @@ const mapStateToProps = createStructuredSelector({
|
|
|
469
595
|
injectedTags: setInjectedTags(),
|
|
470
596
|
});
|
|
471
597
|
|
|
472
|
-
const mapDispatchToProps = (dispatch) => {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
};
|
|
476
|
-
};
|
|
598
|
+
const mapDispatchToProps = (dispatch) => ({
|
|
599
|
+
actions: bindActionCreators(smsEditActions, dispatch),
|
|
600
|
+
});
|
|
477
601
|
|
|
478
602
|
export default withCreatives({
|
|
479
603
|
WrappedComponent: injectIntl(SmsTraiEdit),
|
|
@@ -55,4 +55,18 @@ export default defineMessages({
|
|
|
55
55
|
id: `${prefix}.senderIdlabel`,
|
|
56
56
|
defaultMessage: 'Sender ID',
|
|
57
57
|
},
|
|
58
|
+
missingTagsValidationError: {
|
|
59
|
+
id: `${prefix}.missingTagsValidationError`,
|
|
60
|
+
defaultMessage:
|
|
61
|
+
'Missing tags: {missingTags}. Please add them to this message.',
|
|
62
|
+
},
|
|
63
|
+
unsupportedTagsValidationError: {
|
|
64
|
+
id: `${prefix}.unsupportedTagsValidationError`,
|
|
65
|
+
defaultMessage:
|
|
66
|
+
'Unsupported tags: {unsupportedTags}. Please remove them from this message.',
|
|
67
|
+
},
|
|
68
|
+
unicodeLabel: {
|
|
69
|
+
id: `${prefix}.unicodeLabel`,
|
|
70
|
+
defaultMessage: 'Allow unicode characters',
|
|
71
|
+
},
|
|
58
72
|
});
|