@capillarytech/creatives-library 7.10.40 → 7.10.42
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/package.json +1 -1
- package/v2Components/TemplatePreview/index.js +2 -2
- package/v2Containers/CreativesContainer/SlideBoxContent.js +11 -4
- package/v2Containers/CreativesContainer/SlideBoxHeader.js +31 -4
- package/v2Containers/CreativesContainer/messages.js +4 -0
- package/v2Containers/Templates/index.js +40 -4
- package/v2Containers/Templates/reducer.js +2 -2
- package/v2Containers/Whatsapp/actions.js +21 -4
- package/v2Containers/Whatsapp/constants.js +39 -12
- package/v2Containers/Whatsapp/index.js +547 -167
- package/v2Containers/Whatsapp/index.scss +28 -8
- package/v2Containers/Whatsapp/messages.js +37 -0
- package/v2Containers/Whatsapp/reducer.js +23 -8
- package/v2Containers/Whatsapp/sagas.js +36 -7
- package/v2Containers/Whatsapp/selectors.js +6 -19
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +16545 -18899
- package/v2Containers/Whatsapp/tests/index.test.js +2 -2
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
/* eslint-disable no-undef */
|
|
2
|
-
import React, { useState } from 'react';
|
|
2
|
+
import React, { useState, useEffect } from 'react';
|
|
3
3
|
import { bindActionCreators } from 'redux';
|
|
4
4
|
import { createStructuredSelector } from 'reselect';
|
|
5
5
|
import { injectIntl, FormattedMessage } from 'react-intl';
|
|
6
|
+
import { get, isEmpty, cloneDeep } from 'lodash';
|
|
6
7
|
import styled from 'styled-components';
|
|
7
8
|
import CapSpin from '@capillarytech/cap-ui-library/CapSpin';
|
|
8
9
|
import CapRow from '@capillarytech/cap-ui-library/CapRow';
|
|
@@ -15,8 +16,11 @@ import CapHeading from '@capillarytech/cap-ui-library/CapHeading';
|
|
|
15
16
|
import CapRadioGroup from '@capillarytech/cap-ui-library/CapRadioGroup';
|
|
16
17
|
import CapTooltip from '@capillarytech/cap-ui-library/CapTooltip';
|
|
17
18
|
import CapError from '@capillarytech/cap-ui-library/CapError';
|
|
19
|
+
import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
|
|
18
20
|
import CapButton from '@capillarytech/cap-ui-library/CapButton';
|
|
19
21
|
import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
|
|
22
|
+
import CapAlert from '@capillarytech/cap-ui-library/CapAlert';
|
|
23
|
+
import moment from 'moment';
|
|
20
24
|
import {
|
|
21
25
|
CAP_SPACE_04,
|
|
22
26
|
CAP_SPACE_16,
|
|
@@ -24,7 +28,7 @@ import {
|
|
|
24
28
|
CAP_SPACE_32,
|
|
25
29
|
CAP_WHITE,
|
|
26
30
|
} from '@capillarytech/cap-ui-library/styled/variables';
|
|
27
|
-
import {} from './selectors';
|
|
31
|
+
import { makeSelectWhatsapp, makeSelectAccount } from './selectors';
|
|
28
32
|
import * as WhatsappActions from './actions';
|
|
29
33
|
import './index.scss';
|
|
30
34
|
import {
|
|
@@ -32,28 +36,42 @@ import {
|
|
|
32
36
|
TEMPLATE_MESSAGE_MAX_LENGTH,
|
|
33
37
|
WHATSAPP,
|
|
34
38
|
CATEGORY_OPTIONS,
|
|
39
|
+
WHATSAPP_STATUSES,
|
|
40
|
+
TAG,
|
|
41
|
+
EMBEDDED,
|
|
42
|
+
DEFAULT,
|
|
43
|
+
FULL,
|
|
44
|
+
ALL,
|
|
45
|
+
LIBRARY,
|
|
35
46
|
} from './constants';
|
|
36
47
|
import messages from './messages';
|
|
37
48
|
import withCreatives from '../../hoc/withCreatives';
|
|
38
49
|
import TemplatePreview from '../../v2Components/TemplatePreview';
|
|
50
|
+
import TagList from '../TagList';
|
|
51
|
+
import { makeSelectMetaEntities, setInjectedTags } from '../Cap/selectors';
|
|
52
|
+
|
|
53
|
+
let varMap = {};
|
|
54
|
+
let editContent = {};
|
|
39
55
|
|
|
40
56
|
export const Whatsapp = (props) => {
|
|
41
57
|
const {
|
|
42
58
|
intl,
|
|
59
|
+
actions,
|
|
43
60
|
isFullMode,
|
|
61
|
+
onCreateComplete,
|
|
44
62
|
handleClose,
|
|
63
|
+
params,
|
|
64
|
+
templateData = {},
|
|
65
|
+
editData = {},
|
|
66
|
+
accountData = {},
|
|
67
|
+
globalActions,
|
|
45
68
|
location,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
69
|
+
getDefaultTags,
|
|
70
|
+
supportedTags,
|
|
71
|
+
metaEntities,
|
|
72
|
+
injectedTags,
|
|
49
73
|
} = props || {};
|
|
50
74
|
const { formatMessage } = intl;
|
|
51
|
-
const {
|
|
52
|
-
name: accountName = '',
|
|
53
|
-
configs: accountConfigs = {},
|
|
54
|
-
sourceAccountIdentifier: accountId = '',
|
|
55
|
-
} = selectedWeChatAccount;
|
|
56
|
-
const { accessToken = '' } = accountConfigs;
|
|
57
75
|
const { TextArea } = CapInput;
|
|
58
76
|
const [templateName, setTemplateName] = useState('');
|
|
59
77
|
const [templateNameError, setTemplateNameError] = useState(false);
|
|
@@ -63,11 +81,23 @@ export const Whatsapp = (props) => {
|
|
|
63
81
|
const [templateMessage, setTemplateMessage] = useState('');
|
|
64
82
|
const [templateMessageError, setTemplateMessageError] = useState(false);
|
|
65
83
|
const [addedVarCount, setAddedVarCount] = useState(0);
|
|
84
|
+
const [accountId, setAccountId] = useState('');
|
|
85
|
+
const [accessToken, setAccessToken] = useState('');
|
|
86
|
+
const [accountName, setAccountName] = useState('');
|
|
66
87
|
const [spin, setSpin] = useState(false);
|
|
88
|
+
//for edit only
|
|
89
|
+
const [isEditFlow, setEditFlow] = useState(false);
|
|
90
|
+
const [templateDate, setTemplateDate] = useState('');
|
|
91
|
+
const [templateStatus, setTemplateStatus] = useState(
|
|
92
|
+
WHATSAPP_STATUSES.unsubmitted,
|
|
93
|
+
);
|
|
94
|
+
const [tempMsgArray, updateTempMsgArray] = useState([]);
|
|
95
|
+
const [updatedSmsEditor, setUpdatedSmsEditor] = useState([]);
|
|
96
|
+
//for tag only
|
|
97
|
+
const [tags, updateTags] = useState([]);
|
|
98
|
+
const [textAreaId, updateTextAreaId] = useState();
|
|
67
99
|
|
|
68
|
-
const
|
|
69
|
-
margin-top: ${CAP_SPACE_16};
|
|
70
|
-
`;
|
|
100
|
+
const validVarRegex = /{{([1-9]|1[0-9])}}/g;
|
|
71
101
|
|
|
72
102
|
const WhatsappFooter = styled.div`
|
|
73
103
|
background-color: ${CAP_WHITE};
|
|
@@ -82,7 +112,177 @@ export const Whatsapp = (props) => {
|
|
|
82
112
|
}
|
|
83
113
|
}
|
|
84
114
|
`;
|
|
115
|
+
//edit
|
|
116
|
+
//gets account details
|
|
117
|
+
useEffect(() => {
|
|
118
|
+
const accountObj = accountData.selectedWhatsappAccount || {};
|
|
119
|
+
if (!isEmpty(accountObj)) {
|
|
120
|
+
setAccountId(get(accountObj, `sourceAccountIdentifier`, ''));
|
|
121
|
+
setAccessToken(get(accountObj, `configs.accessToken`, ''));
|
|
122
|
+
setAccountName(get(accountObj, `name`, ''));
|
|
123
|
+
}
|
|
124
|
+
}, [accountData.selectedWhatsappAccount]);
|
|
125
|
+
|
|
126
|
+
//gets template details
|
|
127
|
+
const paramObj = params || {};
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
const { id } = paramObj;
|
|
130
|
+
if (id && !get(templateData, `versions.base.content`)) {
|
|
131
|
+
setSpin(true);
|
|
132
|
+
actions.getTemplateDetails(id);
|
|
133
|
+
setEditFlow(true);
|
|
134
|
+
}
|
|
135
|
+
//cleanup code
|
|
136
|
+
return () => {
|
|
137
|
+
if (isEditFlow) {
|
|
138
|
+
actions.resetEditTemplate();
|
|
139
|
+
varMap = {};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
}, [paramObj.id]);
|
|
85
143
|
|
|
144
|
+
useEffect(() => {
|
|
145
|
+
editContent =
|
|
146
|
+
get(templateData, `versions.base.content.whatsapp`) ||
|
|
147
|
+
get(editData, `templateDetails.versions.base.content.whatsapp`) ||
|
|
148
|
+
{};
|
|
149
|
+
if (editContent && !isEmpty(editContent)) {
|
|
150
|
+
const editMessageTitle =
|
|
151
|
+
(templateData || {}).name || get(editData, 'templateDetails.name');
|
|
152
|
+
const createdAt =
|
|
153
|
+
(templateData || {}).createdAt ||
|
|
154
|
+
get(editData, 'templateDetails.createdAt');
|
|
155
|
+
setTemplateName(editMessageTitle);
|
|
156
|
+
setTemplateDate(createdAt);
|
|
157
|
+
setTemplateCategory(get(editContent, `category`, ''));
|
|
158
|
+
setTemplateStatus(
|
|
159
|
+
get(editContent, `status`, WHATSAPP_STATUSES.unsubmitted),
|
|
160
|
+
);
|
|
161
|
+
computeTempMsgArray();
|
|
162
|
+
}
|
|
163
|
+
}, [editData.templateDetails || templateData]);
|
|
164
|
+
|
|
165
|
+
const computeTempMsgArray = () => {
|
|
166
|
+
let msg = get(editContent, `languages[0].content`, '');
|
|
167
|
+
const validVarArr = msg.match(validVarRegex) || [];
|
|
168
|
+
const templateMessageArray = [];
|
|
169
|
+
msg = msg.slice(2, -1);
|
|
170
|
+
msg = msg.replace(
|
|
171
|
+
`Click ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
|
|
172
|
+
'',
|
|
173
|
+
);
|
|
174
|
+
validVarArr.pop();
|
|
175
|
+
while (msg.length !== 0) {
|
|
176
|
+
const index = msg.indexOf(validVarArr[0]);
|
|
177
|
+
if (index !== -1) {
|
|
178
|
+
templateMessageArray.push(msg.substring(0, index));
|
|
179
|
+
templateMessageArray.push(validVarArr[0]);
|
|
180
|
+
msg = msg.substring(index + validVarArr[0].length, msg.length);
|
|
181
|
+
validVarArr.shift();
|
|
182
|
+
} else {
|
|
183
|
+
templateMessageArray.push(msg);
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
updateTempMsgArray(templateMessageArray.filter((i) => i === 0 || i));
|
|
188
|
+
//stop spinner
|
|
189
|
+
setSpin(false);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
useEffect(() => {
|
|
193
|
+
if (tempMsgArray.length !== 0) {
|
|
194
|
+
const { varMapped = {} } = editContent;
|
|
195
|
+
if (!isEmpty(varMapped)) {
|
|
196
|
+
varMap = cloneDeep(varMapped);
|
|
197
|
+
} else {
|
|
198
|
+
//computing and setting varMap for first edit
|
|
199
|
+
for (let i = 0; i < tempMsgArray.length; i += 1) {
|
|
200
|
+
if (tempMsgArray[i].match(validVarRegex)?.length > 0) {
|
|
201
|
+
varMap[`${tempMsgArray[i]}_${i}`] = '';
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
//setting updatedSmsEditor based on varMap
|
|
206
|
+
const arr = [...tempMsgArray];
|
|
207
|
+
for (const key in varMap) {
|
|
208
|
+
if (varMap[key] !== '') {
|
|
209
|
+
arr[key.slice(key.indexOf('_') + 1)] = varMap[key];
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
setUpdatedSmsEditor(arr);
|
|
213
|
+
}
|
|
214
|
+
}, [tempMsgArray]);
|
|
215
|
+
|
|
216
|
+
// tag Code start from here
|
|
217
|
+
useEffect(() => {
|
|
218
|
+
//fetching tags
|
|
219
|
+
if (isEditFlow) {
|
|
220
|
+
const { type, module } = location.query || {};
|
|
221
|
+
const isEmbedded = type === EMBEDDED;
|
|
222
|
+
const query = {
|
|
223
|
+
layout: 'SMS',
|
|
224
|
+
type: TAG,
|
|
225
|
+
context: isEmbedded ? module : DEFAULT,
|
|
226
|
+
embedded: isEmbedded ? type : FULL,
|
|
227
|
+
};
|
|
228
|
+
if (getDefaultTags) {
|
|
229
|
+
query.context = getDefaultTags;
|
|
230
|
+
}
|
|
231
|
+
globalActions.fetchSchemaForEntity(query);
|
|
232
|
+
}
|
|
233
|
+
}, []);
|
|
234
|
+
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (isEditFlow) {
|
|
237
|
+
let tag =
|
|
238
|
+
metaEntities && metaEntities.tags ? metaEntities.tags.standard : [];
|
|
239
|
+
const { type, module } = location.query || {};
|
|
240
|
+
if (type === EMBEDDED && module === LIBRARY && !getDefaultTags) {
|
|
241
|
+
tag = supportedTags;
|
|
242
|
+
}
|
|
243
|
+
updateTags(tag);
|
|
244
|
+
}
|
|
245
|
+
}, [metaEntities]);
|
|
246
|
+
|
|
247
|
+
const handleOnTagsContextChange = (data) => {
|
|
248
|
+
const { type } = location.query || {};
|
|
249
|
+
const isEmbedded = type === EMBEDDED;
|
|
250
|
+
const query = {
|
|
251
|
+
layout: 'SMS',
|
|
252
|
+
type: TAG,
|
|
253
|
+
context:
|
|
254
|
+
(data || '').toLowerCase() === ALL
|
|
255
|
+
? DEFAULT
|
|
256
|
+
: (data || '').toLowerCase(),
|
|
257
|
+
embedded: isEmbedded ? type : FULL,
|
|
258
|
+
};
|
|
259
|
+
globalActions.fetchSchemaForEntity(query);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
const onTagSelect = (data) => {
|
|
263
|
+
if (varMap && updatedSmsEditor) {
|
|
264
|
+
let numId = Number(textAreaId?.slice(textAreaId?.indexOf('_') + 1));
|
|
265
|
+
if (numId !== NaN) {
|
|
266
|
+
const arr = [...updatedSmsEditor];
|
|
267
|
+
//when trying to insert tag in empty textarea,{#var#} is replaced with "" and then tag is added
|
|
268
|
+
if (arr[numId]?.match(validVarRegex)?.length > 0) {
|
|
269
|
+
arr[numId] = '';
|
|
270
|
+
}
|
|
271
|
+
const messageData = `${arr[numId]}{{${data}}}`;
|
|
272
|
+
arr[numId] = messageData;
|
|
273
|
+
varMap[textAreaId] = messageData;
|
|
274
|
+
setUpdatedSmsEditor(arr);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
//setting the id of currently selected text area, is used onTagSelect
|
|
280
|
+
const setTextAreaId = ({ target: { id } }) => {
|
|
281
|
+
updateTextAreaId(id);
|
|
282
|
+
};
|
|
283
|
+
// tag Code end
|
|
284
|
+
|
|
285
|
+
//create methods start
|
|
86
286
|
const renderTemplateCategoryLabel = (tooltipLabel, title) => (
|
|
87
287
|
<CapRow>
|
|
88
288
|
<CapColumn span={23}>{title}</CapColumn>
|
|
@@ -129,6 +329,46 @@ export const Whatsapp = (props) => {
|
|
|
129
329
|
},
|
|
130
330
|
];
|
|
131
331
|
|
|
332
|
+
const renderLabel = (value) => (
|
|
333
|
+
<CapHeading type="h4" className="whatsapp-render-heading">
|
|
334
|
+
{formatMessage(messages[value])}
|
|
335
|
+
</CapHeading>
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const renderUnsubscribeText = () => (
|
|
339
|
+
<>
|
|
340
|
+
<CapColumn span={12}>
|
|
341
|
+
<CapTooltip
|
|
342
|
+
placement="bottom"
|
|
343
|
+
title={formatMessage(messages.unsubscribeTextTooltip)}
|
|
344
|
+
>
|
|
345
|
+
<CapHeading
|
|
346
|
+
className={
|
|
347
|
+
!isEditFlow
|
|
348
|
+
? 'whatsapp-create-render-unsubscribe-text'
|
|
349
|
+
: 'whatsapp-edit-render-unsubscribe-text'
|
|
350
|
+
}
|
|
351
|
+
>
|
|
352
|
+
{formatMessage(messages.templateMessageUnsubscribeText)}
|
|
353
|
+
</CapHeading>
|
|
354
|
+
</CapTooltip>
|
|
355
|
+
</CapColumn>
|
|
356
|
+
<CapColumn span={12}></CapColumn>
|
|
357
|
+
</>
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
//used by create and edit
|
|
361
|
+
const renderMessageLength = () => (
|
|
362
|
+
<CapHeading type="h6" className="whatsapp-render-message-length">
|
|
363
|
+
{formatMessage(messages.templateMessageLength, {
|
|
364
|
+
currentLength: isEditFlow
|
|
365
|
+
? updatedSmsEditor?.join('')?.length + UNSUBSCRIBE_TEXT_LENGTH
|
|
366
|
+
: templateMessage?.length + UNSUBSCRIBE_TEXT_LENGTH,
|
|
367
|
+
maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
|
|
368
|
+
})}
|
|
369
|
+
</CapHeading>
|
|
370
|
+
);
|
|
371
|
+
|
|
132
372
|
const onTemplateNameChange = ({ target: { value } }) => {
|
|
133
373
|
setTemplateName(value);
|
|
134
374
|
templateNameErrorHandler(value);
|
|
@@ -149,11 +389,6 @@ export const Whatsapp = (props) => {
|
|
|
149
389
|
const onTemplateCategoryChange = (value) => {
|
|
150
390
|
setTemplateCategory(value);
|
|
151
391
|
};
|
|
152
|
-
const renderHeading = (value) => (
|
|
153
|
-
<CapHeading type="h4" className="whatsapp-render-heading">
|
|
154
|
-
{formatMessage(messages[value])}
|
|
155
|
-
</CapHeading>
|
|
156
|
-
);
|
|
157
392
|
|
|
158
393
|
const onTemplateMessageChange = ({ target: { value } }) => {
|
|
159
394
|
const error = templateMessageErrorHandler(value);
|
|
@@ -171,7 +406,6 @@ export const Whatsapp = (props) => {
|
|
|
171
406
|
) {
|
|
172
407
|
errorMessage = formatMessage(messages.templateMessageLengthError);
|
|
173
408
|
} else {
|
|
174
|
-
const validVarRegex = /{{([1-9]|1[0-9])}}/g;
|
|
175
409
|
const validVarArr = value.match(validVarRegex) || [];
|
|
176
410
|
const validVarSet = [...new Set(validVarArr)];
|
|
177
411
|
|
|
@@ -179,7 +413,7 @@ export const Whatsapp = (props) => {
|
|
|
179
413
|
const invalidVarArr = value.match(invalidVarRegex) || [];
|
|
180
414
|
const invalidVarSet = [...new Set(invalidVarArr)];
|
|
181
415
|
|
|
182
|
-
const
|
|
416
|
+
const noContentBetweenVars = /}}[^a-zA-Z]*{{/g;
|
|
183
417
|
|
|
184
418
|
if (validVarArr?.length > 0 || invalidVarArr?.length > 0) {
|
|
185
419
|
if (validVarArr?.length !== validVarSet?.length) {
|
|
@@ -188,7 +422,7 @@ export const Whatsapp = (props) => {
|
|
|
188
422
|
} else if (invalidVarSet?.length !== validVarSet?.length) {
|
|
189
423
|
//checks for invalid vars like Hi {{abcd}}, offer for you {{^_^}}
|
|
190
424
|
errorMessage = formatMessage(messages.unknownVars);
|
|
191
|
-
} else if (value.match(
|
|
425
|
+
} else if (value.match(noContentBetweenVars)?.length > 0) {
|
|
192
426
|
//checks for text between vars like Hi {{1}}{{2}}
|
|
193
427
|
errorMessage = formatMessage(messages.noContentBetweenVars);
|
|
194
428
|
} else {
|
|
@@ -207,44 +441,6 @@ export const Whatsapp = (props) => {
|
|
|
207
441
|
return errorMessage;
|
|
208
442
|
};
|
|
209
443
|
|
|
210
|
-
const renderUnsubscribeText = () => (
|
|
211
|
-
<>
|
|
212
|
-
<CapColumn span={12}>
|
|
213
|
-
<CapTooltip
|
|
214
|
-
placement="bottom"
|
|
215
|
-
title={formatMessage(messages.unsubscribeTextTooltip)}
|
|
216
|
-
>
|
|
217
|
-
<CapHeading className="whatsapp-render-unsubscribe-text">
|
|
218
|
-
{formatMessage(messages.templateMessageUnsubscribeText)}
|
|
219
|
-
</CapHeading>
|
|
220
|
-
</CapTooltip>
|
|
221
|
-
</CapColumn>
|
|
222
|
-
<CapColumn span={12}></CapColumn>
|
|
223
|
-
</>
|
|
224
|
-
);
|
|
225
|
-
|
|
226
|
-
const renderMessageLength = () => (
|
|
227
|
-
<CapHeading type="h6" className="whatsapp-render-message-length">
|
|
228
|
-
{formatMessage(messages.templateMessageLength, {
|
|
229
|
-
currentLength: UNSUBSCRIBE_TEXT_LENGTH + templateMessage?.length,
|
|
230
|
-
maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
|
|
231
|
-
})}
|
|
232
|
-
</CapHeading>
|
|
233
|
-
);
|
|
234
|
-
|
|
235
|
-
const generateVarMapped = () => {
|
|
236
|
-
const varMappedObj = {};
|
|
237
|
-
const finalIndex = addedVarCount + 1;
|
|
238
|
-
for (let i = 1; i <= finalIndex; i += 1) {
|
|
239
|
-
if (i === addedVarCount + 1) {
|
|
240
|
-
varMappedObj[i] = '{{unsubscribe}}';
|
|
241
|
-
} else {
|
|
242
|
-
varMappedObj[i] = '';
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
return varMappedObj;
|
|
246
|
-
};
|
|
247
|
-
|
|
248
444
|
const createPayload = () => ({
|
|
249
445
|
name: templateName,
|
|
250
446
|
versions: {
|
|
@@ -261,7 +457,7 @@ export const Whatsapp = (props) => {
|
|
|
261
457
|
},
|
|
262
458
|
],
|
|
263
459
|
mediaType: 'text',
|
|
264
|
-
|
|
460
|
+
varMapped: {},
|
|
265
461
|
accountId,
|
|
266
462
|
accessToken,
|
|
267
463
|
accountName,
|
|
@@ -322,10 +518,270 @@ export const Whatsapp = (props) => {
|
|
|
322
518
|
return false;
|
|
323
519
|
};
|
|
324
520
|
|
|
521
|
+
const createModeContent = (
|
|
522
|
+
<>
|
|
523
|
+
{/* template name */}
|
|
524
|
+
<CapHeader
|
|
525
|
+
title={
|
|
526
|
+
<CapHeading type="h4">
|
|
527
|
+
{formatMessage(messages.templateNameLabel)}
|
|
528
|
+
<CapTooltipWithInfo
|
|
529
|
+
infoIconProps={{
|
|
530
|
+
style: { marginLeft: CAP_SPACE_04 },
|
|
531
|
+
}}
|
|
532
|
+
autoAdjustOverflow
|
|
533
|
+
title={<FormattedMessage {...messages.templateNameTooltip} />}
|
|
534
|
+
/>
|
|
535
|
+
</CapHeading>
|
|
536
|
+
}
|
|
537
|
+
description={
|
|
538
|
+
<CapLabel className="whatsapp-template-name-desc">
|
|
539
|
+
{formatMessage(messages.templateNameDesc)}
|
|
540
|
+
</CapLabel>
|
|
541
|
+
}
|
|
542
|
+
/>
|
|
543
|
+
<CapInput
|
|
544
|
+
id={`whatsapp_template_name_input`}
|
|
545
|
+
onChange={onTemplateNameChange}
|
|
546
|
+
errorMessage={templateNameError}
|
|
547
|
+
placeholder={formatMessage(messages.templateNamePlaceholder)}
|
|
548
|
+
defaultValue={templateName || ''}
|
|
549
|
+
value={templateName || ''}
|
|
550
|
+
size="default"
|
|
551
|
+
/>
|
|
552
|
+
{/* template category */}
|
|
553
|
+
{renderLabel('templateCategoryLabel')}
|
|
554
|
+
<CapSelect
|
|
555
|
+
id={'select-whatsapp-category'}
|
|
556
|
+
options={templateCategoryOptions || []}
|
|
557
|
+
onChange={onTemplateCategoryChange}
|
|
558
|
+
value={templateCategory}
|
|
559
|
+
/>
|
|
560
|
+
{/* template language */}
|
|
561
|
+
{renderLabel('messageLanguageLabel')}
|
|
562
|
+
<CapInput
|
|
563
|
+
id={`whatsapp_template_language_input`}
|
|
564
|
+
defaultValue={'English'}
|
|
565
|
+
size="default"
|
|
566
|
+
disabled={true}
|
|
567
|
+
/>
|
|
568
|
+
{/* template mdeia type */}
|
|
569
|
+
{renderLabel('mediaLabel')}
|
|
570
|
+
<CapRadioGroup options={mediaRadioOptions || []} defaultValue={'text'} />
|
|
571
|
+
{/* template message create flow */}
|
|
572
|
+
<CapHeading type="h4" className="whatsapp-render-heading">
|
|
573
|
+
{formatMessage(messages.templateMessageLabel)}
|
|
574
|
+
<CapTooltipWithInfo
|
|
575
|
+
placement="right"
|
|
576
|
+
infoIconProps={{
|
|
577
|
+
style: { marginLeft: CAP_SPACE_04 },
|
|
578
|
+
}}
|
|
579
|
+
autoAdjustOverflow
|
|
580
|
+
title={
|
|
581
|
+
<FormattedMessage
|
|
582
|
+
{...messages.templateMessageTooltip}
|
|
583
|
+
values={{
|
|
584
|
+
br: <br />,
|
|
585
|
+
var: '{{1}}',
|
|
586
|
+
}}
|
|
587
|
+
/>
|
|
588
|
+
}
|
|
589
|
+
/>
|
|
590
|
+
</CapHeading>
|
|
591
|
+
<CapRow className="whatsapp-create-template-message-input">
|
|
592
|
+
<TextArea
|
|
593
|
+
id={`whatsapp-create-template-message-input`}
|
|
594
|
+
autosize={{ minRows: 3, maxRows: 5 }}
|
|
595
|
+
placeholder={formatMessage(messages.templateMessagePlaceholder)}
|
|
596
|
+
onChange={onTemplateMessageChange}
|
|
597
|
+
errorMessage={
|
|
598
|
+
templateMessageError && (
|
|
599
|
+
<CapError className="whatsapp-template-message-error">
|
|
600
|
+
{templateMessageError}
|
|
601
|
+
</CapError>
|
|
602
|
+
)
|
|
603
|
+
}
|
|
604
|
+
value={templateMessage || ''}
|
|
605
|
+
/>
|
|
606
|
+
{renderUnsubscribeText()}
|
|
607
|
+
</CapRow>
|
|
608
|
+
{renderMessageLength()}
|
|
609
|
+
</>
|
|
610
|
+
);
|
|
611
|
+
//create methods end
|
|
612
|
+
|
|
613
|
+
//edit methods start
|
|
614
|
+
const getAlertType = () => {
|
|
615
|
+
if (templateStatus === WHATSAPP_STATUSES.approved) {
|
|
616
|
+
return 'success';
|
|
617
|
+
} else if (templateStatus === WHATSAPP_STATUSES.rejected) {
|
|
618
|
+
return 'error';
|
|
619
|
+
}
|
|
620
|
+
return 'warning';
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
const getAlertMessage = () => {
|
|
624
|
+
if (templateStatus === WHATSAPP_STATUSES.approved) {
|
|
625
|
+
return (
|
|
626
|
+
<CapLabel type="label2">
|
|
627
|
+
{formatMessage(messages.approvedStatusMsg)}
|
|
628
|
+
</CapLabel>
|
|
629
|
+
);
|
|
630
|
+
} else if (templateStatus === WHATSAPP_STATUSES.rejected) {
|
|
631
|
+
return (
|
|
632
|
+
<CapLabel type="label2">
|
|
633
|
+
{formatMessage(messages.rejectedStatusMsg)}
|
|
634
|
+
</CapLabel>
|
|
635
|
+
);
|
|
636
|
+
}
|
|
637
|
+
return (
|
|
638
|
+
<>
|
|
639
|
+
<CapLabel type="label2" style={{ fontWeight: 500 }}>
|
|
640
|
+
{formatMessage(messages.awaitingStatusMsg)}
|
|
641
|
+
</CapLabel>
|
|
642
|
+
<CapLabel
|
|
643
|
+
type="label2"
|
|
644
|
+
style={{ marginTop: CAP_SPACE_04, marginBottom: CAP_SPACE_04 }}
|
|
645
|
+
>
|
|
646
|
+
{formatMessage(messages.awaitingStatusDesc, {
|
|
647
|
+
date: moment(templateDate).format('D MMM YYYY'),
|
|
648
|
+
time: moment(templateDate).format('hh:mm A'),
|
|
649
|
+
})}
|
|
650
|
+
</CapLabel>
|
|
651
|
+
</>
|
|
652
|
+
);
|
|
653
|
+
};
|
|
654
|
+
|
|
655
|
+
// on change event of Text Area
|
|
656
|
+
const textAreaValueChange = ({ target: { value, id } }) => {
|
|
657
|
+
const numId = Number(id.slice(id.indexOf('_') + 1));
|
|
658
|
+
const arr = [...updatedSmsEditor];
|
|
659
|
+
|
|
660
|
+
//assign entered value to varMap
|
|
661
|
+
varMap[id] = value;
|
|
662
|
+
//based on entered value update updatedSmsEditor
|
|
663
|
+
if (value === '') {
|
|
664
|
+
arr[numId] = id.slice(0, id.indexOf('_'));
|
|
665
|
+
} else {
|
|
666
|
+
arr[numId] = value;
|
|
667
|
+
}
|
|
668
|
+
setUpdatedSmsEditor(arr);
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
const textAreaValue = (idValue) => {
|
|
672
|
+
if (idValue >= 0 && updatedSmsEditor) {
|
|
673
|
+
const value = updatedSmsEditor[idValue];
|
|
674
|
+
if (value && (value.match(validVarRegex) || []).length === 0) {
|
|
675
|
+
return value;
|
|
676
|
+
}
|
|
677
|
+
return '';
|
|
678
|
+
}
|
|
679
|
+
return '';
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
const renderedEditMessage = () => {
|
|
683
|
+
const renderArray = [];
|
|
684
|
+
if (tempMsgArray?.length !== 0) {
|
|
685
|
+
let varCount = 0;
|
|
686
|
+
tempMsgArray.forEach((elem, index) => {
|
|
687
|
+
if (elem.match(validVarRegex)?.length > 0) {
|
|
688
|
+
varCount += 1;
|
|
689
|
+
renderArray.push(
|
|
690
|
+
<TextArea
|
|
691
|
+
id={`${elem}_${index}`}
|
|
692
|
+
key={`${elem}_${index}`}
|
|
693
|
+
placeholder={formatMessage(messages.inputplaceHolderText, {
|
|
694
|
+
value: `{{${varCount}}}`,
|
|
695
|
+
})}
|
|
696
|
+
autosize={{ minRows: 1, maxRows: 3 }}
|
|
697
|
+
onChange={textAreaValueChange}
|
|
698
|
+
value={textAreaValue(index)}
|
|
699
|
+
onFocus={setTextAreaId}
|
|
700
|
+
disabled={templateStatus !== WHATSAPP_STATUSES.approved}
|
|
701
|
+
/>,
|
|
702
|
+
);
|
|
703
|
+
} else {
|
|
704
|
+
renderArray.push(
|
|
705
|
+
<CapHeading
|
|
706
|
+
key={`${elem}_${index}`}
|
|
707
|
+
type="h4"
|
|
708
|
+
className="whatsapp-edit-template-message-heading"
|
|
709
|
+
>
|
|
710
|
+
{elem}
|
|
711
|
+
</CapHeading>,
|
|
712
|
+
);
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
}
|
|
716
|
+
renderArray.push(renderUnsubscribeText());
|
|
717
|
+
return renderArray;
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
const editModeContent = (
|
|
721
|
+
<>
|
|
722
|
+
<CapAlert message={getAlertMessage()} type={getAlertType()} />
|
|
723
|
+
<CapRow className="whatsapp-render-heading">
|
|
724
|
+
<CapHeader
|
|
725
|
+
title={
|
|
726
|
+
<CapHeading type="h4">
|
|
727
|
+
{formatMessage(messages.templateMessageLabel)}
|
|
728
|
+
</CapHeading>
|
|
729
|
+
}
|
|
730
|
+
suffix={
|
|
731
|
+
templateStatus === WHATSAPP_STATUSES.approved && (
|
|
732
|
+
<TagList
|
|
733
|
+
label={formatMessage(messages.addLabels)}
|
|
734
|
+
onTagSelect={onTagSelect}
|
|
735
|
+
location={location}
|
|
736
|
+
tags={tags || []}
|
|
737
|
+
onContextChange={handleOnTagsContextChange}
|
|
738
|
+
injectedTags={injectedTags || {}}
|
|
739
|
+
/>
|
|
740
|
+
)
|
|
741
|
+
}
|
|
742
|
+
/>
|
|
743
|
+
</CapRow>
|
|
744
|
+
<CapTooltip
|
|
745
|
+
placement="bottom"
|
|
746
|
+
title={
|
|
747
|
+
templateStatus === WHATSAPP_STATUSES.approved
|
|
748
|
+
? ''
|
|
749
|
+
: templateStatus === WHATSAPP_STATUSES.rejected
|
|
750
|
+
? formatMessage(messages.disabledEditTooltip, {
|
|
751
|
+
status: templateStatus,
|
|
752
|
+
})
|
|
753
|
+
: formatMessage(messages.disabledEditTooltip, {
|
|
754
|
+
status: 'awaiting for approval',
|
|
755
|
+
})
|
|
756
|
+
}
|
|
757
|
+
>
|
|
758
|
+
<CapRow
|
|
759
|
+
className={`whatsapp-edit-template-message-input ${
|
|
760
|
+
templateStatus !== WHATSAPP_STATUSES.approved &&
|
|
761
|
+
'whatsapp-edit-disabled'
|
|
762
|
+
}`}
|
|
763
|
+
>
|
|
764
|
+
{renderedEditMessage()}
|
|
765
|
+
</CapRow>
|
|
766
|
+
</CapTooltip>
|
|
767
|
+
|
|
768
|
+
{renderMessageLength()}
|
|
769
|
+
</>
|
|
770
|
+
);
|
|
771
|
+
//edit methods end
|
|
772
|
+
|
|
773
|
+
//used by create and edit
|
|
325
774
|
const getPreviewSection = () => {
|
|
326
|
-
const templateMsg =
|
|
327
|
-
|
|
328
|
-
|
|
775
|
+
const templateMsg = (
|
|
776
|
+
<>
|
|
777
|
+
<CapLabel type="label5">
|
|
778
|
+
{isEditFlow ? updatedSmsEditor.join('') : templateMessage}
|
|
779
|
+
</CapLabel>
|
|
780
|
+
<CapLabel type="label11">
|
|
781
|
+
{formatMessage(messages.templateMessageUnsubscribeText)}
|
|
782
|
+
</CapLabel>
|
|
783
|
+
</>
|
|
784
|
+
);
|
|
329
785
|
return (
|
|
330
786
|
<TemplatePreview
|
|
331
787
|
channel={WHATSAPP}
|
|
@@ -334,101 +790,16 @@ export const Whatsapp = (props) => {
|
|
|
334
790
|
/>
|
|
335
791
|
);
|
|
336
792
|
};
|
|
793
|
+
|
|
337
794
|
return (
|
|
338
795
|
<CapSpin spinning={spin}>
|
|
339
796
|
<CapRow>
|
|
340
797
|
<CapColumn span={14}>
|
|
341
|
-
|
|
342
|
-
id={`whatsapp_template_name_input`}
|
|
343
|
-
onChange={onTemplateNameChange}
|
|
344
|
-
errorMessage={templateNameError}
|
|
345
|
-
placeholder={formatMessage(messages.templateNamePlaceholder)}
|
|
346
|
-
defaultValue={templateName || ''}
|
|
347
|
-
value={templateName || ''}
|
|
348
|
-
size="default"
|
|
349
|
-
label={
|
|
350
|
-
<CapHeader
|
|
351
|
-
title={
|
|
352
|
-
<>
|
|
353
|
-
{formatMessage(messages.templateNameLabel)}
|
|
354
|
-
<CapTooltipWithInfo
|
|
355
|
-
infoIconProps={{
|
|
356
|
-
style: { marginLeft: CAP_SPACE_04 },
|
|
357
|
-
}}
|
|
358
|
-
autoAdjustOverflow
|
|
359
|
-
title={
|
|
360
|
-
<FormattedMessage {...messages.templateNameTooltip} />
|
|
361
|
-
}
|
|
362
|
-
/>
|
|
363
|
-
</>
|
|
364
|
-
}
|
|
365
|
-
description={formatMessage(messages.templateNameDesc)}
|
|
366
|
-
size="regular"
|
|
367
|
-
/>
|
|
368
|
-
}
|
|
369
|
-
/>
|
|
370
|
-
<StyledSelect
|
|
371
|
-
id={'select-whatsapp-category'}
|
|
372
|
-
label={formatMessage(messages.templateCategoryLabel)}
|
|
373
|
-
options={templateCategoryOptions || []}
|
|
374
|
-
onChange={onTemplateCategoryChange}
|
|
375
|
-
value={templateCategory}
|
|
376
|
-
/>
|
|
377
|
-
{renderHeading('messageLanguageLabel')}
|
|
378
|
-
<CapInput
|
|
379
|
-
id={`whatsapp_template_language_input`}
|
|
380
|
-
defaultValue={'English'}
|
|
381
|
-
size="default"
|
|
382
|
-
disabled={true}
|
|
383
|
-
/>
|
|
384
|
-
{renderHeading('mediaLabel')}
|
|
385
|
-
<CapRadioGroup
|
|
386
|
-
options={mediaRadioOptions || []}
|
|
387
|
-
defaultValue={'text'}
|
|
388
|
-
/>
|
|
389
|
-
<CapHeading type="h4" className="whatsapp-render-heading">
|
|
390
|
-
<>
|
|
391
|
-
{formatMessage(messages.templateMessageLabel)}
|
|
392
|
-
<CapTooltipWithInfo
|
|
393
|
-
placement="right"
|
|
394
|
-
infoIconProps={{
|
|
395
|
-
style: { marginLeft: CAP_SPACE_04 },
|
|
396
|
-
}}
|
|
397
|
-
autoAdjustOverflow
|
|
398
|
-
title={
|
|
399
|
-
<FormattedMessage
|
|
400
|
-
{...messages.templateMessageTooltip}
|
|
401
|
-
values={{
|
|
402
|
-
br: <br />,
|
|
403
|
-
var: '{{1}}',
|
|
404
|
-
}}
|
|
405
|
-
/>
|
|
406
|
-
}
|
|
407
|
-
/>
|
|
408
|
-
</>
|
|
409
|
-
</CapHeading>
|
|
410
|
-
<CapRow className="whatsapp-template-message-input">
|
|
411
|
-
<TextArea
|
|
412
|
-
id={`whatsapp-template-message-input`}
|
|
413
|
-
autosize={{ minRows: 3, maxRows: 5 }}
|
|
414
|
-
placeholder={formatMessage(messages.templateMessagePlaceholder)}
|
|
415
|
-
onChange={onTemplateMessageChange}
|
|
416
|
-
errorMessage={
|
|
417
|
-
templateMessageError && (
|
|
418
|
-
<CapError className="whatsapp-template-message-error">
|
|
419
|
-
{templateMessageError}
|
|
420
|
-
</CapError>
|
|
421
|
-
)
|
|
422
|
-
}
|
|
423
|
-
value={templateMessage || ''}
|
|
424
|
-
/>
|
|
425
|
-
{renderUnsubscribeText()}
|
|
426
|
-
</CapRow>
|
|
427
|
-
{renderMessageLength()}
|
|
798
|
+
{isEditFlow ? editModeContent : createModeContent}
|
|
428
799
|
<div className="whatsapp-scroll-div" />
|
|
429
800
|
</CapColumn>
|
|
430
801
|
<CapColumn span={6}>
|
|
431
|
-
<CapRow>
|
|
802
|
+
<CapRow className={isEditFlow ? 'whatsapp-edit-alert-margin' : ''}>
|
|
432
803
|
<CapColumn span={24} offset={9}>
|
|
433
804
|
{getPreviewSection()}
|
|
434
805
|
</CapColumn>
|
|
@@ -436,26 +807,35 @@ export const Whatsapp = (props) => {
|
|
|
436
807
|
</CapColumn>
|
|
437
808
|
</CapRow>
|
|
438
809
|
<WhatsappFooter>
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
810
|
+
{!isEditFlow && (
|
|
811
|
+
<>
|
|
812
|
+
<CapButton
|
|
813
|
+
onClick={onDoneCallback()}
|
|
814
|
+
disabled={isDisableDone()}
|
|
815
|
+
className="whatsapp-create-btn"
|
|
816
|
+
>
|
|
817
|
+
<FormattedMessage {...messages.sendForApprovalButtonLabel} />
|
|
818
|
+
</CapButton>
|
|
819
|
+
<CapButton
|
|
820
|
+
onClick={handleClose}
|
|
821
|
+
className="whatsapp-cancel-btn"
|
|
822
|
+
type="secondary"
|
|
823
|
+
>
|
|
824
|
+
<FormattedMessage {...messages.cancelButtonLabel} />
|
|
825
|
+
</CapButton>
|
|
826
|
+
</>
|
|
827
|
+
)}
|
|
453
828
|
</WhatsappFooter>
|
|
454
829
|
</CapSpin>
|
|
455
830
|
);
|
|
456
831
|
};
|
|
457
832
|
|
|
458
|
-
const mapStateToProps = createStructuredSelector({
|
|
833
|
+
const mapStateToProps = createStructuredSelector({
|
|
834
|
+
editData: makeSelectWhatsapp(),
|
|
835
|
+
accountData: makeSelectAccount(),
|
|
836
|
+
metaEntities: makeSelectMetaEntities(),
|
|
837
|
+
injectedTags: setInjectedTags(),
|
|
838
|
+
});
|
|
459
839
|
|
|
460
840
|
const mapDispatchToProps = (dispatch) => ({
|
|
461
841
|
actions: bindActionCreators(WhatsappActions, dispatch),
|