@capillarytech/creatives-library 7.12.39 → 7.12.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. package/package.json +1 -1
  2. package/v2Components/CapWhatsappCTA/constants.js +0 -5
  3. package/v2Components/CapWhatsappCTA/index.js +13 -12
  4. package/v2Components/CapWhatsappCTA/index.scss +15 -0
  5. package/v2Components/CapWhatsappCTA/messages.js +0 -4
  6. package/v2Components/CapWhatsappCTA/tests/index.test.js +152 -0
  7. package/v2Components/TemplatePreview/index.js +5 -6
  8. package/v2Components/TemplatePreview/messages.js +0 -8
  9. package/v2Components/TemplatePreview/tests/__snapshots__/index.test.js.snap +190 -27
  10. package/v2Components/TemplatePreview/tests/index.test.js +52 -5
  11. package/v2Containers/CreativesContainer/index.js +7 -2
  12. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +30 -6
  13. package/v2Containers/CreativesContainer/tests/index.test.js +47 -14
  14. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +40 -240
  15. package/v2Containers/Whatsapp/constants.js +10 -7
  16. package/v2Containers/Whatsapp/index.js +100 -61
  17. package/v2Containers/Whatsapp/index.scss +6 -2
  18. package/v2Containers/Whatsapp/messages.js +6 -2
  19. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +94558 -28425
  20. package/v2Containers/Whatsapp/tests/__snapshots__/utils.test.js.snap +98 -8
  21. package/v2Containers/Whatsapp/tests/index.test.js +159 -18
  22. package/v2Containers/Whatsapp/tests/mockData.js +150 -89
  23. package/v2Containers/Whatsapp/tests/utils.test.js +8 -0
  24. package/v2Containers/Whatsapp/utils.js +49 -48
  25. package/v2Containers/mockdata.js +177 -5
@@ -203,13 +203,7 @@ export const Whatsapp = (props) => {
203
203
  if (btnType === WHATSAPP_BUTTON_TYPES.CTA && buttons.length > 0) {
204
204
  setCtadata(
205
205
  buttons.map((cta) => {
206
- const {
207
- index,
208
- type,
209
- text,
210
- phone_number = '',
211
- url = '',
212
- } = cta || {};
206
+ const { index, type, text, phone_number = '', url = '' } = cta;
213
207
  const obj = {
214
208
  index,
215
209
  text,
@@ -239,17 +233,27 @@ export const Whatsapp = (props) => {
239
233
  const computeTempMsgArray = () => {
240
234
  let msg = get(editContent, `languages[0].content`, '');
241
235
  const validVarArr = msg.match(validVarRegex) || [];
236
+ const unsubscribeRegex1 = /Click {{([1-9]|1[0-9])}} to unsubscribe/g;
237
+ const unsubscribeRegex2 = /Click {{unsubscribe}} to unsubscribe/g;
242
238
  const templateMessageArray = [];
243
239
  //removing $'' which was added for twilio enter handling
244
240
  // msg = msg.slice(2, -1);
245
- //removing Click {{unsubscribe}} to unsubscribe
246
- msg = msg.replace(
247
- `\nClick ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
248
- '',
249
- );
250
- //removing last var added for Click {{unsubscribe}} to unsubscribe
251
- if (isFullMode) {
252
- validVarArr.pop();
241
+ if (
242
+ msg.match(unsubscribeRegex1)?.length > 0 ||
243
+ msg.match(unsubscribeRegex2)?.length > 0
244
+ ) {
245
+ //removing Click {{([1-9]|1[0-9])}} to unsubscribe
246
+ msg = msg.replace(
247
+ `\nClick ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
248
+ '',
249
+ );
250
+ //removing Click {{unsubscribe}} to unsubscribe
251
+ msg = msg.replace(`\nClick {{unsubscribe}} to unsubscribe`, '');
252
+ //removing last var added for Click {{([1-9]|1[0-9])}} to unsubscribe
253
+ if (isFullMode) {
254
+ validVarArr.pop();
255
+ }
256
+ setUnsubscribeRequired(true);
253
257
  }
254
258
  while (msg.length !== 0) {
255
259
  //converting content string to an array split at var
@@ -524,43 +528,63 @@ export const Whatsapp = (props) => {
524
528
 
525
529
  const unsubscribeHandler = ({ target: { checked } }) => {
526
530
  setUnsubscribeRequired(checked);
531
+ const error = templateMessageErrorHandler(templateMessage);
532
+ setTemplateMessageError(error);
527
533
  };
528
534
 
529
- const renderUnsubscribeText = () => (
530
- <>
531
- <CapColumn span={12}>
532
- <CapCheckbox
533
- className={`whatsapp-create-unsubscribe-checkbox ${
534
- isEditFlow ? '' : 'whatsapp-create-unsubscribe'
535
- }`}
536
- onChange={unsubscribeHandler}
537
- checked={unsubscribeRequired}
538
- disabled={isEditFlow}
539
- autoFocus={true}
540
- >
541
- <CapTooltip
542
- placement="bottom"
543
- title={
544
- !isEditFlow && formatMessage(messages.unsubscribeTextTooltip)
545
- }
535
+ const renderUnsubscribeText = () => {
536
+ const isDisabled =
537
+ isEditFlow ||
538
+ templateMessage.length + UNSUBSCRIBE_TEXT_LENGTH >
539
+ TEMPLATE_MESSAGE_MAX_LENGTH;
540
+ return (
541
+ <>
542
+ <CapColumn span={12}>
543
+ <CapCheckbox
544
+ className={`whatsapp-unsubscribe-checkbox ${
545
+ isEditFlow
546
+ ? 'whatsapp-edit-unsubscribe-checkbox'
547
+ : 'whatsapp-create-unsubscribe-checkbox'
548
+ }`}
549
+ onChange={unsubscribeHandler}
550
+ checked={unsubscribeRequired}
551
+ disabled={isDisabled}
552
+ autoFocus={true}
546
553
  >
547
- <span className="whatsapp-render-unsubscribe-text">
548
- {formatMessage(messages.templateMessageUnsubscribeText)}
549
- </span>
550
- </CapTooltip>
551
- </CapCheckbox>
552
- </CapColumn>
553
- <CapColumn span={12}></CapColumn>
554
- </>
555
- );
554
+ <CapTooltip
555
+ placement="bottom"
556
+ title={
557
+ isDisabled &&
558
+ (isEditFlow
559
+ ? formatMessage(messages.unsubscribeTextTooltipEditFlow)
560
+ : formatMessage(messages.unsubscribeTextTooltipCreateFlow))
561
+ }
562
+ >
563
+ <span className="whatsapp-render-unsubscribe-text">
564
+ {formatMessage(messages.templateMessageUnsubscribeText)}
565
+ </span>
566
+ </CapTooltip>
567
+ </CapCheckbox>
568
+ </CapColumn>
569
+ <CapColumn span={12}></CapColumn>
570
+ </>
571
+ );
572
+ };
573
+
574
+ const computeTextLength = () => {
575
+ let whatsappContentLen = 0;
576
+ whatsappContentLen = isEditFlow
577
+ ? updatedSmsEditor.join('').length
578
+ : templateMessage.length;
579
+ whatsappContentLen += unsubscribeRequired ? UNSUBSCRIBE_TEXT_LENGTH : 0;
580
+ return whatsappContentLen;
581
+ };
556
582
 
557
583
  //used by create and edit
558
584
  const renderMessageLength = () => (
559
585
  <CapHeading type="label1" className="whatsapp-render-message-length">
560
586
  {formatMessage(messages.templateMessageLength, {
561
- currentLength: isEditFlow
562
- ? updatedSmsEditor?.join('')?.length + UNSUBSCRIBE_TEXT_LENGTH
563
- : templateMessage?.length + UNSUBSCRIBE_TEXT_LENGTH,
587
+ currentLength: computeTextLength(),
564
588
  maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
565
589
  })}
566
590
  </CapHeading>
@@ -641,7 +665,7 @@ export const Whatsapp = (props) => {
641
665
  if (value === '') {
642
666
  errorMessage = formatMessage(messages.emptyTemplateMessageErrorMessage);
643
667
  } else if (
644
- UNSUBSCRIBE_TEXT_LENGTH + value?.length >
668
+ value?.length + (unsubscribeRequired ? UNSUBSCRIBE_TEXT_LENGTH : 0) >
645
669
  TEMPLATE_MESSAGE_MAX_LENGTH
646
670
  ) {
647
671
  errorMessage = formatMessage(messages.templateMessageLengthError);
@@ -653,7 +677,7 @@ export const Whatsapp = (props) => {
653
677
  const invalidVarArr = value.match(invalidVarRegex) || [];
654
678
  const invalidVarSet = [...new Set(invalidVarArr)];
655
679
 
656
- const noContentBetweenVars = /}}[^a-zA-Z]*{{/g;
680
+ const noContentBetweenVars = /}}\s*{{/g;
657
681
  const moreThanTwoBrackets = /{{3,}([1-9]|1[0-9])}{3,}/g;
658
682
 
659
683
  if (validVarArr?.length > 0 || invalidVarArr?.length > 0) {
@@ -684,19 +708,33 @@ export const Whatsapp = (props) => {
684
708
  }
685
709
  return errorMessage;
686
710
  };
687
- // prettier-ignore
688
- const getPayloadContent = () =>
689
- isEditFlow && !isFullMode
690
- ? `${updatedSmsEditor.join('')}\n${formatMessage(
711
+
712
+ const getPayloadContent = () => {
713
+ if (isEditFlow && !isFullMode) {
714
+ //campaigns edit flow + unsubscribeRequired
715
+ if (unsubscribeRequired) {
716
+ return `${updatedSmsEditor.join('')}\n${formatMessage(
691
717
  messages.templateMessageUnsubscribeText,
692
- )}`
693
- : `${templateMessage}\n${formatMessage(messages.modifiedUnsubscribeText, {
694
- value: `{{${addedVarCount + 1}}}`,
695
- })}`;
718
+ )}`;
719
+ }
720
+ //campaigns edit flow + unsubscribeNotRequired
721
+ return updatedSmsEditor.join('');
722
+ } else if (unsubscribeRequired) {
723
+ //creatives create and edit flow + unsubscribeRequired
724
+ return `${templateMessage}\n${formatMessage(
725
+ messages.modifiedUnsubscribeText,
726
+ {
727
+ value: `{{${addedVarCount + 1}}}`,
728
+ },
729
+ )}`;
730
+ }
731
+ //creatives create and edit flow + unsubscribeNotRequired
732
+ return templateMessage;
733
+ };
696
734
 
697
735
  const getCtaPayload = () =>
698
736
  ctaData.map((cta) => {
699
- const { index, ctaType, text, phone_number, urlType, url } = cta || {};
737
+ const { index, ctaType, text, phone_number, urlType, url } = cta;
700
738
  if (ctaType === PHONE_NUMBER) {
701
739
  return {
702
740
  index,
@@ -1078,6 +1116,7 @@ export const Whatsapp = (props) => {
1078
1116
  }
1079
1117
  return <CapError>{tagError}</CapError>;
1080
1118
  };
1119
+
1081
1120
  const editModeContent = (
1082
1121
  <>
1083
1122
  {templateStatus && (
@@ -1139,9 +1178,11 @@ export const Whatsapp = (props) => {
1139
1178
  <CapLabel type="label5">
1140
1179
  {isEditFlow ? updatedSmsEditor.join('') : templateMessage}
1141
1180
  </CapLabel>
1142
- <CapLabel type="label5">
1143
- {formatMessage(messages.templateMessageUnsubscribeText)}
1144
- </CapLabel>
1181
+ {unsubscribeRequired && (
1182
+ <CapLabel type="label5">
1183
+ {formatMessage(messages.templateMessageUnsubscribeText)}
1184
+ </CapLabel>
1185
+ )}
1145
1186
  </>
1146
1187
  );
1147
1188
  return (
@@ -1153,9 +1194,7 @@ export const Whatsapp = (props) => {
1153
1194
  ctaData,
1154
1195
  }),
1155
1196
  }}
1156
- whatsappContentLen={
1157
- isEditFlow ? updatedSmsEditor.join('').length : templateMessage.length
1158
- }
1197
+ whatsappContentLen={computeTextLength()}
1159
1198
  whatsappAccountName={accountName}
1160
1199
  />
1161
1200
  );
@@ -10,17 +10,21 @@
10
10
  margin-bottom: 6px;
11
11
  }
12
12
 
13
- .whatsapp-create-unsubscribe-checkbox {
13
+ .whatsapp-unsubscribe-checkbox {
14
14
  .ant-checkbox-inner {
15
15
  height: 16px;
16
16
  width: 16px;
17
17
  }
18
18
  }
19
19
 
20
- .whatsapp-create-unsubscribe {
20
+ .whatsapp-create-unsubscribe-checkbox {
21
21
  margin: $CAP_SPACE_08 0px $CAP_SPACE_08 16px;
22
22
  }
23
23
 
24
+ .whatsapp-edit-unsubscribe-checkbox {
25
+ margin: $CAP_SPACE_08 0px;
26
+ }
27
+
24
28
  .whatsapp-render-unsubscribe-text {
25
29
  color: $FONT_COLOR_02;
26
30
  font-size: 14px;
@@ -127,10 +127,14 @@ export default defineMessages({
127
127
  id: `${prefix}.modifiedUnsubscribeText`,
128
128
  defaultMessage: 'Click {value} to unsubscribe',
129
129
  },
130
- unsubscribeTextTooltip: {
131
- id: `${prefix}.unsubscribeTextTooltip`,
130
+ unsubscribeTextTooltipEditFlow: {
131
+ id: `${prefix}.unsubscribeTextTooltipEditFlow`,
132
132
  defaultMessage: 'This is non-editable',
133
133
  },
134
+ unsubscribeTextTooltipCreateFlow: {
135
+ id: `${prefix}.unsubscribeTextTooltipCreateFlow`,
136
+ defaultMessage: 'To enable the checkbox, reduce the message character count to 988',
137
+ },
134
138
  repetativeVars: {
135
139
  id: `${prefix}.repetativeVars`,
136
140
  defaultMessage: 'Variables cannot be repeated',