@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.
@@ -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
- //removing Click {{unsubscribe}} to unsubscribe
243
- msg = msg.replace(
244
- `\nClick ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
245
- '',
246
- );
247
- //removing last var added for Click {{unsubscribe}} to unsubscribe
248
- if (isFullMode) {
249
- validVarArr.pop();
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
- <CapTooltip
526
- placement="bottom"
527
- title={!isEditFlow && formatMessage(messages.unsubscribeTextTooltip)}
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
- <CapHeading
530
- className={
531
- !isEditFlow
532
- ? 'whatsapp-create-render-unsubscribe-text'
533
- : 'whatsapp-edit-render-unsubscribe-text'
553
+ <CapTooltip
554
+ placement="bottom"
555
+ title={
556
+ !isEditFlow && formatMessage(messages.unsubscribeTextTooltip)
534
557
  }
535
558
  >
536
- {formatMessage(messages.templateMessageUnsubscribeText)}
537
- </CapHeading>
538
- </CapTooltip>
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: isEditFlow
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
- UNSUBSCRIBE_TEXT_LENGTH + value?.length >
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 = /}}[^a-zA-Z]*{{/g;
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
- // prettier-ignore
675
- const getPayloadContent = () =>
676
- isEditFlow && !isFullMode
677
- ? `${updatedSmsEditor.join('')}\n${formatMessage(
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
- : `${templateMessage}\n${formatMessage(messages.modifiedUnsubscribeText, {
681
- value: `{{${addedVarCount + 1}}}`,
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
- <CapLabel type="label5">
1132
- {formatMessage(messages.templateMessageUnsubscribeText)}
1133
- </CapLabel>
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-create-render-unsubscribe-text {
14
- color: $FONT_COLOR_02;
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-render-unsubscribe-text {
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 {