@capillarytech/creatives-library 7.17.82-alpha.0 → 7.17.82

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.
@@ -70,10 +70,11 @@ import {
70
70
  DOCUMENT_FORMAT,
71
71
  DOCUMENT_SIZE,
72
72
  TEMPLATE_HEADER_MAX_LENGTH,
73
- TEMPLATE_BUTTON_TEXT_MAX_LENGTH,
73
+ QUICK_REPLY_BUTTON_TEXT_MAX_LENGTH,
74
74
  HEADER_TEXT,
75
75
  FOOTER_TEXT,
76
- MESSAGE_TEXT
76
+ MESSAGE_TEXT,
77
+ BUTTON_TEXT
77
78
  } from './constants';
78
79
  import { DATE_DISPLAY_FORMAT, TIME_DISPLAY_FORMAT } from '../App/constants';
79
80
  import messages from './messages';
@@ -135,11 +136,11 @@ export const Whatsapp = (props) => {
135
136
  WHATSAPP_MEDIA_TYPES.TEXT,
136
137
  );
137
138
  const [templateMessage, setTemplateMessage] = useState('');
139
+ const [templateMessageError, setTemplateMessageError] = useState(false);
138
140
  const [templateHeader, setTemplateHeader] = useState('');
139
141
  const [templateHeaderError, setTemplateHeaderError] = useState(false);
140
142
  const [templateFooter, setTemplateFooter] = useState('');
141
143
  const [templateFooterError, setTemplateFooterError] = useState(false);
142
- const [templateMessageError, setTemplateMessageError] = useState(false);
143
144
  const [addedVarCount, setAddedVarCount] = useState(0);
144
145
  const [accountId, setAccountId] = useState('');
145
146
  const [accessToken, setAccessToken] = useState('');
@@ -177,11 +178,12 @@ export const Whatsapp = (props) => {
177
178
  const [tempHeaderData, setTempHeaderData] = useState([]);
178
179
  const [headerVarMappedData, setHeaderVarMappedData] = useState({});
179
180
  const [updatedHeaderData, setUpdatedHeaderData] = useState([]);
180
- const [headerTextAreaId, setHeaderTextAreaId] = useState();
181
+ const [headerTextAreaId, setHeaderTextAreaId] = useState('');
181
182
  const [isHeaderTagValidationError, updateIsHeaderTagValidationError] =
182
183
  useState(false);
183
184
 
184
185
  const validVarRegex = /{{([1-9]|1[0-9])}}/g;
186
+ const headerValidVarRegex = /{{(1)}}/g;
185
187
 
186
188
  const isBtnTypeCta = buttonType === WHATSAPP_BUTTON_TYPES.CTA;
187
189
  const isBtnTypeQuickReply = buttonType === WHATSAPP_BUTTON_TYPES.QUICK_REPLY;
@@ -189,6 +191,7 @@ export const Whatsapp = (props) => {
189
191
  const isMediaTypeImage = templateMediaType === WHATSAPP_MEDIA_TYPES.IMAGE;
190
192
  const isMediaTypeVideo = templateMediaType === WHATSAPP_MEDIA_TYPES.VIDEO;
191
193
  const isMediaTypeDoc = templateMediaType === WHATSAPP_MEDIA_TYPES.DOCUMENT;
194
+ const isHostIsNotTwilio = host !== HOST_TWILIO;
192
195
  const WhatsappFooter = styled.div`
193
196
  background-color: ${CAP_WHITE};
194
197
  position: fixed;
@@ -314,35 +317,41 @@ export const Whatsapp = (props) => {
314
317
  }),
315
318
  );
316
319
  }
317
- if (btnType === WHATSAPP_BUTTON_TYPES.QUICK_REPLY && buttons.length > 0) {
320
+ if (btnType === WHATSAPP_BUTTON_TYPES.QUICK_REPLY && buttons?.length > 0) {
318
321
  setQuickReplyData(buttons);
319
322
  }
320
323
  computeTempMsgArray();
321
- if (header) {
324
+ if (header && (mediaType === WHATSAPP_MEDIA_TYPES.TEXT && isHostIsNotTwilio)) {
322
325
  computeHeaderMsgArray();
323
326
  }
324
327
  }
325
328
  }, [editData.templateDetails || templateData]);
326
329
 
327
- const computeHeaderMsgArray = () => {
328
- let msg = get(editContent, `whatsappMedia.header`, '');
329
- const validVarArr = msg.match(validVarRegex) || [];
330
- const templateHeaderArray = [];
331
- while (msg.length !== 0) {
330
+ const converStringToVarArr = (validVarArr, content) => {
331
+ const templateVarArray = [];
332
+ while (content?.length !== 0) {
332
333
  //converting content string to an array split at var
333
- const index = msg.indexOf(validVarArr[0]);
334
+ const index = content.indexOf(validVarArr?.[0]);
334
335
  if (index !== -1) {
335
- templateHeaderArray.push(msg.substring(0, index)); //push string before var
336
- templateHeaderArray.push(validVarArr[0]); //push var
337
- msg = msg.substring(index + validVarArr[0].length, msg.length); //remaining str
338
- validVarArr.shift(); //remove considered var
336
+ templateVarArray.push(content.substring(0, index)); //push string before var
337
+ templateVarArray.push(validVarArr?.[0]); //push var
338
+ content = content.substring(index + validVarArr?.[0]?.length, content?.length); //remaining str
339
+ validVarArr?.shift(); //remove considered var
339
340
  } else {
340
- templateHeaderArray.push(msg); //remaining str
341
+ templateVarArray.push(content); //remaining str
341
342
  break;
342
343
  }
343
344
  }
345
+ return templateVarArray;
346
+ }
347
+
348
+ const computeHeaderMsgArray = () => {
349
+ let msg = get(editContent, `whatsappMedia.header`, '');
350
+ const validVarArr = msg?.match(headerValidVarRegex) || [];
351
+ //conerting msg string to variable arr
352
+ const templateHeaderArray = converStringToVarArr(validVarArr, msg);
344
353
  setTempHeaderData(templateHeaderArray);
345
- if (templateHeaderArray.length !== 0) {
354
+ if (templateHeaderArray?.length !== 0) {
346
355
  let headerVarMap = {};
347
356
  const {
348
357
  whatsappMedia: { headerVarMapped = {} },
@@ -350,11 +359,11 @@ export const Whatsapp = (props) => {
350
359
  if (!isEmpty(headerVarMapped)) {
351
360
  headerVarMap = cloneDeep(headerVarMapped);
352
361
  } else {
353
- for (let i = 0; i < templateHeaderArray.length; i += 1) {
354
- if (templateHeaderArray[i].match(validVarRegex)?.length > 0) {
355
- headerVarMap[`${templateHeaderArray[i]}_${i}`] = '';
362
+ templateHeaderArray?.forEach((headerValue, i) => {
363
+ if (headerValue?.match(headerValidVarRegex)?.length > 0) {
364
+ headerVarMap[`${headerValue}_${i}`] = '';
356
365
  }
357
- }
366
+ })
358
367
  }
359
368
  const arr = [...templateHeaderArray];
360
369
  for (const key in headerVarMap) {
@@ -372,7 +381,6 @@ export const Whatsapp = (props) => {
372
381
  const validVarArr = msg.match(validVarRegex) || [];
373
382
  const unsubscribeRegex1 = /Click {{([1-9]|1[0-9])}} to unsubscribe/g;
374
383
  const unsubscribeRegex2 = /Click {{unsubscribe}} to unsubscribe/g;
375
- const templateMessageArray = [];
376
384
  //removing $'' which was added for twilio enter handling
377
385
  // msg = msg.slice(2, -1);
378
386
  if (
@@ -392,19 +400,8 @@ export const Whatsapp = (props) => {
392
400
  }
393
401
  setUnsubscribeRequired(true);
394
402
  }
395
- while (msg.length !== 0) {
396
- //converting content string to an array split at var
397
- const index = msg.indexOf(validVarArr[0]);
398
- if (index !== -1) {
399
- templateMessageArray.push(msg.substring(0, index)); //push string before var
400
- templateMessageArray.push(validVarArr[0]); //push var
401
- msg = msg.substring(index + validVarArr[0].length, msg.length); //remaining str
402
- validVarArr.shift(); //remove considered var
403
- } else {
404
- templateMessageArray.push(msg); //remaining str
405
- break;
406
- }
407
- }
403
+ //conerting msg string to variable arr
404
+ const templateMessageArray = converStringToVarArr(validVarArr, msg);
408
405
  updateTempMsgArray(templateMessageArray.filter((i) => i === 0 || i));
409
406
  };
410
407
 
@@ -468,45 +465,35 @@ export const Whatsapp = (props) => {
468
465
  }
469
466
  }, [metaEntities, isEditFlow]);
470
467
 
471
- //performs tag validation
472
- useEffect(() => {
473
- if (
474
- !isFullMode &&
475
- updatedSmsEditor?.length > 0 &&
476
- !updatedSmsEditor.join('').match(validVarRegex)
477
- ) {
468
+ const tagValidation = (contentData, regex, type) => {
469
+ if (contentData?.length > 0 && !contentData.join("").match(regex)) {
478
470
  tagValidationResponse =
479
471
  validateTags({
480
- content: updatedSmsEditor.join(''),
472
+ content: contentData.join(""),
481
473
  tagsParam: tags,
482
474
  injectedTagsParams: injectedTags,
483
475
  location,
484
476
  tagModule: getDefaultTags,
485
477
  }) || {};
486
- updateIsTagValidationError(
487
- tagValidationResponse.unsupportedTags.length > 0,
488
- );
478
+ type === HEADER_TEXT
479
+ ? updateIsHeaderTagValidationError(
480
+ tagValidationResponse?.unsupportedTags?.length > 0
481
+ )
482
+ : updateIsTagValidationError(
483
+ tagValidationResponse?.unsupportedTags?.length > 0
484
+ );
489
485
  }
486
+ };
487
+
488
+ //performs tag validation
489
+ useEffect(() => {
490
+ if (!isFullMode)
491
+ tagValidation(updatedSmsEditor, validVarRegex, MESSAGE_TEXT);
490
492
  }, [updatedSmsEditor, tags]);
491
493
 
492
494
  useEffect(() => {
493
- if (
494
- !isFullMode &&
495
- updatedHeaderData?.length > 0 &&
496
- !updatedHeaderData.join('').match(validVarRegex)
497
- ) {
498
- headerTagValidationResponse =
499
- validateTags({
500
- content: updatedHeaderData.join(''),
501
- tagsParam: tags,
502
- injectedTagsParams: injectedTags,
503
- location,
504
- tagModule: getDefaultTags,
505
- }) || {};
506
- updateIsHeaderTagValidationError(
507
- headerTagValidationResponse.unsupportedTags.length > 0
508
- );
509
- }
495
+ if (!isFullMode)
496
+ tagValidation(updatedHeaderData, headerValidVarRegex, HEADER_TEXT);
510
497
  }, [updatedHeaderData, tags]);
511
498
 
512
499
  const handleOnTagsContextChange = (data) => {
@@ -524,43 +511,59 @@ export const Whatsapp = (props) => {
524
511
  globalActions.fetchSchemaForEntity(query);
525
512
  };
526
513
 
527
- const onTagSelect = (data) => {
528
- if (varMap && updatedSmsEditor) {
529
- const numId = Number(textAreaId?.slice(textAreaId?.indexOf('_') + 1));
530
- if (numId != NaN) {
531
- const arr = [...updatedSmsEditor];
514
+ const onTagSelect = (tagSelectData) => {
515
+ const {
516
+ data = "",
517
+ type = MESSAGE_TEXT,
518
+ mapData = {},
519
+ updatedData = [],
520
+ areaId = "",
521
+ regex,
522
+ } = tagSelectData;
523
+ if (mapData && updatedData) {
524
+ const numId = Number(areaId?.slice(areaId?.indexOf("_") + 1));
525
+ if (!isNaN(numId)) {
526
+ const arr = [...updatedData];
532
527
  //when trying to insert tag in empty textarea,{#var#} is replaced with "" and then tag is added
533
- if (arr[numId]?.match(validVarRegex)?.length > 0) {
534
- arr[numId] = '';
528
+ if (arr?.[numId]?.match(regex)?.length > 0) {
529
+ arr[numId] = "";
535
530
  }
536
531
  const messageData = `${arr[numId]}{{${data}}}`;
537
532
  arr[numId] = messageData;
538
- varMap[textAreaId] = messageData;
539
- setUpdatedSmsEditor(arr);
533
+ if (type === HEADER_TEXT) {
534
+ setHeaderVarMappedData((prevState) => ({
535
+ ...prevState,
536
+ [areaId]: messageData,
537
+ }));
538
+ setUpdatedHeaderData(arr);
539
+ } else {
540
+ varMap[areaId] = messageData;
541
+ setUpdatedSmsEditor(arr);
542
+ }
540
543
  }
541
544
  }
542
545
  };
543
546
 
547
+ const onMessageTagSelect = (data) => {
548
+ onTagSelect({
549
+ data,
550
+ type: MESSAGE_TEXT,
551
+ mapData: varMap,
552
+ updatedData: updatedSmsEditor,
553
+ areaId: textAreaId,
554
+ regex: validVarRegex,
555
+ });
556
+ };
557
+
544
558
  const onHeaderTagSelect = (data) => {
545
- if (headerVarMappedData && updatedHeaderData) {
546
- const numId = Number(
547
- headerTextAreaId?.slice(headerTextAreaId?.indexOf('_') + 1)
548
- );
549
- if (!isNaN(numId)) {
550
- const arr = [...updatedHeaderData];
551
- //when trying to insert tag in empty textarea,{#var#} is replaced with "" and then tag is added
552
- if (arr[numId]?.match(validVarRegex)?.length > 0) {
553
- arr[numId] = '';
554
- }
555
- const messageData = `${arr[numId]}{{${data}}}`;
556
- arr[numId] = messageData;
557
- setHeaderVarMappedData((prevState) => ({
558
- ...prevState,
559
- [textAreaId]: messageData,
560
- }));
561
- setUpdatedHeaderData(arr);
562
- }
563
- }
559
+ onTagSelect({
560
+ data,
561
+ type: HEADER_TEXT,
562
+ mapData: headerVarMappedData,
563
+ updatedData: updatedHeaderData,
564
+ areaId: headerTextAreaId,
565
+ regex: headerValidVarRegex,
566
+ });
564
567
  };
565
568
 
566
569
  //setting the id of currently selected text area, is used onTagSelect
@@ -679,6 +682,32 @@ export const Whatsapp = (props) => {
679
682
  });
680
683
  };
681
684
 
685
+ const computeTextLength = (type) => {
686
+ switch (type) {
687
+ case MESSAGE_TEXT:
688
+ let whatsappContentLen = 0;
689
+ whatsappContentLen = isEditFlow
690
+ ? updatedSmsEditor?.join("")?.length
691
+ : templateMessage?.length;
692
+ whatsappContentLen += unsubscribeRequired ? UNSUBSCRIBE_TEXT_LENGTH : 0;
693
+ return whatsappContentLen;
694
+ case HEADER_TEXT:
695
+ let headerContentLen = 0;
696
+ headerContentLen = isEditFlow
697
+ ? updatedHeaderData?.join("")?.length
698
+ : templateHeader?.length;
699
+ return headerContentLen || 0;
700
+ case FOOTER_TEXT:
701
+ return templateFooter?.length || 0;
702
+ default:
703
+ let overallLength =
704
+ computeTextLength(MESSAGE_TEXT) +
705
+ computeTextLength(HEADER_TEXT) +
706
+ computeTextLength(FOOTER_TEXT);
707
+ return overallLength;
708
+ }
709
+ };
710
+
682
711
  //used by create and edit
683
712
  const renderMessageLength = (type, currentLength) => (
684
713
  <CapHeading type="label1" className="whatsapp-render-message-length">
@@ -726,9 +755,6 @@ export const Whatsapp = (props) => {
726
755
  <>
727
756
  <div
728
757
  className="whatsapp-button-quick-reply"
729
- style={{
730
- marginTop: "24px",
731
- }}
732
758
  >
733
759
  <CapHeading type="h4">
734
760
  {formatMessage(messages.btnTypeQuickReply)}
@@ -745,6 +771,7 @@ export const Whatsapp = (props) => {
745
771
  )}
746
772
  </>
747
773
  ),
774
+ disabled: host === HOST_TWILIO
748
775
  },
749
776
  ];
750
777
 
@@ -799,32 +826,6 @@ export const Whatsapp = (props) => {
799
826
  );
800
827
  };
801
828
 
802
- const computeTextLength = (type) => {
803
- switch (type) {
804
- case MESSAGE_TEXT:
805
- let whatsappContentLen = 0;
806
- whatsappContentLen = isEditFlow
807
- ? updatedSmsEditor.join("").length
808
- : templateMessage.length;
809
- whatsappContentLen += unsubscribeRequired ? UNSUBSCRIBE_TEXT_LENGTH : 0;
810
- return whatsappContentLen;
811
- case HEADER_TEXT:
812
- let headerContentLen = 0;
813
- headerContentLen = isEditFlow
814
- ? updatedHeaderData.join("").length
815
- : templateHeader.length;
816
- return headerContentLen || 0;
817
- case FOOTER_TEXT:
818
- return templateFooter.length || 0;
819
- default:
820
- let overallLength =
821
- computeTextLength(MESSAGE_TEXT) +
822
- computeTextLength(HEADER_TEXT) +
823
- computeTextLength(FOOTER_TEXT);
824
- return overallLength;
825
- }
826
- };
827
-
828
829
  const maxLengthByType = (type) => {
829
830
  switch (type) {
830
831
  case MESSAGE_TEXT:
@@ -832,8 +833,8 @@ export const Whatsapp = (props) => {
832
833
  case HEADER_TEXT:
833
834
  case FOOTER_TEXT:
834
835
  return TEMPLATE_HEADER_MAX_LENGTH;
835
- case "buttonText":
836
- return TEMPLATE_BUTTON_TEXT_MAX_LENGTH;
836
+ case BUTTON_TEXT:
837
+ return QUICK_REPLY_BUTTON_TEXT_MAX_LENGTH;
837
838
  }
838
839
  };
839
840
 
@@ -1012,33 +1013,38 @@ export const Whatsapp = (props) => {
1012
1013
  setTemplateMediaType(value);
1013
1014
  };
1014
1015
 
1015
- const onAddVar = () => {
1016
- const validVarArr = templateMessage.match(validVarRegex) || [];
1017
- const tempMsg = `${templateMessage}{{${validVarArr.length + 1}}}`;
1018
- const error = templateMessageErrorHandler(tempMsg);
1019
- setTemplateMessage(tempMsg);
1020
- setTemplateMessageError(error);
1016
+ const onMessageAddVar = () => {
1017
+ onAddVar(MESSAGE_TEXT, templateMessage, validVarRegex);
1021
1018
  };
1022
1019
 
1023
1020
  const onHeaderAddVar = () => {
1024
- const validVarArr = templateHeader.match(validVarRegex) || [];
1025
- const tempMsg = `${templateHeader}{{${validVarArr.length + 1}}}`;
1026
- const error = templateHeaderErrorHandler(tempMsg);
1027
- setTemplateHeader(tempMsg);
1028
- setTemplateHeaderError(error);
1021
+ onAddVar(HEADER_TEXT, templateHeader, headerValidVarRegex);
1029
1022
  };
1030
1023
 
1031
- const onTemplateMessageChange = ({ target: { value } }) => {
1032
- const error = templateMessageErrorHandler(value);
1033
- setTemplateMessage(value);
1034
- setTemplateMessageError(error);
1035
- };
1024
+ const onAddVar = (type, messageContent, regex) => {
1025
+ const validVarArr = messageContent.match(regex) || [];
1026
+ const tempMsg = `${messageContent}{{${validVarArr.length + 1}}}`;
1027
+ const error = type === HEADER_TEXT ? templateHeaderErrorHandler(tempMsg) : templateMessageErrorHandler(tempMsg);
1028
+ if (type === HEADER_TEXT) {
1029
+ setTemplateHeader(tempMsg);
1030
+ setTemplateHeaderError(error);
1031
+ } else {
1032
+ setTemplateMessage(tempMsg);
1033
+ setTemplateMessageError(error);
1034
+ }
1035
+ }
1036
1036
 
1037
- const onTemplateHeaderChanges = ({ target: { value } }) => {
1038
- const error = templateHeaderErrorHandler(value);
1039
- setTemplateHeader(value);
1040
- setTemplateHeaderError(error);
1041
- };
1037
+ const onTemplateValueChange = ({ target: { value } }, type) => {
1038
+ if (type === HEADER_TEXT) {
1039
+ const error = templateHeaderErrorHandler(value);
1040
+ setTemplateHeader(value);
1041
+ setTemplateHeaderError(error);
1042
+ } else {
1043
+ const error = templateMessageErrorHandler(value);
1044
+ setTemplateMessage(value);
1045
+ setTemplateMessageError(error);
1046
+ }
1047
+ }
1042
1048
 
1043
1049
  const onTemplateFooterChanges = ({ target: { value } }) => {
1044
1050
  let error = false;
@@ -1076,7 +1082,7 @@ export const Whatsapp = (props) => {
1076
1082
 
1077
1083
  const variableErrorHandling = (value, type) => {
1078
1084
  let errorMessage = false;
1079
- const validVarArr = value.match(validVarRegex) || [];
1085
+ const validVarArr = value.match(type === HEADER_TEXT ? headerValidVarRegex : validVarRegex) || [];
1080
1086
  const validVarSet = [...new Set(validVarArr)];
1081
1087
 
1082
1088
  const invalidVarRegex = /{{(.*?)}}/g;
@@ -1094,10 +1100,14 @@ export const Whatsapp = (props) => {
1094
1100
  errorMessage = formatMessage(messages.repetativeVars);
1095
1101
  } else if (invalidVarSet?.length !== validVarSet?.length) {
1096
1102
  //checks for invalid vars like Hi {{abcd}}, offer for you {{^_^}}
1097
- errorMessage = formatMessage(messages.unknownVars, {
1098
- one: "{{1}}",
1099
- nineteen: "{{19}}",
1100
- });
1103
+ if (type === HEADER_TEXT) {
1104
+ errorMessage = formatMessage(messages.headerUnknownVars);
1105
+ } else {
1106
+ errorMessage = formatMessage(messages.unknownVars, {
1107
+ one: "{{1}}",
1108
+ nineteen: "{{19}}",
1109
+ });
1110
+ }
1101
1111
  } else if (value.match(noContentBetweenVars)?.length > 0) {
1102
1112
  //checks for text between vars like Hi {{1}}{{2}}
1103
1113
  errorMessage = formatMessage(messages.noContentBetweenVars);
@@ -1227,9 +1237,14 @@ export const Whatsapp = (props) => {
1227
1237
  buttons: getQuickReplyData(),
1228
1238
  }),
1229
1239
  whatsappMedia: {
1230
- header: isEditFlow && !isFullMode ? updatedHeaderData.join("") : templateHeader,
1231
- headerVarMapped: !isFullMode ? headerVarMappedData : {},
1232
- footer: templateFooter || "",
1240
+ ...(isMediaTypeText && isHostIsNotTwilio && {
1241
+ header: isEditFlow && !isFullMode ? updatedHeaderData.join("") : templateHeader,
1242
+ headerVarMapped: !isFullMode ? headerVarMappedData : {},
1243
+ headerTemplate: !isFullMode && tempHeaderData.join(""),
1244
+ }),
1245
+ ...(isHostIsNotTwilio && {
1246
+ footer: templateFooter || ""
1247
+ }),
1233
1248
  },
1234
1249
  },
1235
1250
  },
@@ -1302,6 +1317,9 @@ export const Whatsapp = (props) => {
1302
1317
  if (!isMediaTypeText && host === HOST_KARIX && karixFileHandle === '') {
1303
1318
  return true;
1304
1319
  }
1320
+ if (templateHeaderError || templateFooterError) {
1321
+ return true;
1322
+ }
1305
1323
  //cta
1306
1324
  if (isBtnTypeCta) {
1307
1325
  if (ctaData.length === 1 && ctaData[0].isSaved) {
@@ -1320,7 +1338,7 @@ export const Whatsapp = (props) => {
1320
1338
  }
1321
1339
 
1322
1340
  if (isBtnTypeQuickReply) {
1323
- return !quickReplyData.every((quickReply) => quickReply.isSaved === true);
1341
+ return !quickReplyData.every((quickReply) => quickReply?.isSaved === true);
1324
1342
  }
1325
1343
  return false;
1326
1344
  };
@@ -1354,9 +1372,7 @@ export const Whatsapp = (props) => {
1354
1372
  <CapHeading type="h4">
1355
1373
  {formatMessage(globalMessages.templateNameLabel)}
1356
1374
  <CapTooltipWithInfo
1357
- infoIconProps={{
1358
- style: { marginLeft: CAP_SPACE_04 },
1359
- }}
1375
+ className="whatsapp-text-field_spacing"
1360
1376
  autoAdjustOverflow
1361
1377
  title={<FormattedMessage {...messages.templateNameTooltip} />}
1362
1378
  />
@@ -1400,53 +1416,62 @@ export const Whatsapp = (props) => {
1400
1416
  {/* template media type */}
1401
1417
  {renderMediaSection()}
1402
1418
  {renderMediaComponent()}
1403
- {/* template message create flow */}
1404
- <CapHeader
1405
- className={`${isMediaTypeImage ? "whatsapp-heading-spacing" : ""}`}
1406
- title={
1407
- <CapHeading type="h4" className="whatsapp-create-mode-heading">
1408
- {formatMessage(messages.templateHeaderLabel)}
1409
- <CapTooltipWithInfo
1410
- placement="right"
1411
- infoIconProps={{
1412
- style: { marginLeft: CAP_SPACE_04 },
1413
- }}
1414
- autoAdjustOverflow
1415
- title={<FormattedMessage {...messages.templateHeaderTooltip} />}
1419
+ {/* this section is for header section in create mode */}
1420
+ {isMediaTypeText && isHostIsNotTwilio && (
1421
+ <>
1422
+ <CapHeader
1423
+ title={
1424
+ <CapHeading type="h4" className="whatsapp-create-mode-heading">
1425
+ {formatMessage(messages.templateHeaderLabel)}
1426
+ <CapTooltipWithInfo
1427
+ placement="right"
1428
+ className="whatsapp-text-field_spacing"
1429
+ autoAdjustOverflow
1430
+ title={
1431
+ <FormattedMessage {...messages.templateHeaderTooltip} />
1432
+ }
1433
+ />
1434
+ <CapHeading className="whatsapp-optional-label1 align-item-center">
1435
+ {formatMessage(messages.optional)}
1436
+ </CapHeading>
1437
+ </CapHeading>
1438
+ }
1439
+ suffix={
1440
+ <CapButton
1441
+ type="flat"
1442
+ isAddBtn
1443
+ onClick={onHeaderAddVar}
1444
+ disabled={
1445
+ ((templateHeader.match(headerValidVarRegex) || []).length >
1446
+ 0 ||
1447
+ templateHeaderError) &&
1448
+ templateHeader
1449
+ }
1450
+ >
1451
+ {formatMessage(messages.addVar)}
1452
+ </CapButton>
1453
+ }
1454
+ />
1455
+ <CapRow className="whatsapp-create-template-message-input whatsapp-create-template-header-input">
1456
+ <TextArea
1457
+ id="whatsapp-create-template-message-input"
1458
+ autosize={{ minRows: 1, maxRows: 5 }}
1459
+ placeholder={formatMessage(messages.templateMessagePlaceholder)}
1460
+ onChange={(e) => onTemplateValueChange(e, HEADER_TEXT)}
1461
+ errorMessage={
1462
+ templateHeaderError && (
1463
+ <CapError className="whatsapp-template-message-error">
1464
+ {templateHeaderError}
1465
+ </CapError>
1466
+ )
1467
+ }
1468
+ value={templateHeader || ""}
1416
1469
  />
1417
- <CapHeading className="whatsapp-optional-label1 align-item-center">
1418
- {formatMessage(messages.optional)}
1419
- </CapHeading>
1420
- </CapHeading>
1421
- }
1422
- suffix={
1423
- <CapButton
1424
- type="flat"
1425
- isAddBtn
1426
- onClick={onHeaderAddVar}
1427
- disabled={templateHeaderError && templateHeader}
1428
- >
1429
- {formatMessage(messages.addVar)}
1430
- </CapButton>
1431
- }
1432
- />
1433
- <CapRow className="whatsapp-create-template-message-input whatsapp-create-template-header-input">
1434
- <TextArea
1435
- id="whatsapp-create-template-message-input"
1436
- autosize={{ minRows: 1, maxRows: 5 }}
1437
- placeholder={formatMessage(messages.templateMessagePlaceholder)}
1438
- onChange={onTemplateHeaderChanges}
1439
- errorMessage={
1440
- templateHeaderError && (
1441
- <CapError className="whatsapp-template-message-error">
1442
- {templateHeaderError}
1443
- </CapError>
1444
- )
1445
- }
1446
- value={templateHeader || ""}
1447
- />
1448
- </CapRow>
1449
- {renderMessageLength(HEADER_TEXT)}
1470
+ </CapRow>
1471
+ {renderMessageLength(HEADER_TEXT)}
1472
+ </>
1473
+ )}
1474
+ {/* template message create flow */}
1450
1475
  <CapHeader
1451
1476
  className={`${isMediaTypeImage ? "whatsapp-heading-spacing" : ""}`}
1452
1477
  title={
@@ -1454,9 +1479,7 @@ export const Whatsapp = (props) => {
1454
1479
  {formatMessage(messages.templateMessageLabel)}
1455
1480
  <CapTooltipWithInfo
1456
1481
  placement="right"
1457
- infoIconProps={{
1458
- style: { marginLeft: CAP_SPACE_04 },
1459
- }}
1482
+ className="whatsapp-text-field_spacing"
1460
1483
  autoAdjustOverflow
1461
1484
  title={
1462
1485
  <FormattedMessage
@@ -1474,7 +1497,7 @@ export const Whatsapp = (props) => {
1474
1497
  <CapButton
1475
1498
  type="flat"
1476
1499
  isAddBtn
1477
- onClick={onAddVar}
1500
+ onClick={onMessageAddVar}
1478
1501
  disabled={
1479
1502
  (addedVarCount >= 19 || templateMessageError) && templateMessage
1480
1503
  }
@@ -1488,7 +1511,7 @@ export const Whatsapp = (props) => {
1488
1511
  id="whatsapp-create-template-message-input"
1489
1512
  autosize={{ minRows: 3, maxRows: 5 }}
1490
1513
  placeholder={formatMessage(messages.templateMessagePlaceholder)}
1491
- onChange={onTemplateMessageChange}
1514
+ onChange={(e) => onTemplateValueChange(e, MESSAGE_TEXT)}
1492
1515
  errorMessage={
1493
1516
  templateMessageError && (
1494
1517
  <CapError className="whatsapp-template-message-error">
@@ -1501,42 +1524,47 @@ export const Whatsapp = (props) => {
1501
1524
  {renderUnsubscribeText()}
1502
1525
  </CapRow>
1503
1526
  {renderMessageLength(MESSAGE_TEXT)}
1504
- <CapHeader
1505
- className={`${isMediaTypeImage ? "whatsapp-heading-spacing" : ""}`}
1506
- title={
1507
- <CapHeading type="h4" className="whatsapp-create-mode-heading">
1508
- {formatMessage(messages.templateFooterLabel)}
1509
- <CapTooltipWithInfo
1510
- placement="right"
1511
- infoIconProps={{
1512
- style: { marginLeft: CAP_SPACE_04 },
1513
- }}
1514
- autoAdjustOverflow
1515
- title={<FormattedMessage {...messages.templateFooterTooltip} />}
1527
+ {/* this section if for footer in create mode */}
1528
+ {isHostIsNotTwilio && (
1529
+ <>
1530
+ <CapHeader
1531
+ className={`${isMediaTypeImage ? "whatsapp-heading-spacing" : ""}`}
1532
+ title={
1533
+ <CapHeading type="h4" className="whatsapp-create-mode-heading">
1534
+ {formatMessage(messages.templateFooterLabel)}
1535
+ <CapTooltipWithInfo
1536
+ placement="right"
1537
+ className="whatsapp-text-field_spacing"
1538
+ autoAdjustOverflow
1539
+ title={
1540
+ <FormattedMessage {...messages.templateFooterTooltip} />
1541
+ }
1542
+ />
1543
+ <CapHeading className="whatsapp-optional-label1 align-item-center">
1544
+ {formatMessage(messages.optional)}
1545
+ </CapHeading>
1546
+ </CapHeading>
1547
+ }
1548
+ />
1549
+ <CapRow className="whatsapp-create-template-message-input whatsapp-create-template-header-input">
1550
+ <TextArea
1551
+ id="whatsapp-create-template-message-input"
1552
+ autosize={{ minRows: 1, maxRows: 5 }}
1553
+ placeholder={formatMessage(messages.templateMessagePlaceholder)}
1554
+ onChange={onTemplateFooterChanges}
1555
+ errorMessage={
1556
+ templateFooterError && (
1557
+ <CapError className="whatsapp-template-message-error">
1558
+ {templateFooterError}
1559
+ </CapError>
1560
+ )
1561
+ }
1562
+ value={templateFooter || ""}
1516
1563
  />
1517
- <CapHeading className="whatsapp-optional-label1 align-item-center">
1518
- {formatMessage(messages.optional)}
1519
- </CapHeading>
1520
- </CapHeading>
1521
- }
1522
- />
1523
- <CapRow className="whatsapp-create-template-message-input whatsapp-create-template-header-input">
1524
- <TextArea
1525
- id="whatsapp-create-template-message-input"
1526
- autosize={{ minRows: 1, maxRows: 5 }}
1527
- placeholder={formatMessage(messages.templateMessagePlaceholder)}
1528
- onChange={onTemplateFooterChanges}
1529
- errorMessage={
1530
- templateFooterError && (
1531
- <CapError className="whatsapp-template-message-error">
1532
- {templateFooterError}
1533
- </CapError>
1534
- )
1535
- }
1536
- value={templateFooter || ""}
1537
- />
1538
- </CapRow>
1539
- {renderMessageLength(FOOTER_TEXT)}
1564
+ </CapRow>
1565
+ {renderMessageLength(FOOTER_TEXT)}
1566
+ </>
1567
+ )}
1540
1568
  {renderButtonsSection()}
1541
1569
  </>
1542
1570
  );
@@ -1655,7 +1683,7 @@ export const Whatsapp = (props) => {
1655
1683
  ? updatedHeaderData[idValue]
1656
1684
  : updatedSmsEditor[idValue];
1657
1685
  //if value is there and it is not a variable return it
1658
- if (value && (value.match(validVarRegex) || []).length === 0) {
1686
+ if (value && (value.match(type === HEADER_TEXT ? headerValidVarRegex : validVarRegex) || []).length === 0) {
1659
1687
  return value;
1660
1688
  }
1661
1689
  }
@@ -1668,7 +1696,7 @@ export const Whatsapp = (props) => {
1668
1696
  let varCount = 0;
1669
1697
  messageData.forEach((elem, index) => {
1670
1698
  // if var return textarea else return text
1671
- if (elem.match(validVarRegex)?.length > 0) {
1699
+ if (elem.match(type === HEADER_TEXT ? headerValidVarRegex : validVarRegex)?.length > 0) {
1672
1700
  varCount += 1;
1673
1701
  renderArray.push(
1674
1702
  <TextArea
@@ -1697,7 +1725,9 @@ export const Whatsapp = (props) => {
1697
1725
  }
1698
1726
  });
1699
1727
  }
1700
- renderArray.push(renderUnsubscribeText());
1728
+ if (type !== HEADER_TEXT) {
1729
+ renderArray.push(renderUnsubscribeText());
1730
+ }
1701
1731
  return renderArray;
1702
1732
  };
1703
1733
 
@@ -1743,7 +1773,8 @@ export const Whatsapp = (props) => {
1743
1773
  {renderLabel("mediaLabel")}
1744
1774
  <CapLabel type="label15">{capitalizeString(templateMediaType)}</CapLabel>
1745
1775
  {renderMediaComponent()}
1746
- {templateHeader && (
1776
+ {/* this section is for render header section */}
1777
+ {(templateHeader && isMediaTypeText && isHostIsNotTwilio) && (
1747
1778
  <>
1748
1779
  <CapRow className="whatsapp-render-heading">
1749
1780
  <CapHeader
@@ -1779,12 +1810,10 @@ export const Whatsapp = (props) => {
1779
1810
  </CapTooltip>
1780
1811
  {renderMessageLength(HEADER_TEXT)}
1781
1812
  {isHeaderTagValidationError && tagValidationErrorMessage(HEADER_TEXT)}
1782
- {computeTextLength(HEADER_TEXT) > TEMPLATE_HEADER_MAX_LENGTH ? (
1813
+ {computeTextLength(HEADER_TEXT) > TEMPLATE_HEADER_MAX_LENGTH && (
1783
1814
  <CapError>
1784
1815
  {formatMessage(messages.templateMessageLengthError)}
1785
1816
  </CapError>
1786
- ) : (
1787
- ""
1788
1817
  )}
1789
1818
  </>
1790
1819
  )}
@@ -1799,7 +1828,7 @@ export const Whatsapp = (props) => {
1799
1828
  templateStatus === WHATSAPP_STATUSES.approved && (
1800
1829
  <TagList
1801
1830
  label={formatMessage(globalMessages.addLabels)}
1802
- onTagSelect={onTagSelect}
1831
+ onTagSelect={onMessageTagSelect}
1803
1832
  location={location}
1804
1833
  tags={tags || []}
1805
1834
  onContextChange={handleOnTagsContextChange}
@@ -1830,7 +1859,7 @@ export const Whatsapp = (props) => {
1830
1859
  ) : (
1831
1860
  ""
1832
1861
  )}
1833
- {templateFooter && (
1862
+ {templateFooter && isHostIsNotTwilio && (
1834
1863
  <>
1835
1864
  <CapHeader
1836
1865
  className={`${isMediaTypeImage ? "whatsapp-heading-spacing" : ""}`}