@capillarytech/creatives-library 8.0.68-alpha.3 → 8.0.68

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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@capillarytech/creatives-library",
3
3
  "author": "meharaj",
4
- "version": "8.0.68-alpha.3",
4
+ "version": "8.0.68",
5
5
  "description": "Capillary creatives ui",
6
6
  "main": "./index.js",
7
7
  "module": "./index.es.js",
@@ -1,90 +1,92 @@
1
1
  export const expectedStateGetLiquidTagsRequest = {
2
- fetchingLiquidTags: true,
3
- fetchingSchema: true,
4
- fetchingSchemaError: "",
5
- liquidTags: [],
6
- messages: [],
7
- metaEntities: {
8
- layouts: [],
9
- tagLookupMap: {},
10
- tags: []
11
- },
12
- orgID: "",
13
- token: ""
14
- };
15
-
16
- export const expectedStateGetLiquidTagsFailure = {
17
- fetchingLiquidTags: false,
18
- fetchingSchema: true,
19
- fetchingSchemaError: "",
20
- liquidTags: [],
21
- messages: [],
22
- metaEntities: {
23
- layouts: [],
24
- tagLookupMap: {},
25
- tags: []
26
- },
27
- orgID: "",
28
- token: ""
29
- };
30
-
31
- export const expectedStateGetLiquidTagsSuccess = {
32
- fetchingLiquidTags: false,
33
- fetchingSchema: true,
34
- fetchingSchemaError: "",
35
- liquidTags: [],
36
- messages: [],
37
- metaEntities: {
38
- layouts: [],
39
- tagLookupMap: {},
40
- tags: []
41
- },
42
- orgID: "",
43
- token: ""
44
- };
45
-
46
- export const expectedStateGetSchemaForEntitySuccessTAG = {
47
- fetchingLiquidTags: false,
48
- fetchingSchema: false,
49
- fetchingSchemaError: false,
50
- liquidTags: [],
51
- messages: [],
52
- metaEntities: {
53
- layouts: undefined,
54
- tagLookupMap: { undefined: {definition: {}} },
55
- tags: { standard: { random: "32" } }
56
- },
57
- orgID: "",
58
- token: ""
59
- };
60
-
61
- export const expectedStateGetSchemaForEntitySuccess = {
62
- fetchingLiquidTags: false,
63
- fetchingSchema: false,
64
- fetchingSchemaError: false,
65
- liquidTags: [],
66
- messages: [],
67
- metaEntities: {
68
- layouts: undefined,
69
- tagLookupMap: undefined,
70
- tags: undefined
71
- },
72
- orgID: "",
73
- token: ""
74
- };
2
+ fetchingLiquidTags: true,
3
+ fetchingSchema: true,
4
+ fetchingSchemaError: "",
5
+ liquidTags: [],
6
+ messages: [],
7
+ metaEntities: {
8
+ layouts: [],
9
+ tagLookupMap: {},
10
+ tags: [],
11
+ },
12
+ orgID: "",
13
+ token: "",
14
+ };
15
+
16
+ export const expectedStateGetLiquidTagsFailure = {
17
+ fetchingLiquidTags: false,
18
+ fetchingSchema: true,
19
+ fetchingSchemaError: "",
20
+ liquidTags: [],
21
+ messages: [],
22
+ metaEntities: {
23
+ layouts: [],
24
+ tagLookupMap: {},
25
+ tags: [],
26
+ },
27
+ orgID: "",
28
+ token: "",
29
+ };
30
+
31
+ export const expectedStateGetLiquidTagsSuccess = {
32
+ fetchingLiquidTags: false,
33
+ fetchingSchema: true,
34
+ fetchingSchemaError: "",
35
+ liquidTags: [],
36
+ messages: [],
37
+ metaEntities: {
38
+ layouts: [],
39
+ tagLookupMap: {},
40
+ tags: [],
41
+ },
42
+ orgID: "",
43
+ token: "",
44
+ };
45
+
46
+ export const expectedStateGetSchemaForEntitySuccessTAG = {
47
+ fetchingLiquidTags: false,
48
+ fetchingSchema: false,
49
+ fetchingSchemaError: false,
50
+ liquidTags: [],
51
+ messages: [],
52
+ metaEntities: {
53
+ layouts: undefined,
54
+ tagLookupMap: { undefined: { definition: {} } },
55
+ tags: { standard: { random: "32" } },
56
+ },
57
+ orgID: "",
58
+ token: "",
59
+ };
60
+
61
+ export const expectedStateGetSchemaForEntitySuccess = {
62
+ fetchingLiquidTags: false,
63
+ fetchingSchema: false,
64
+ fetchingSchemaError: false,
65
+ liquidTags: [],
66
+ messages: [],
67
+ metaEntities: {
68
+ layouts: undefined,
69
+ tagLookupMap: undefined,
70
+ tags: undefined,
71
+ },
72
+ orgID: "",
73
+ token: "",
74
+ };
75
+
76
+ export const expectedForwardedTags = {
77
+ fetchingLiquidTags: false,
78
+ fetchingSchema: false,
79
+ fetchingSchemaError: '',
80
+ injectedTags: undefined,
81
+ liquidTags: [],
82
+ messages: [],
83
+ metaEntities: {
84
+ layouts: [],
85
+ tagLookupMap: {
75
86
 
76
- export const expectedForwardedTags = {
77
- fetchingLiquidTags: false,
78
- fetchingSchema: true,
79
- fetchingSchemaError: '',
80
- injectedTags: undefined,
81
- liquidTags: [],
82
- messages: [],
83
- metaEntities: {
84
- layouts: [],
85
- tagLookupMap: {},
86
- tags: []
87
87
  },
88
- orgID: "",
89
- token: ""
90
- };
88
+ tags: [],
89
+ },
90
+ orgID: "",
91
+ token: "",
92
+ };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Created by vivek on 22/5/17.
3
3
  */
4
- import { fromJS } from 'immutable';
4
+ import { fromJS, Map as ImmutableMap } from 'immutable';
5
5
  import _ from 'lodash';
6
6
  import * as types from './constants';
7
7
  import initialState from '../../initialState';
@@ -113,20 +113,28 @@ function capReducer(state = fromJS(initialState.cap), action) {
113
113
  // Process extended tags
114
114
  const extendedSubtags = getTagMapValue(action?.data?.metaEntities?.extended);
115
115
 
116
+ const getExistingTagLookupMap = (state) => {
117
+ if (!state || !state.get) return {};
118
+ const tagLookupMap = state.getIn(['metaEntities', 'tagLookupMap']);
119
+ return state.get('metaEntities') && ImmutableMap.isMap(tagLookupMap)
120
+ ? tagLookupMap.toJS()
121
+ : {};
122
+ };
123
+
116
124
  // Combine all maps
117
125
  const combinedTagMap = {
118
126
  ...standardTagMap,
119
127
  ...customSubtags,
120
128
  ...extendedSubtags,
121
- ...state.getIn(['metaEntities', 'tagLookupMap'])?.toJS(),
129
+ ...getExistingTagLookupMap(state),
122
130
  };
123
131
  const stateMeta = state.get("metaEntities");
124
132
  return state
125
133
  .set('fetchingSchema', false)
126
134
  .set('fetchingLiquidTags', false)
127
135
  .set('metaEntities', {
128
- layouts: action.data && action.entityType === 'LAYOUT' ? action.data.metaEntities : stateMeta.layouts,
129
- tags: action.data && action.entityType === 'TAG' ? action.data.metaEntities : stateMeta.tags,
136
+ layouts: action.data && action.entityType === 'LAYOUT' ? action.data.metaEntities : stateMeta?.layouts,
137
+ tags: action.data && action.entityType === 'TAG' ? action.data.metaEntities : stateMeta?.tags,
130
138
  tagLookupMap: action?.data && action?.entityType === TAG ? combinedTagMap : stateMeta?.tagLookupMap,
131
139
  })
132
140
  .set('fetchingSchemaError', false);
@@ -1,16 +1,16 @@
1
- import { fromJS } from 'immutable';
1
+ import { fromJS, Map as ImmutableMap } from 'immutable';
2
2
  import {
3
- GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
4
- GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
5
- GET_SUPPORT_VIDEOS_CONFIG_FAILURE,
6
- REQUEST,
7
- SUCCESS,
8
- FAILURE,
9
- GET_LIQUID_TAGS_SUCCESS,
10
- GET_LIQUID_TAGS_FAILURE,
11
- GET_LIQUID_TAGS_REQUEST,
12
- GET_SCHEMA_FOR_ENTITY_SUCCESS,
13
- SET_INJECTED_TAGS,
3
+ GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
4
+ GET_SUPPORT_VIDEOS_CONFIG_SUCCESS,
5
+ GET_SUPPORT_VIDEOS_CONFIG_FAILURE,
6
+ REQUEST,
7
+ SUCCESS,
8
+ FAILURE,
9
+ GET_LIQUID_TAGS_SUCCESS,
10
+ GET_LIQUID_TAGS_FAILURE,
11
+ GET_LIQUID_TAGS_REQUEST,
12
+ GET_SCHEMA_FOR_ENTITY_SUCCESS,
13
+ SET_INJECTED_TAGS,
14
14
  } from '../constants';
15
15
  import reducer from '../reducer';
16
16
  import initialState from '../../../initialState';
@@ -20,12 +20,13 @@ import {
20
20
  expectedStateGetLiquidTagsSuccess,
21
21
  expectedStateGetSchemaForEntitySuccessTAG,
22
22
  expectedStateGetSchemaForEntitySuccess,
23
- expectedForwardedTags
24
23
  } from '../mockData';
24
+ import { TAG } from '../../Whatsapp/constants';
25
+ import { loadItem } from '../../../services/localStorageApi';
25
26
 
26
- const mockedInitialState = fromJS(initialState.cap);
27
27
 
28
28
  describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
29
+ const mockedInitialState = fromJS(initialState.cap);
29
30
  it('should handle GET_SUPPORT_VIDEOS_CONFIG_REQUEST', () => {
30
31
  const action = {
31
32
  type: GET_SUPPORT_VIDEOS_CONFIG_REQUEST,
@@ -42,7 +43,7 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
42
43
  is_active: true,
43
44
  _id: "12345",
44
45
  json_config: [
45
- { data: 'Test data' },
46
+ { data: 'Test data' },
46
47
  ],
47
48
  };
48
49
  const action = {
@@ -93,8 +94,8 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
93
94
  it('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action with action type as TAG', () => {
94
95
  const action = {
95
96
  type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
96
- data: {metaEntities:{standard:{"random": "32"}}},
97
- entityType: "TAG"
97
+ data: { metaEntities: { standard: { random: "32" } } },
98
+ entityType: "TAG",
98
99
  };
99
100
 
100
101
  expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetSchemaForEntitySuccessTAG);
@@ -103,7 +104,7 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
103
104
  it('handles the GET_SCHEMA_FOR_ENTITY_SUCCESS action', () => {
104
105
  const action = {
105
106
  type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
106
- data: {metaEntities:{standard:{"random": "32"}}},
107
+ data: { metaEntities: { standard: { random: "32" } } },
107
108
  };
108
109
 
109
110
  expect(reducer(mockedInitialState, action).toJS()).toEqual(expectedStateGetSchemaForEntitySuccess);
@@ -113,7 +114,108 @@ describe('should handle GET_SUPPORT_VIDEOS_CONFIG', () => {
113
114
  type: SET_INJECTED_TAGS,
114
115
  data: {},
115
116
  };
116
-
117
+
117
118
  expect(reducer(mockedInitialState, action).toJS())?.fetchingSchema?.toEqual(true);
118
119
  });
119
120
  });
121
+
122
+ describe('GET_SCHEMA_FOR_ENTITY_SUCCESS handler', () => {
123
+ it('should handle existing tagLookupMap correctly when metaEntities and tagLookupMap exist', () => {
124
+ const initialStateTest = fromJS({
125
+ token: loadItem('token') || '',
126
+ orgID: loadItem('orgID') || '',
127
+ messages: [],
128
+ metaEntities: {
129
+ tags: [{ id: 1, name: 'tag1' }],
130
+ layouts: ['layout1', 'layout2'],
131
+ tagLookupMap: {
132
+ existingTag: { definition: { value: 'existing' } },
133
+ anotherTag: { definition: { value: 'another' } },
134
+ },
135
+ standard: [],
136
+ },
137
+ liquidTags: [],
138
+ fetchingLiquidTags: false,
139
+ fetchingSchema: false,
140
+ fetchingSchemaError: '',
141
+ });
142
+
143
+ let action = {
144
+ type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
145
+ entityType: TAG,
146
+ data: {
147
+ metaEntities: {
148
+ standard: [],
149
+ custom: [],
150
+ extended: [],
151
+ },
152
+ },
153
+ };
154
+
155
+ let newState = reducer(initialStateTest, action);
156
+ let metaEntities = newState.get('metaEntities');
157
+
158
+ expect(metaEntities).toEqual(expect.objectContaining({
159
+ tagLookupMap: expect.objectContaining({
160
+ existingTag: expect.objectContaining({
161
+ definition: expect.objectContaining({
162
+ value: 'existing',
163
+ }),
164
+ }),
165
+ }),
166
+ }));
167
+
168
+ action = {
169
+ type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
170
+ entityType: 'LAYOUT',
171
+ data: {
172
+ metaEntities: {
173
+ layouts: ['layout1', 'layout2'],
174
+ standard: [],
175
+ },
176
+ },
177
+ };
178
+ newState = reducer(initialStateTest, action);
179
+ metaEntities = newState.get('metaEntities');
180
+ expect(metaEntities).toEqual(expect.objectContaining({
181
+ layouts: expect.objectContaining({
182
+ layouts: expect.arrayContaining(['layout1', 'layout2']),
183
+ }),
184
+ }));
185
+ });
186
+
187
+ it('should handle non-existent tagLookupMap by returning empty object', () => {
188
+ const initialStateTest = fromJS({
189
+ token: loadItem('token') || '',
190
+ orgID: loadItem('orgID') || '',
191
+ messages: [],
192
+ metaEntities: {
193
+ tagLookupMap: {},
194
+ },
195
+ liquidTags: [],
196
+ fetchingLiquidTags: false,
197
+ fetchingSchema: false,
198
+ fetchingSchemaError: '',
199
+ });
200
+
201
+ const action = {
202
+ type: GET_SCHEMA_FOR_ENTITY_SUCCESS,
203
+ entityType: TAG,
204
+ data: {
205
+ metaEntities: {
206
+ standard: [],
207
+ custom: [],
208
+ extended: [],
209
+ },
210
+ },
211
+ };
212
+
213
+ const newState = reducer(initialStateTest, action);
214
+ const metaEntities = newState.get('metaEntities');
215
+
216
+ // Updated assertions to handle plain object
217
+ expect(metaEntities).toBeDefined();
218
+ expect(metaEntities.tagLookupMap).toBeDefined();
219
+ expect(metaEntities.tagLookupMap).toEqual({});
220
+ });
221
+ });
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import PropTypes from 'prop-types';
3
- import Bugsnag from "@bugsnag/js";
4
3
  import {
5
4
  CapSlideBox,
6
5
  CapHeader,
@@ -140,13 +139,21 @@ export class Creatives extends React.Component {
140
139
  templateData.updatedByName = commonUtil.getUserNameById(userId, usersList);
141
140
  this.setState({ slidBoxContent: constants.PREVIEW, templateData });
142
141
  } else {
143
- if (template?.versions?.base?.content?.zalo?.previewUrl) {
144
- commonUtil.handlePreviewInNewTab(
145
- template.versions.base.content.zalo.previewUrl
146
- );
147
- } else {
148
- Bugsnag.leaveBreadcrumb("Zalo preview url not found");
149
- }
142
+ const {
143
+ name = "",
144
+ sourceAccountIdentifier = "",
145
+ configs: { token = "" } = {},
146
+ } = get(this.props, "Templates.selectedZaloAccount", {});
147
+ const { hostName = '' } = get(this.props, "Templates.senderDetails", {});
148
+ this.props.zaloActions.getTemplateInfoById({
149
+ username: name,
150
+ oa_id: sourceAccountIdentifier,
151
+ token,
152
+ host: hostName,
153
+ id: template?._id,
154
+ preview: true,
155
+ actionCallback: this.actionCallback,
156
+ });
150
157
  }
151
158
  };
152
159
 
@@ -12,7 +12,6 @@ import styled from 'styled-components';
12
12
  import {injectIntl, intlShape, FormattedMessage } from 'react-intl';
13
13
  import { createStructuredSelector } from 'reselect';
14
14
  import moment from "moment";
15
- import Bugsnag from "@bugsnag/js";
16
15
  import get from 'lodash/get';
17
16
  import isEmpty from 'lodash/isEmpty';
18
17
  import isEqual from 'lodash/isEqual';
@@ -534,8 +533,8 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
534
533
  params.accountId = Number(query.account_id);
535
534
  this.getAllTemplates({params});
536
535
  }
537
- }
538
-
536
+ }
537
+
539
538
 
540
539
  if (selectedChannel === "ebill" && nextProps.CreateEbill && nextProps.CreateEbill.createResponse && nextProps.CreateEbill.createResponse.templateId && nextProps.CreateEbill.createResponse.templateId !== '') {
541
540
  const message = `${this.state.channel} ${this.props.intl.formatMessage(messages.templateDuplicateSuccess)}`;
@@ -921,7 +920,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
921
920
  }
922
921
  if (
923
922
  this.state.channel.toLowerCase() === ZALO_LOWERCASE &&
924
- !isEmpty(this.props.Templates?.selectedZaloAccount) &&
923
+ !isEmpty(this.props.Templates?.selectedZaloAccount) &&
925
924
  !params?.isAccountSelection && !isEmpty(this.props.Templates?.selectedZaloAccount?.hostName)
926
925
  ) {
927
926
  const {
@@ -983,7 +982,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
983
982
  default:
984
983
  return selectedWhatsappCategory === category;
985
984
  }
986
- }
985
+ }
987
986
  return true;
988
987
  }
989
988
  filterWhatsappTemplates = (templates) => {
@@ -1221,7 +1220,7 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
1221
1220
  break;
1222
1221
  }
1223
1222
  case MOBILE_PUSH:
1224
- case INAPP:
1223
+ case INAPP:
1225
1224
  templateData.content = template;
1226
1225
  break;
1227
1226
  case WECHAT:
@@ -2190,13 +2189,21 @@ export class Templates extends React.Component { // eslint-disable-line react/pr
2190
2189
  this.setState({ previewTemplate: templateInfo });
2191
2190
  }
2192
2191
  } else {
2193
- if (template?.versions?.base?.content?.zalo?.previewUrl) {
2194
- handlePreviewInNewTab(
2195
- template.versions.base.content.zalo.previewUrl
2196
- );
2197
- } else {
2198
- Bugsnag.leaveBreadcrumb("Zalo preview url not found");
2199
- }
2192
+ const {
2193
+ name = "",
2194
+ sourceAccountIdentifier = "",
2195
+ configs: { token = "" } = {},
2196
+ hostName = "",
2197
+ } = get(this.props, "Templates.selectedZaloAccount", {});
2198
+ this.props.zaloActions.getTemplateInfoById({
2199
+ username: name,
2200
+ oa_id: sourceAccountIdentifier,
2201
+ token: token,
2202
+ host: hostName || this.state.hostName || this.props.Templates?.senderDetails?.hostName,
2203
+ id: template?._id,
2204
+ preview: true,
2205
+ actionCallback: this.actionCallback,
2206
+ });
2200
2207
  }
2201
2208
  }
2202
2209