@capillarytech/creatives-library 7.12.38 → 7.12.40
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/CapWhatsappCTA/messages.js +1 -1
- package/v2Components/TemplatePreview/_templatePreview.scss +1 -0
- package/v2Components/TemplatePreview/index.js +5 -6
- package/v2Components/TemplatePreview/messages.js +0 -8
- package/v2Components/TemplatePreview/tests/__snapshots__/index.test.js.snap +3 -12
- package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +1 -6
- package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +40 -240
- package/v2Containers/Whatsapp/index.js +86 -41
- package/v2Containers/Whatsapp/index.scss +17 -3
- package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +19589 -19483
- package/v2Containers/Whatsapp/tests/__snapshots__/utils.test.js.snap +2 -12
- package/v2Containers/Whatsapp/utils.js +46 -47
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
/* eslint-disable react/jsx-boolean-value */
|
|
1
2
|
/* eslint-disable camelcase */
|
|
2
3
|
/* eslint-disable no-undef */
|
|
3
4
|
import React, { useState, useEffect } from 'react';
|
|
@@ -21,6 +22,7 @@ import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
|
|
|
21
22
|
import CapButton from '@capillarytech/cap-ui-library/CapButton';
|
|
22
23
|
import CapNotification from '@capillarytech/cap-ui-library/CapNotification';
|
|
23
24
|
import CapAlert from '@capillarytech/cap-ui-library/CapAlert';
|
|
25
|
+
import CapCheckbox from '@capillarytech/cap-ui-library/CapCheckbox';
|
|
24
26
|
import moment from 'moment';
|
|
25
27
|
import {
|
|
26
28
|
CAP_SPACE_04,
|
|
@@ -109,6 +111,7 @@ export const Whatsapp = (props) => {
|
|
|
109
111
|
const [accessToken, setAccessToken] = useState('');
|
|
110
112
|
const [accountName, setAccountName] = useState('');
|
|
111
113
|
const [spin, setSpin] = useState(false);
|
|
114
|
+
const [unsubscribeRequired, setUnsubscribeRequired] = useState(false);
|
|
112
115
|
//for edit only
|
|
113
116
|
const [isEditFlow, setEditFlow] = useState(false);
|
|
114
117
|
const [templateDate, setTemplateDate] = useState('');
|
|
@@ -236,17 +239,21 @@ export const Whatsapp = (props) => {
|
|
|
236
239
|
const computeTempMsgArray = () => {
|
|
237
240
|
let msg = get(editContent, `languages[0].content`, '');
|
|
238
241
|
const validVarArr = msg.match(validVarRegex) || [];
|
|
242
|
+
const unsubscribePresent = /Click {{([1-9]|1[0-9])}} to unsubscribe/g;
|
|
239
243
|
const templateMessageArray = [];
|
|
240
244
|
//removing $'' which was added for twilio enter handling
|
|
241
245
|
// msg = msg.slice(2, -1);
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
246
|
+
if (msg.match(unsubscribePresent)?.length > 0) {
|
|
247
|
+
//removing Click {{unsubscribe}} to unsubscribe
|
|
248
|
+
msg = msg.replace(
|
|
249
|
+
`\nClick ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
|
|
250
|
+
'',
|
|
251
|
+
);
|
|
252
|
+
//removing last var added for Click {{unsubscribe}} to unsubscribe
|
|
253
|
+
if (isFullMode) {
|
|
254
|
+
validVarArr.pop();
|
|
255
|
+
}
|
|
256
|
+
setUnsubscribeRequired(true);
|
|
250
257
|
}
|
|
251
258
|
while (msg.length !== 0) {
|
|
252
259
|
//converting content string to an array split at var
|
|
@@ -519,35 +526,60 @@ export const Whatsapp = (props) => {
|
|
|
519
526
|
</CapHeading>
|
|
520
527
|
);
|
|
521
528
|
|
|
529
|
+
const unsubscribeHandler = ({ target: { checked } }) => {
|
|
530
|
+
setUnsubscribeRequired(checked);
|
|
531
|
+
const error = templateMessageErrorHandler(templateMessage);
|
|
532
|
+
setTemplateMessageError(error);
|
|
533
|
+
};
|
|
534
|
+
|
|
522
535
|
const renderUnsubscribeText = () => (
|
|
523
536
|
<>
|
|
524
537
|
<CapColumn span={12}>
|
|
525
|
-
<
|
|
526
|
-
|
|
527
|
-
|
|
538
|
+
<CapCheckbox
|
|
539
|
+
className={`whatsapp-unsubscribe-checkbox ${
|
|
540
|
+
isEditFlow
|
|
541
|
+
? 'whatsapp-edit-unsubscribe-checkbox'
|
|
542
|
+
: 'whatsapp-create-unsubscribe-checkbox'
|
|
543
|
+
}`}
|
|
544
|
+
onChange={unsubscribeHandler}
|
|
545
|
+
checked={unsubscribeRequired}
|
|
546
|
+
disabled={
|
|
547
|
+
isEditFlow ||
|
|
548
|
+
templateMessage.length + UNSUBSCRIBE_TEXT_LENGTH >
|
|
549
|
+
TEMPLATE_MESSAGE_MAX_LENGTH
|
|
550
|
+
}
|
|
551
|
+
autoFocus={true}
|
|
528
552
|
>
|
|
529
|
-
<
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
: 'whatsapp-edit-render-unsubscribe-text'
|
|
553
|
+
<CapTooltip
|
|
554
|
+
placement="bottom"
|
|
555
|
+
title={
|
|
556
|
+
!isEditFlow && formatMessage(messages.unsubscribeTextTooltip)
|
|
534
557
|
}
|
|
535
558
|
>
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
559
|
+
<span className="whatsapp-render-unsubscribe-text">
|
|
560
|
+
{formatMessage(messages.templateMessageUnsubscribeText)}
|
|
561
|
+
</span>
|
|
562
|
+
</CapTooltip>
|
|
563
|
+
</CapCheckbox>
|
|
539
564
|
</CapColumn>
|
|
540
565
|
<CapColumn span={12}></CapColumn>
|
|
541
566
|
</>
|
|
542
567
|
);
|
|
543
568
|
|
|
569
|
+
const computeLength = () => {
|
|
570
|
+
let whatsappContentLen = 0;
|
|
571
|
+
whatsappContentLen = isEditFlow
|
|
572
|
+
? updatedSmsEditor.join('').length
|
|
573
|
+
: templateMessage.length;
|
|
574
|
+
whatsappContentLen += unsubscribeRequired ? UNSUBSCRIBE_TEXT_LENGTH : 0;
|
|
575
|
+
return whatsappContentLen;
|
|
576
|
+
};
|
|
577
|
+
|
|
544
578
|
//used by create and edit
|
|
545
579
|
const renderMessageLength = () => (
|
|
546
580
|
<CapHeading type="label1" className="whatsapp-render-message-length">
|
|
547
581
|
{formatMessage(messages.templateMessageLength, {
|
|
548
|
-
currentLength:
|
|
549
|
-
? updatedSmsEditor?.join('')?.length + UNSUBSCRIBE_TEXT_LENGTH
|
|
550
|
-
: templateMessage?.length + UNSUBSCRIBE_TEXT_LENGTH,
|
|
582
|
+
currentLength: computeLength(),
|
|
551
583
|
maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
|
|
552
584
|
})}
|
|
553
585
|
</CapHeading>
|
|
@@ -628,7 +660,7 @@ export const Whatsapp = (props) => {
|
|
|
628
660
|
if (value === '') {
|
|
629
661
|
errorMessage = formatMessage(messages.emptyTemplateMessageErrorMessage);
|
|
630
662
|
} else if (
|
|
631
|
-
|
|
663
|
+
value?.length + (unsubscribeRequired ? UNSUBSCRIBE_TEXT_LENGTH : 0) >
|
|
632
664
|
TEMPLATE_MESSAGE_MAX_LENGTH
|
|
633
665
|
) {
|
|
634
666
|
errorMessage = formatMessage(messages.templateMessageLengthError);
|
|
@@ -640,7 +672,7 @@ export const Whatsapp = (props) => {
|
|
|
640
672
|
const invalidVarArr = value.match(invalidVarRegex) || [];
|
|
641
673
|
const invalidVarSet = [...new Set(invalidVarArr)];
|
|
642
674
|
|
|
643
|
-
const noContentBetweenVars = /}}
|
|
675
|
+
const noContentBetweenVars = /}}\s*{{/g;
|
|
644
676
|
const moreThanTwoBrackets = /{{3,}([1-9]|1[0-9])}{3,}/g;
|
|
645
677
|
|
|
646
678
|
if (validVarArr?.length > 0 || invalidVarArr?.length > 0) {
|
|
@@ -671,15 +703,29 @@ export const Whatsapp = (props) => {
|
|
|
671
703
|
}
|
|
672
704
|
return errorMessage;
|
|
673
705
|
};
|
|
674
|
-
|
|
675
|
-
const getPayloadContent = () =>
|
|
676
|
-
isEditFlow && !isFullMode
|
|
677
|
-
|
|
706
|
+
|
|
707
|
+
const getPayloadContent = () => {
|
|
708
|
+
if (isEditFlow && !isFullMode) {
|
|
709
|
+
//campaigns edit flow + unsubscribeRequired
|
|
710
|
+
if (unsubscribeRequired) {
|
|
711
|
+
return `${updatedSmsEditor.join('')}\n${formatMessage(
|
|
678
712
|
messages.templateMessageUnsubscribeText,
|
|
679
|
-
)}
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
713
|
+
)}`;
|
|
714
|
+
}
|
|
715
|
+
//campaigns edit flow + unsubscribeNotRequired
|
|
716
|
+
return updatedSmsEditor.join('');
|
|
717
|
+
} else if (unsubscribeRequired) {
|
|
718
|
+
//creatives create and edit flow + unsubscribeRequired
|
|
719
|
+
return `${templateMessage}\n${formatMessage(
|
|
720
|
+
messages.modifiedUnsubscribeText,
|
|
721
|
+
{
|
|
722
|
+
value: `{{${addedVarCount + 1}}}`,
|
|
723
|
+
},
|
|
724
|
+
)}`;
|
|
725
|
+
}
|
|
726
|
+
//creatives create and edit flow + unsubscribeNotRequired
|
|
727
|
+
return templateMessage;
|
|
728
|
+
};
|
|
683
729
|
|
|
684
730
|
const getCtaPayload = () =>
|
|
685
731
|
ctaData.map((cta) => {
|
|
@@ -1065,6 +1111,7 @@ export const Whatsapp = (props) => {
|
|
|
1065
1111
|
}
|
|
1066
1112
|
return <CapError>{tagError}</CapError>;
|
|
1067
1113
|
};
|
|
1114
|
+
|
|
1068
1115
|
const editModeContent = (
|
|
1069
1116
|
<>
|
|
1070
1117
|
{templateStatus && (
|
|
@@ -1113,9 +1160,7 @@ export const Whatsapp = (props) => {
|
|
|
1113
1160
|
placement="bottom"
|
|
1114
1161
|
title={formatMessage(messages.disabledButtonsSection)}
|
|
1115
1162
|
>
|
|
1116
|
-
<CapRow>
|
|
1117
|
-
{renderButtonsSection()}
|
|
1118
|
-
</CapRow>
|
|
1163
|
+
<CapRow>{renderButtonsSection()}</CapRow>
|
|
1119
1164
|
</CapTooltip>
|
|
1120
1165
|
</>
|
|
1121
1166
|
);
|
|
@@ -1128,9 +1173,11 @@ export const Whatsapp = (props) => {
|
|
|
1128
1173
|
<CapLabel type="label5">
|
|
1129
1174
|
{isEditFlow ? updatedSmsEditor.join('') : templateMessage}
|
|
1130
1175
|
</CapLabel>
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1176
|
+
{unsubscribeRequired && (
|
|
1177
|
+
<CapLabel type="label5">
|
|
1178
|
+
{formatMessage(messages.templateMessageUnsubscribeText)}
|
|
1179
|
+
</CapLabel>
|
|
1180
|
+
)}
|
|
1134
1181
|
</>
|
|
1135
1182
|
);
|
|
1136
1183
|
return (
|
|
@@ -1142,9 +1189,7 @@ export const Whatsapp = (props) => {
|
|
|
1142
1189
|
ctaData,
|
|
1143
1190
|
}),
|
|
1144
1191
|
}}
|
|
1145
|
-
whatsappContentLen={
|
|
1146
|
-
isEditFlow ? updatedSmsEditor.join('').length : templateMessage.length
|
|
1147
|
-
}
|
|
1192
|
+
whatsappContentLen={computeLength()}
|
|
1148
1193
|
whatsappAccountName={accountName}
|
|
1149
1194
|
/>
|
|
1150
1195
|
);
|
|
@@ -10,13 +10,27 @@
|
|
|
10
10
|
margin-bottom: 6px;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
.whatsapp-
|
|
14
|
-
|
|
13
|
+
.whatsapp-unsubscribe-checkbox {
|
|
14
|
+
.ant-checkbox-inner {
|
|
15
|
+
height: 16px;
|
|
16
|
+
width: 16px;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.whatsapp-create-unsubscribe-checkbox {
|
|
15
21
|
margin: $CAP_SPACE_08 0px $CAP_SPACE_08 16px;
|
|
16
22
|
}
|
|
17
23
|
|
|
18
|
-
.whatsapp-edit-
|
|
24
|
+
.whatsapp-edit-unsubscribe-checkbox {
|
|
25
|
+
margin: $CAP_SPACE_08 0px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.whatsapp-render-unsubscribe-text {
|
|
19
29
|
color: $FONT_COLOR_02;
|
|
30
|
+
font-size: 14px;
|
|
31
|
+
font-weight: normal;
|
|
32
|
+
line-height: 24px;
|
|
33
|
+
margin-left: -8px;
|
|
20
34
|
}
|
|
21
35
|
|
|
22
36
|
.whatsapp-render-message-length {
|