@capillarytech/creatives-library 7.12.40 → 7.12.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.
@@ -4,11 +4,22 @@ import { shallowWithIntl } from '../../../helpers/intl-enzym-test-helpers';
4
4
  import { Creatives } from '../index';
5
5
  import mockdata from '../../mockdata';
6
6
 
7
- const { whatsappTemplates, rcsTemplates, whatsappEditTemplateData, rcsEditTemplateData } = mockdata;
7
+ const {
8
+ whatsappTemplates,
9
+ rcsTemplates,
10
+ whatsappGetCreativeData,
11
+ whatsappGetTemplateData,
12
+ rcsEditTemplateData,
13
+ whatsappGetCreativeData2,
14
+ } = mockdata;
8
15
 
9
- jest.mock("../../../v2Components/FormBuilder", () => ({
16
+ jest.mock('../../../v2Components/FormBuilder', () => ({
10
17
  __esModule: true,
11
- default: (props) => <div className="FormBuilder-mock" {...props}>FormBuilder</div>,
18
+ default: (props) => (
19
+ <div className="FormBuilder-mock" {...props}>
20
+ FormBuilder
21
+ </div>
22
+ ),
12
23
  }));
13
24
 
14
25
  describe('Test SlideBoxContent container', () => {
@@ -29,17 +40,24 @@ describe('Test SlideBoxContent container', () => {
29
40
  templateData={templateData}
30
41
  handleCloseCreatives={handleCloseCreatives}
31
42
  getCreativesData={getCreativesData}
32
- />
43
+ />,
33
44
  );
34
45
  };
35
46
 
36
47
  it('Should render correct component for whatsapp channel create mode', () => {
37
- renderFunction("WHATSAPP", "createTemplate", whatsappTemplates, { mode: "create" });
48
+ renderFunction('WHATSAPP', 'createTemplate', whatsappTemplates, {
49
+ mode: 'create',
50
+ });
38
51
  expect(renderedComponent).toMatchSnapshot();
39
52
  });
40
53
 
41
54
  it('Should render correct component for whatsapp channel edit mode', () => {
42
- renderFunction("WHATSAPP", "editTemplate", whatsappTemplates, whatsappEditTemplateData);
55
+ renderFunction(
56
+ 'WHATSAPP',
57
+ 'editTemplate',
58
+ whatsappTemplates,
59
+ whatsappGetTemplateData,
60
+ );
43
61
  renderedComponent.instance().onEditTemplate();
44
62
  renderedComponent.find('CapSlideBox').props().content.props.handleClose();
45
63
  expect(renderedComponent).toMatchSnapshot();
@@ -48,23 +66,38 @@ describe('Test SlideBoxContent container', () => {
48
66
  });
49
67
 
50
68
  it('Text getCreatives data for whatsapp', () => {
51
- renderFunction("WHATSAPP", "editTemplate", whatsappTemplates, whatsappEditTemplateData);
69
+ console.log('abcRcb');
70
+ renderFunction(
71
+ 'WHATSAPP',
72
+ 'editTemplate',
73
+ whatsappTemplates,
74
+ whatsappGetCreativeData,
75
+ );
52
76
  renderedComponent.instance().onEditTemplate();
53
- renderedComponent.find('CapSlideBox').props().content.props.getFormData(whatsappEditTemplateData);
54
- expect(getCreativesData).toHaveBeenCalledTimes(1);
55
- expect(getCreativesData).toHaveBeenCalledWith({ channel: "WHATSAPP" });
77
+ renderedComponent
78
+ .find('CapSlideBox')
79
+ .props()
80
+ .content.props.getFormData(whatsappGetCreativeData);
81
+ renderedComponent
82
+ .find('CapSlideBox')
83
+ .props()
84
+ .content.props.getFormData(whatsappGetCreativeData2);
85
+ expect(getCreativesData).toHaveBeenCalledTimes(2);
56
86
  });
57
87
 
58
88
  it('Should render correct component for rcs channel create mode', () => {
59
- renderFunction("RCS", "createTemplate", rcsTemplates, { mode: "create" });
89
+ renderFunction('RCS', 'createTemplate', rcsTemplates, { mode: 'create' });
60
90
  expect(renderedComponent).toMatchSnapshot();
61
91
  });
62
92
 
63
93
  it('Text getCreatives data for rcs', () => {
64
- renderFunction("RCS", "editTemplate", rcsTemplates, rcsEditTemplateData);
94
+ renderFunction('RCS', 'editTemplate', rcsTemplates, rcsEditTemplateData);
65
95
  renderedComponent.instance().onEditTemplate();
66
- renderedComponent.find('CapSlideBox').props().content.props.getFormData(rcsEditTemplateData);
96
+ renderedComponent
97
+ .find('CapSlideBox')
98
+ .props()
99
+ .content.props.getFormData(rcsEditTemplateData);
67
100
  expect(getCreativesData).toHaveBeenCalledTimes(1);
68
- expect(getCreativesData).toHaveBeenCalledWith({ channel: "RCS" });
101
+ expect(getCreativesData).toHaveBeenCalledWith({ channel: 'RCS' });
69
102
  });
70
103
  });
@@ -128,20 +128,23 @@ export const WHATSAPP_MEDIA_TYPES = {
128
128
  IMAGE: 'IMAGE',
129
129
  VIDEO: 'VIDEO',
130
130
  };
131
-
131
+ export const NONE = 'NONE';
132
+ export const CTA = 'CTA';
133
+ export const QUICK_REPLY = 'QUICK_REPLY';
132
134
  export const WHATSAPP_BUTTON_TYPES = {
133
- NONE: 'NONE',
134
- CTA: 'CTA',
135
- QUICK_REPLY: 'QUICK_REPLY',
135
+ NONE,
136
+ CTA,
137
+ QUICK_REPLY,
136
138
  };
137
-
139
+ export const PHONE_NUMBER = 'PHONE_NUMBER';
140
+ export const STATIC_URL = 'STATIC_URL';
138
141
  export const INITIAL_CTA_DATA = [
139
142
  {
140
143
  index: 0,
141
- ctaType: 'PHONE_NUMBER',
144
+ ctaType: PHONE_NUMBER,
142
145
  text: '',
143
146
  phone_number: '',
144
- urlType: 'STATIC_URL',
147
+ urlType: STATIC_URL,
145
148
  url: '',
146
149
  isSaved: false,
147
150
  },
@@ -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,23 @@ export const Whatsapp = (props) => {
239
233
  const computeTempMsgArray = () => {
240
234
  let msg = get(editContent, `languages[0].content`, '');
241
235
  const validVarArr = msg.match(validVarRegex) || [];
242
- const unsubscribePresent = /Click {{([1-9]|1[0-9])}} to unsubscribe/g;
236
+ const unsubscribeRegex1 = /Click {{([1-9]|1[0-9])}} to unsubscribe/g;
237
+ const unsubscribeRegex2 = /Click {{unsubscribe}} to unsubscribe/g;
243
238
  const templateMessageArray = [];
244
239
  //removing $'' which was added for twilio enter handling
245
240
  // msg = msg.slice(2, -1);
246
- if (msg.match(unsubscribePresent)?.length > 0) {
247
- //removing Click {{unsubscribe}} to unsubscribe
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
248
246
  msg = msg.replace(
249
247
  `\nClick ${validVarArr[validVarArr.length - 1]} to unsubscribe`,
250
248
  '',
251
249
  );
252
- //removing last var added for Click {{unsubscribe}} to unsubscribe
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
253
  if (isFullMode) {
254
254
  validVarArr.pop();
255
255
  }
@@ -532,41 +532,46 @@ export const Whatsapp = (props) => {
532
532
  setTemplateMessageError(error);
533
533
  };
534
534
 
535
- const renderUnsubscribeText = () => (
536
- <>
537
- <CapColumn span={12}>
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}
552
- >
553
- <CapTooltip
554
- placement="bottom"
555
- title={
556
- !isEditFlow && formatMessage(messages.unsubscribeTextTooltip)
557
- }
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}
558
553
  >
559
- <span className="whatsapp-render-unsubscribe-text">
560
- {formatMessage(messages.templateMessageUnsubscribeText)}
561
- </span>
562
- </CapTooltip>
563
- </CapCheckbox>
564
- </CapColumn>
565
- <CapColumn span={12}></CapColumn>
566
- </>
567
- );
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
+ };
568
573
 
569
- const computeLength = () => {
574
+ const computeTextLength = () => {
570
575
  let whatsappContentLen = 0;
571
576
  whatsappContentLen = isEditFlow
572
577
  ? updatedSmsEditor.join('').length
@@ -579,7 +584,7 @@ export const Whatsapp = (props) => {
579
584
  const renderMessageLength = () => (
580
585
  <CapHeading type="label1" className="whatsapp-render-message-length">
581
586
  {formatMessage(messages.templateMessageLength, {
582
- currentLength: computeLength(),
587
+ currentLength: computeTextLength(),
583
588
  maxLength: TEMPLATE_MESSAGE_MAX_LENGTH,
584
589
  })}
585
590
  </CapHeading>
@@ -604,6 +609,7 @@ export const Whatsapp = (props) => {
604
609
  }
605
610
  />
606
611
  <CapRadioGroup
612
+ disabled={isEditFlow}
607
613
  options={buttonRadioOptions || []}
608
614
  value={buttonType}
609
615
  onChange={onChangeButtonType}
@@ -729,7 +735,7 @@ export const Whatsapp = (props) => {
729
735
 
730
736
  const getCtaPayload = () =>
731
737
  ctaData.map((cta) => {
732
- const { index, ctaType, text, phone_number, urlType, url } = cta || {};
738
+ const { index, ctaType, text, phone_number, urlType, url } = cta;
733
739
  if (ctaType === PHONE_NUMBER) {
734
740
  return {
735
741
  index,
@@ -836,11 +842,24 @@ export const Whatsapp = (props) => {
836
842
  if (templateMessage.trim() === '' || templateMessageError) {
837
843
  return true;
838
844
  }
839
- if (buttonType === WHATSAPP_BUTTON_TYPES.CTA) {
840
- return !ctaData.every((i) => i.isSaved === true);
845
+ //cta
846
+ if (buttonType === WHATSAPP_BUTTON_TYPES.CTA) {
847
+ if (ctaData.length === 1 && ctaData[0].isSaved) {
848
+ //if button type is cta and 1st button is saved
849
+ return false;
850
+ } else if (
851
+ ctaData.length === 2 &&
852
+ ctaData[0].isSaved &&
853
+ ctaData[1].isSaved
854
+ ) {
855
+ //if button type is cta and 2nd button is saved
856
+ return false;
841
857
  }
842
- return false;
843
- };
858
+ //if button type is cta and there are no buttons saved
859
+ return true;
860
+ }
861
+ return false;
862
+ };
844
863
 
845
864
  const createModeContent = (
846
865
  <>
@@ -1155,6 +1174,13 @@ export const Whatsapp = (props) => {
1155
1174
 
1156
1175
  {renderMessageLength()}
1157
1176
  {isTagValidationError && tagValidationErrorMessage()}
1177
+ {computeTextLength() > TEMPLATE_MESSAGE_MAX_LENGTH ? (
1178
+ <CapError>
1179
+ {formatMessage(messages.templateMessageLengthError)}
1180
+ </CapError>
1181
+ ) : (
1182
+ ''
1183
+ )}
1158
1184
 
1159
1185
  <CapTooltip
1160
1186
  placement="bottom"
@@ -1189,7 +1215,7 @@ export const Whatsapp = (props) => {
1189
1215
  ctaData,
1190
1216
  }),
1191
1217
  }}
1192
- whatsappContentLen={computeLength()}
1218
+ whatsappContentLen={computeTextLength()}
1193
1219
  whatsappAccountName={accountName}
1194
1220
  />
1195
1221
  );
@@ -1197,7 +1223,8 @@ export const Whatsapp = (props) => {
1197
1223
 
1198
1224
  const isEditDoneDisabled = () =>
1199
1225
  isTagValidationError ||
1200
- Object.values(varMap).some((inputValue) => inputValue === '');
1226
+ Object.values(varMap).some((inputValue) => inputValue === '') ||
1227
+ computeTextLength() > TEMPLATE_MESSAGE_MAX_LENGTH;
1201
1228
  return (
1202
1229
  <CapSpin spinning={spin}>
1203
1230
  <CapRow className="cap-whatsapp-creatives">
@@ -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',