@capillarytech/creatives-library 7.17.81 → 7.17.82-alpha.1

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 (38) hide show
  1. package/containers/Cap/sagas.js +7 -5
  2. package/containers/Cap/tests/saga.test.js +81 -1
  3. package/package.json +3 -2
  4. package/services/api.js +5 -0
  5. package/services/tests/api.test.js +9 -1
  6. package/v2Components/CapWhatsappQuickReply/index.js +243 -0
  7. package/v2Components/CapWhatsappQuickReply/index.scss +43 -0
  8. package/v2Components/CapWhatsappQuickReply/messages.js +24 -0
  9. package/v2Components/TemplatePreview/_templatePreview.scss +23 -0
  10. package/v2Components/TemplatePreview/index.js +51 -1
  11. package/v2Components/TemplatePreview/messages.js +4 -0
  12. package/v2Components/TemplatePreview/tests/__snapshots__/index.test.js.snap +0 -14
  13. package/v2Containers/CreativesContainer/index.js +22 -2
  14. package/v2Containers/CreativesContainer/tests/__snapshots__/SlideBoxContent.test.js.snap +2 -0
  15. package/v2Containers/Templates/index.js +5 -2
  16. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +6 -0
  17. package/v2Containers/Whatsapp/actions.js +16 -0
  18. package/v2Containers/Whatsapp/constants.js +22 -0
  19. package/v2Containers/Whatsapp/index.js +699 -187
  20. package/v2Containers/Whatsapp/index.scss +55 -1
  21. package/v2Containers/Whatsapp/messages.js +37 -0
  22. package/v2Containers/Whatsapp/reducer.js +19 -0
  23. package/v2Containers/Whatsapp/sagas.js +40 -1
  24. package/v2Containers/Whatsapp/styles.scss +29 -0
  25. package/v2Containers/Whatsapp/tests/__snapshots__/index.test.js.snap +40962 -24255
  26. package/v2Containers/Whatsapp/tests/__snapshots__/utils.test.js.snap +12 -0
  27. package/v2Containers/Whatsapp/tests/actions.test.js +21 -0
  28. package/v2Containers/Whatsapp/tests/index.test.js +8 -0
  29. package/v2Containers/Whatsapp/tests/mockData.js +6 -0
  30. package/v2Containers/Whatsapp/tests/reducer.test.js +67 -0
  31. package/v2Containers/Whatsapp/tests/saga.test.js +90 -0
  32. package/v2Containers/Whatsapp/tests/utils.test.js +11 -0
  33. package/v2Containers/Whatsapp/utils.js +45 -3
  34. package/v2Containers/mockdata.js +105 -4
  35. package/v2Containers/InApp/constants.js +0 -0
  36. package/v2Containers/InApp/index.js +0 -499
  37. package/v2Containers/InApp/index.scss +0 -0
  38. package/v2Containers/InApp/messages.js +0 -0
@@ -17,6 +17,8 @@ Object {
17
17
  "url": "https://docs.google.com/{{1}}",
18
18
  },
19
19
  ],
20
+ "templateFooterPreview": "",
21
+ "templateHeaderPreview": "",
20
22
  "templateMsg": <CapLabel
21
23
  type="label9"
22
24
  >
@@ -30,6 +32,8 @@ Click {{unsubscribe}} to unsubscribe
30
32
  exports[`Test utils test getWhatsappContent 2`] = `
31
33
  Object {
32
34
  "charCount": 36,
35
+ "templateFooterPreview": "",
36
+ "templateHeaderPreview": "",
33
37
  "templateMsg": <CapLabel
34
38
  type="label9"
35
39
  >
@@ -55,6 +59,8 @@ Object {
55
59
  "url": "https://docs.google.com/{{1}}",
56
60
  },
57
61
  ],
62
+ "templateFooterPreview": "",
63
+ "templateHeaderPreview": "",
58
64
  "templateMsg": <CapLabel
59
65
  type="label9"
60
66
  >
@@ -132,6 +138,8 @@ Object {
132
138
  </div>
133
139
  </div>
134
140
  </React.Fragment>,
141
+ "templateFooterPreview": "",
142
+ "templateHeaderPreview": "",
135
143
  "templateMsg": <CapLabel
136
144
  type="label9"
137
145
  >
@@ -144,6 +152,8 @@ Click {{unsubscribe}} to unsubscribe
144
152
  exports[`Test utils test getWhatsappContent 5`] = `
145
153
  Object {
146
154
  "charCount": -1,
155
+ "templateFooterPreview": "",
156
+ "templateHeaderPreview": "",
147
157
  "templateMsg": <CapLabel
148
158
  type="label9"
149
159
  >
@@ -169,6 +179,8 @@ Object {
169
179
  "url": "https://docs.google.com/{{1}}",
170
180
  },
171
181
  ],
182
+ "templateFooterPreview": "",
183
+ "templateHeaderPreview": "",
172
184
  "templateMsg": <CapLabel
173
185
  type="label5"
174
186
  >
@@ -38,4 +38,25 @@ describe('Test whatsapp actions', () => {
38
38
  actions.createWhatsappTemplate(payload, undefined, undefined),
39
39
  ).toStrictEqual(expected);
40
40
  });
41
+
42
+ it("test getMetaTags", () => {
43
+ const payload = {
44
+ previewUrl: 'https://capillarytech.com',
45
+ callBack: undefined,
46
+ };
47
+ const expected = {
48
+ type: types.URL_META_TAGS_REQUEST,
49
+ previewUrl: 'https://capillarytech.com',
50
+ callBack: undefined,
51
+ };
52
+ expect(actions.getMetaTags(payload)).toStrictEqual(expected);
53
+ });
54
+
55
+ it("test resetMetaTags", () => {
56
+ const expected = {
57
+ type: types.URL_META_TAGS_RESET,
58
+ };
59
+ expect(actions.resetMetaTags()).toStrictEqual(expected);
60
+ });
41
61
  });
62
+
@@ -23,6 +23,8 @@ describe('Creatives Whatsapp test1/>', () => {
23
23
  const handleClose = jest.fn();
24
24
  const onCreateComplete = jest.fn();
25
25
  const formatMessage = jest.fn();
26
+ const getMetaTags = jest.fn();
27
+ const resetMetaTags = jest.fn();
26
28
  const location = mockData.location;
27
29
  const params = {
28
30
  id: mockData.editData1.templateDetails._id,
@@ -42,6 +44,8 @@ describe('Creatives Whatsapp test1/>', () => {
42
44
  clearCreateResponse,
43
45
  getTemplateDetails,
44
46
  resetEditTemplate,
47
+ getMetaTags,
48
+ resetMetaTags,
45
49
  }}
46
50
  globalActions={{ fetchSchemaForEntity }}
47
51
  onCreateComplete={onCreateComplete}
@@ -268,6 +272,8 @@ describe('Creatives Whatsapp test2/>', () => {
268
272
  const handleClose = jest.fn();
269
273
  const onCreateComplete = jest.fn();
270
274
  const formatMessage = jest.fn();
275
+ const getMetaTags = jest.fn();
276
+ const resetMetaTags = jest.fn();
271
277
  const location = mockData.location;
272
278
  const params = {
273
279
  id: mockData.editData1.templateDetails._id,
@@ -284,6 +290,8 @@ describe('Creatives Whatsapp test2/>', () => {
284
290
  clearCreateResponse,
285
291
  getTemplateDetails,
286
292
  resetEditTemplate,
293
+ getMetaTags,
294
+ resetMetaTags,
287
295
  }}
288
296
  globalActions={{ fetchSchemaForEntity }}
289
297
  onCreateComplete={onCreateComplete}
@@ -245,4 +245,10 @@ export const mockData = {
245
245
  },
246
246
  search: '',
247
247
  },
248
+ metaTagsMock: {
249
+ image: 'https://capillarytech.com/assest/capillary.png',
250
+ title: 'Capillary',
251
+ description: 'sample',
252
+ url: "https://capillarytech.com",
253
+ },
248
254
  };
@@ -0,0 +1,67 @@
1
+ import { fromJS } from "immutable";
2
+ import whatsappReducer from "../reducer";
3
+ import {
4
+ URL_META_TAGS_REQUEST,
5
+ URL_META_TAGS_SUCCESS,
6
+ URL_META_TAGS_FAILURE,
7
+ URL_META_TAGS_RESET,
8
+ } from "../constants";
9
+ import { mockData } from "./mockData";
10
+
11
+ describe("whatsapp reducer", () => {
12
+ let state;
13
+ const action = {};
14
+ beforeEach(() => {
15
+ state = fromJS({
16
+ getMetaTagsRequest: false,
17
+ metaTagsDetails: {},
18
+ getMetaTagsError: '',
19
+ });
20
+ });
21
+
22
+ it("Reducer : URL_META_TAGS_REQUEST", () => {
23
+ action.type = URL_META_TAGS_REQUEST;
24
+ state = state
25
+ .set("getMetaTagsRequest", true)
26
+ .set("metaTagsDetails", {});
27
+ const expectedResult = state;
28
+ expect(whatsappReducer(state, action)).toEqual(
29
+ expectedResult
30
+ );
31
+ });
32
+
33
+ it("Reducer : URL_META_TAGS_SUCCESS", () => {
34
+ action.type = URL_META_TAGS_SUCCESS;
35
+ action.data = mockData.metaTagsMock;
36
+ state = state
37
+ .set("getMetaTagsRequest", false)
38
+ .set("metaTagsDetails", mockData.metaTagsMock);
39
+ const expectedResult = state;
40
+ expect(whatsappReducer(state, action)).toEqual(
41
+ expectedResult
42
+ );
43
+ });
44
+
45
+ it("Reducer : URL_META_TAGS_FAILURE", () => {
46
+ action.type = URL_META_TAGS_FAILURE;
47
+ action.error = 'error';
48
+ state = state
49
+ .set("getMetaTagsRequest", false)
50
+ .set("metaTagsDetails", {})
51
+ .set("getMetaTagsError", 'error');
52
+ const expectedResult = state;
53
+ expect(whatsappReducer(state, action)).toEqual(
54
+ expectedResult
55
+ );
56
+ });
57
+
58
+ it("Reducer : URL_META_TAGS_RESET", () => {
59
+ action.type = URL_META_TAGS_RESET;
60
+ state = state
61
+ .set("metaTagsDetails", {});
62
+ const expectedResult = state;
63
+ expect(whatsappReducer(state, action)).toEqual(
64
+ expectedResult
65
+ );
66
+ });
67
+ });
@@ -0,0 +1,90 @@
1
+ import { expectSaga, testSaga } from "redux-saga-test-plan";
2
+ import * as matchers from "redux-saga-test-plan/matchers";
3
+ import { takeLatest } from "redux-saga/effects";
4
+ import { getMetaTagsDetails, watchGetMetaTagsDetails } from "../sagas";
5
+ import {
6
+ URL_META_TAGS_REQUEST,
7
+ URL_META_TAGS_SUCCESS,
8
+ URL_META_TAGS_FAILURE,
9
+ } from "../constants";
10
+ import * as Api from "../../../services/api";
11
+
12
+ describe("Whatsapp saga", () => {
13
+ const error = new Error("error");
14
+ const callBack = jest.fn();
15
+ describe("whatsapp test saga", () => {
16
+ it("handle success response from getMetaTagsDetails", () => {
17
+ expectSaga(getMetaTagsDetails, {
18
+ previewUrl: "https://capillarytech.com",
19
+ callBack,
20
+ }).provide([
21
+ [
22
+ matchers.call.fn(Api.getMetaTags),
23
+ {
24
+ success: true,
25
+ result: [],
26
+ },
27
+ ],
28
+ ])
29
+ .put({
30
+ type: URL_META_TAGS_SUCCESS,
31
+ result: {},
32
+ })
33
+ .run();
34
+ });
35
+
36
+ it("handle success false response from getMetaTagsDetails", () => {
37
+ expectSaga(getMetaTagsDetails, {
38
+ previewUrl: "https://capillarytech.com",
39
+ callBack,
40
+ }).provide([
41
+ [
42
+ matchers.call.fn(Api.getMetaTags),
43
+ {
44
+ success: false,
45
+ result: [],
46
+ message: 'error',
47
+ },
48
+ ],
49
+ ])
50
+ .put({
51
+ type: URL_META_TAGS_FAILURE,
52
+ error: 'error',
53
+ })
54
+ .run();
55
+ });
56
+
57
+ it("handle success false response from getMetaTagsDetails when callback not present", () => {
58
+ expectSaga(getMetaTagsDetails, {
59
+ previewUrl: "https://capillarytech.com",
60
+ }).provide([
61
+ [
62
+ matchers.call.fn(Api.getMetaTags),
63
+ {
64
+ success: false,
65
+ result: [],
66
+ message: 'error',
67
+ },
68
+ ],
69
+ ])
70
+ .put({
71
+ type: URL_META_TAGS_FAILURE,
72
+ error: 'error',
73
+ })
74
+ .run();
75
+ });
76
+
77
+ it("handles error thrown", () => {
78
+ testSaga(getMetaTagsDetails, { callBack }).next().throw(error).next().isDone();
79
+ });
80
+ });
81
+
82
+ describe("watchGetMetaTagsDetails saga", () => {
83
+ const generator = watchGetMetaTagsDetails();
84
+ it("should call watchers functions", async () => {
85
+ expect(generator.next().value).toEqual(
86
+ takeLatest(URL_META_TAGS_REQUEST, getMetaTagsDetails)
87
+ );
88
+ });
89
+ });
90
+ });
@@ -5,6 +5,7 @@ import {
5
5
  getWhatsappCta,
6
6
  bytesConversion,
7
7
  getWhatsappDocPreview,
8
+ getWhatsappQuickReply
8
9
  } from '../utils';
9
10
  import mockdata from '../../mockdata';
10
11
 
@@ -18,6 +19,9 @@ const {
18
19
  getWhatsappCategoryOutput2,
19
20
  getWhatsappDocPreviewOutput,
20
21
  getWhatsappDocPreviewOutput1,
22
+ whatsappPreviewTemplateData3,
23
+ whatsappPreviewTemplateData3Result,
24
+ whatsappPreviewTemplateData3QuickReplyResult
21
25
  } = mockdata;
22
26
 
23
27
  describe('Test utils', () => {
@@ -27,10 +31,17 @@ describe('Test utils', () => {
27
31
  expect(getWhatsappContent(whatsappPreviewTemplateDataVid)).toMatchSnapshot();
28
32
  expect(getWhatsappContent(whatsappPreviewTemplateDataDoc)).toMatchSnapshot();
29
33
  expect(getWhatsappContent({})).toMatchSnapshot();
34
+ expect(getWhatsappContent(whatsappPreviewTemplateData3)).toEqual(whatsappPreviewTemplateData3Result);
30
35
  expect(bytesConversion(1024)).toEqual('1.0 KB');
31
36
  expect(bytesConversion('abcd')).toEqual('0 bytes');
32
37
  });
33
38
 
39
+ it("test getWhatsappQuickReply", () => {
40
+ expect(getWhatsappQuickReply(whatsappPreviewTemplateData3)).toEqual(
41
+ whatsappPreviewTemplateData3QuickReplyResult
42
+ );
43
+ });
44
+
34
45
  it('test getWhatsappContent for preview', () => {
35
46
  expect(
36
47
  getWhatsappContent(whatsappPreviewTemplateData, true),
@@ -3,6 +3,7 @@ import { FormattedMessage } from 'react-intl';
3
3
  import CapLabel from '@capillarytech/cap-ui-library/CapLabel';
4
4
  import CapIcon from '@capillarytech/cap-ui-library/CapIcon';
5
5
  import CapImage from '@capillarytech/cap-ui-library/CapImage';
6
+ import CapDivider from '@capillarytech/cap-ui-library/CapDivider';
6
7
  import { get } from 'lodash';
7
8
  import { WHATSAPP } from '../CreativesContainer/constants';
8
9
  import {
@@ -17,6 +18,7 @@ import {
17
18
  WHATSAPP_MEDIA_TYPES,
18
19
  HOST_TWILIO,
19
20
  SIZE_UNITS,
21
+ QUICK_REPLY
20
22
  } from '../Whatsapp/constants';
21
23
  import './styles.scss';
22
24
  import pdfIcon from "../../assets/pdfIcon.svg";
@@ -65,11 +67,15 @@ export const getWhatsappContent = (template, isPreview) => {
65
67
  [WHATSAPP.toLowerCase()]: {
66
68
  languages = [{}],
67
69
  buttonType = NONE,
68
- buttons: ctaData = [],
70
+ buttons: buttonsData = [],
69
71
  mediaType = WHATSAPP_MEDIA_TYPES.TEXT,
70
72
  imageUrl = '',
71
73
  videoPreviewImg = '',
72
74
  whatsappDocParams = {},
75
+ whatsappMedia: {
76
+ header = '',
77
+ footer = '',
78
+ } = {},
73
79
  } = {},
74
80
  } = {},
75
81
  } = {},
@@ -104,10 +110,15 @@ export const getWhatsappContent = (template, isPreview) => {
104
110
  }
105
111
 
106
112
  return {
113
+ templateHeaderPreview: header ? <CapLabel className="whatsapp-template-list-header-preview">{header}</CapLabel> : '',
114
+ templateFooterPreview: footer ? <CapLabel className="whatsapp-template-list-footer-preview">{footer}</CapLabel> : '',
107
115
  templateMsg: <CapLabel type={isPreview ? 'label5' : 'label9'}>{text}</CapLabel>,
108
- charCount: text?.length - 1,
116
+ charCount: text?.length - 1 + header?.length + footer?.length,
109
117
  ...(buttonType === CTA && {
110
- ctaData,
118
+ ctaData: buttonsData
119
+ }),
120
+ ...(buttonType === QUICK_REPLY && {
121
+ quickReplyData: buttonsData
111
122
  }),
112
123
  ...mediaParams,
113
124
  };
@@ -143,6 +154,37 @@ export const getWhatsappCta = (template) => {
143
154
  return renderArray;
144
155
  };
145
156
 
157
+ // It will render all the quick reply button in mobile preview and template list
158
+ export const getWhatsappQuickReply= (template, templatePreview) => {
159
+ const { buttonType = NONE, buttons = [] } = templatePreview ? template : get(
160
+ template,
161
+ `versions.base.content.whatsapp`,
162
+ {},
163
+ );
164
+ const renderArray = [];
165
+ if (buttonType === QUICK_REPLY && buttons?.length) {
166
+ renderArray.push(<CapDivider className={templatePreview ? "whatsapp-divider" : "whatsapp-list-view-divider"} />);
167
+ buttons?.forEach((quickReply, index) => {
168
+ const { text } = quickReply || {};
169
+ if (text) {
170
+ renderArray.push(
171
+ <CapLabel type="label21" className={templatePreview ? "whatsapp-cta-preview" : "whatsapp-list-quick-reply-preview"}>
172
+ <CapIcon
173
+ type='small-link'
174
+ size="xs"
175
+ />
176
+ {text}
177
+ </CapLabel>
178
+ )
179
+ }
180
+ if (index < buttons?.length -1) {
181
+ renderArray.push(<CapDivider className={templatePreview ? "whatsapp-divider" : "whatsapp-list-view-divider"} />);
182
+ }
183
+ })
184
+ }
185
+ return renderArray;
186
+ }
187
+
146
188
  export const getWhatsappCategory = (category, hostName) => (
147
189
  hostName === HOST_TWILIO ? TWILIO_CATEGORY_OPTIONS : [...KARIX_GUPSHUP_CATEGORY_OPTIONS, ...KARIX_GUPSHUP_OLDER_CATEGORY_OPTIONS]
148
190
  ).find((obj) => obj.value === category);
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import { FormattedMessage } from "react-intl";
3
- import { CapImage, CapLabel } from "@capillarytech/cap-ui-library";
3
+ import { CapImage, CapLabel, CapDivider, CapIcon } from "@capillarytech/cap-ui-library";
4
4
  import pdfIcon from "../assets/pdfIcon.svg";
5
5
  import messages from "./Whatsapp/messages";
6
6
 
@@ -1417,6 +1417,107 @@ export default {
1417
1417
  updatedAt: "2022-07-17T11:08:56.326Z",
1418
1418
  totalCount: 7,
1419
1419
  },
1420
+ whatsappPreviewTemplateData3: {
1421
+ mode: "preview",
1422
+ _id: "62d3edc8b497b63ff5bbf8ea",
1423
+ name: "test_twilio_159425",
1424
+ type: "WHATSAPP",
1425
+ versions: {
1426
+ $init: true,
1427
+ history: [],
1428
+ base: {
1429
+ content: {
1430
+ whatsapp: {
1431
+ status: "approved",
1432
+ templateId: "HTee0274fb8dfdd45427bb678f875b0d54",
1433
+ hostName: "twiliowhatsapptrans",
1434
+ accessToken: "4676323eb5d1f975b0987070c03a8efc",
1435
+ accountId: "AC41030cebba9e2f1ce37c78235da0ee18",
1436
+ templateEditor: false,
1437
+ mediaType: "TEXT",
1438
+ languages: [
1439
+ {
1440
+ content: "Hi, your payment is successful.",
1441
+ language: "en",
1442
+ },
1443
+ ],
1444
+ category: "ALERT_UPDATE",
1445
+ rejection_reason: null,
1446
+ whatsappMedia: {
1447
+ header: "Hello welcome",
1448
+ footer: "Thanks",
1449
+ },
1450
+ buttonType: "QUICK_REPLY",
1451
+ buttons: [
1452
+ {
1453
+ index: 0,
1454
+ type: "QUICK_REPLY",
1455
+ text: "Interested",
1456
+ },
1457
+ {
1458
+ index: 0,
1459
+ type: "QUICK_REPLY",
1460
+ text: "Not Interested",
1461
+ },
1462
+ ],
1463
+ },
1464
+ },
1465
+ },
1466
+ },
1467
+ isActive: true,
1468
+ orgId: 50371,
1469
+ createdBy: "15000449",
1470
+ updatedBy: "15000449",
1471
+ createdAt: "2022-07-17T11:08:56.326Z",
1472
+ updatedAt: "2022-07-17T11:08:56.326Z",
1473
+ totalCount: 7,
1474
+ },
1475
+ whatsappPreviewTemplateData3Result: {
1476
+ quickReplyData: [
1477
+ {
1478
+ index: 0,
1479
+ type: "QUICK_REPLY",
1480
+ text: "Interested",
1481
+ },
1482
+ {
1483
+ index: 0,
1484
+ type: "QUICK_REPLY",
1485
+ text: "Not Interested",
1486
+ },
1487
+ ],
1488
+ charCount: 49,
1489
+ templateFooterPreview: (
1490
+ <CapLabel className="whatsapp-template-list-footer-preview" type="label1">
1491
+ Thanks
1492
+ </CapLabel>
1493
+ ),
1494
+ templateHeaderPreview: (
1495
+ <CapLabel className="whatsapp-template-list-header-preview" type="label1">
1496
+ Hello welcome
1497
+ </CapLabel>
1498
+ ),
1499
+ templateMsg: (
1500
+ <CapLabel type="label9">Hi, your payment is successful.</CapLabel>
1501
+ ),
1502
+ },
1503
+ whatsappPreviewTemplateData3QuickReplyResult: [
1504
+ <CapDivider className="whatsapp-list-view-divider" />,
1505
+ <CapLabel className="whatsapp-list-quick-reply-preview" type="label21">
1506
+ <CapIcon
1507
+ size="xs"
1508
+ type="small-link"
1509
+ />
1510
+ Interested
1511
+ </CapLabel>,
1512
+ <CapDivider className="whatsapp-list-view-divider" />,
1513
+ <CapLabel className="whatsapp-list-quick-reply-preview" type="label21">
1514
+ <CapIcon
1515
+ size="xs"
1516
+ type="small-link"
1517
+ />
1518
+ Not Interested
1519
+ </CapLabel>,
1520
+ ],
1420
1521
  rcsPreviewTemplateData: {
1421
1522
  mode: "preview",
1422
1523
  _id: "620e213d39bd394c58aeaaca",
@@ -1758,7 +1859,7 @@ export default {
1758
1859
  },
1759
1860
  zaloEditTemplateData: {
1760
1861
  _id: 42342,
1761
- name: 'Test sample',
1762
- type: 'ZALO'
1763
- }
1862
+ name: "Test sample",
1863
+ type: "ZALO",
1864
+ },
1764
1865
  };
File without changes