@capillarytech/creatives-library 7.17.65 → 7.17.66-alpha.0
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 +1 -1
- package/utils/common.js +41 -1
- package/v2Components/CapTagList/index.js +3 -3
- package/v2Containers/TagList/index.js +15 -12
package/package.json
CHANGED
package/utils/common.js
CHANGED
|
@@ -166,7 +166,9 @@ export function getTreeStructuredTags({tagsList, userLocale = 'en', offerDetails
|
|
|
166
166
|
}
|
|
167
167
|
});
|
|
168
168
|
let combinedTags = result;
|
|
169
|
-
if (offerDetails.length) {
|
|
169
|
+
if (offerDetails.length && offerDetails[0].type === 'BADGES') {
|
|
170
|
+
combinedTags = transformBadgeTags(offerDetails, result);
|
|
171
|
+
} else {
|
|
170
172
|
combinedTags = transformCouponTags(offerDetails, result);
|
|
171
173
|
}
|
|
172
174
|
return getTreeStructureData(combinedTags);
|
|
@@ -227,6 +229,44 @@ function transformCouponTags(offerDetails, allTags) {
|
|
|
227
229
|
return allTags;
|
|
228
230
|
}
|
|
229
231
|
|
|
232
|
+
export function transformBadgeTags(badgeDetails, allTags) {
|
|
233
|
+
const badgeTags = {};
|
|
234
|
+
const badgeTagsKeys = Object.keys(_.get(allTags, 'Badge.subtags', []));
|
|
235
|
+
const withBadgeId = (obj, id) => {
|
|
236
|
+
const tempObj = {};
|
|
237
|
+
if (obj?.subtags) {
|
|
238
|
+
tempObj.subtags = _.mapValues(obj.subtags, (tag) => ({
|
|
239
|
+
...withBadgeId(tag, id),
|
|
240
|
+
}));
|
|
241
|
+
}
|
|
242
|
+
return {
|
|
243
|
+
...obj,
|
|
244
|
+
...tempObj,
|
|
245
|
+
incentiveSeriesId: id,
|
|
246
|
+
};
|
|
247
|
+
};
|
|
248
|
+
badgeDetails.forEach((offer) => {
|
|
249
|
+
const { badgeId, badgeName } = offer;
|
|
250
|
+
const couponSubTags = {};
|
|
251
|
+
badgeTagsKeys.forEach((badgeTagKey) => {
|
|
252
|
+
const badgeSubTagsObj = withBadgeId(allTags?.Badge?.subtags[badgeTagKey], badgeId);
|
|
253
|
+
couponSubTags[badgeTagKey] = badgeSubTagsObj;
|
|
254
|
+
});
|
|
255
|
+
const key = badgeName || badgeId;
|
|
256
|
+
badgeTags[key] = {
|
|
257
|
+
'tag-header': true,
|
|
258
|
+
'name': badgeName,
|
|
259
|
+
'desc': badgeName,
|
|
260
|
+
'incentiveSeriesId': badgeId,
|
|
261
|
+
'subtags': couponSubTags,
|
|
262
|
+
'resolved': true,
|
|
263
|
+
'badgeTags': true,
|
|
264
|
+
};
|
|
265
|
+
});
|
|
266
|
+
// eslint-disable-next-line no-param-reassign
|
|
267
|
+
allTags.Badge.subtags = badgeTags;
|
|
268
|
+
}
|
|
269
|
+
|
|
230
270
|
function populateTagForChildren(targetTag, tagsObject, tagValue) {
|
|
231
271
|
const tag = targetTag;
|
|
232
272
|
if (tag && tag['tag-header'] && !tag.resolved) {
|
|
@@ -202,9 +202,9 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
202
202
|
const temp = this.renderTags(val.subtags, '', disabled);
|
|
203
203
|
const tagValue = (
|
|
204
204
|
<CapTreeNode
|
|
205
|
-
title={disabled ? <CapTooltip title={loyaltyAttrDisableText}>{val
|
|
205
|
+
title={disabled ? <CapTooltip title={loyaltyAttrDisableText}>{val?.name}</CapTooltip> : val?.name}
|
|
206
206
|
tag={val}
|
|
207
|
-
key={val
|
|
207
|
+
key={val?.incentiveSeriesId ? `${key}(${val?.incentiveSeriesId})` : `${key}`}
|
|
208
208
|
disabled={disabled}
|
|
209
209
|
>
|
|
210
210
|
{temp}
|
|
@@ -223,7 +223,7 @@ class CapTagList extends React.Component { // eslint-disable-line react/prefer-s
|
|
|
223
223
|
title={childDisabled ? <CapTooltip title={key === CUSTOMER_BARCODE_TAG ? customerBarcodeDisableText : loyaltyAttrDisableText}>{val.desc || val.name}</CapTooltip> : (val.desc || val.name)}
|
|
224
224
|
tag={val}
|
|
225
225
|
isLeaf
|
|
226
|
-
key={val.
|
|
226
|
+
key={val.incentiveSeriesId ? `${key}(${val.incentiveSeriesId})` : `${key}`}
|
|
227
227
|
disabled={childDisabled}
|
|
228
228
|
>
|
|
229
229
|
</CapTreeNode>);
|
|
@@ -22,7 +22,7 @@ import './_tagList.scss';
|
|
|
22
22
|
import { selectCurrentOrgDetails } from '../Cap/selectors';
|
|
23
23
|
import { injectIntl } from 'react-intl';
|
|
24
24
|
import { scope } from './messages';
|
|
25
|
-
import { handleInjectedData, hasGiftVoucherFeature, hasPromoFeature, hasBadgesFeature } from '../../utils/common';
|
|
25
|
+
import { handleInjectedData, hasGiftVoucherFeature, hasPromoFeature, hasBadgesFeature, transformBadgeTags } from '../../utils/common';
|
|
26
26
|
import { GIFT_VOUCHER_RELATED_TAGS, PROMO_ENGINE_RELATED_TAGS, BADGES_RELATED_TAGS } from '../../containers/App/constants';
|
|
27
27
|
|
|
28
28
|
const TreeNode = Tree.TreeNode;
|
|
@@ -50,14 +50,11 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
50
50
|
this.setState({loading: true});
|
|
51
51
|
}
|
|
52
52
|
if (!_.isEqual(nextProps.injectedTags, this.props.injectedTags)) {
|
|
53
|
-
|
|
54
53
|
this.setState({loading: false});
|
|
55
54
|
}
|
|
56
55
|
if (!_.isEqual(nextProps.tags, this.props.tags)) {
|
|
57
|
-
|
|
58
56
|
this.setState({loading: false});
|
|
59
57
|
}
|
|
60
|
-
|
|
61
58
|
}
|
|
62
59
|
componentDidUpdate(prevProps) {
|
|
63
60
|
if (this.props.tags !== prevProps.tags || this.props.injectedTags !== prevProps.injectedTags || this.props.selectedOfferDetails !== prevProps.selectedOfferDetails) {
|
|
@@ -89,8 +86,14 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
89
86
|
if (props.tags && props.tags.length > 0) {
|
|
90
87
|
tags = this.populateTags(props.tags);
|
|
91
88
|
}
|
|
89
|
+
console.log(`selected Badges: ${props.selectedOfferDetails}, ${JSON.stringify(tags)}`);
|
|
92
90
|
if (props.selectedOfferDetails && !_.isEmpty(props.selectedOfferDetails) && (tags && tags.coupon)) {
|
|
93
|
-
|
|
91
|
+
console.log(`selected offers: ${JSON.stringify(props.selectedOfferDetails)}`);
|
|
92
|
+
if (props.selectedOfferDetails[0]?.type === 'BADGES') {
|
|
93
|
+
transformBadgeTags(props.selectedOfferDetails, tags);
|
|
94
|
+
} else {
|
|
95
|
+
this.transformCouponTags(props.selectedOfferDetails, tags);
|
|
96
|
+
}
|
|
94
97
|
}
|
|
95
98
|
this.setState({tags: _.merge( {}, tags, injectedTags)});
|
|
96
99
|
}
|
|
@@ -120,8 +123,8 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
120
123
|
}
|
|
121
124
|
if (!tag['tag-header']) {
|
|
122
125
|
mainTags[tag.value] = {
|
|
123
|
-
|
|
124
|
-
|
|
126
|
+
name: tag?.label[userLocale] ? tag?.label[userLocale] : tag?.label?.en,
|
|
127
|
+
desc: tag?.label[userLocale] ? tag?.label[userLocale] : tag?.label?.en,
|
|
125
128
|
};
|
|
126
129
|
} else if (tag['tag-header'] && mainTags[tag.value]) {
|
|
127
130
|
mainTags[tag.value].subtags = _.concat(mainTags[tag.value].subtags, tag.subtags);
|
|
@@ -197,12 +200,12 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
197
200
|
return {
|
|
198
201
|
...obj,
|
|
199
202
|
...tempObj,
|
|
200
|
-
|
|
203
|
+
incentiveSeriesId: id,
|
|
201
204
|
};
|
|
202
205
|
};
|
|
203
206
|
offerDetails.forEach((offer) => {
|
|
204
|
-
const { id, couponName, description,
|
|
205
|
-
const couponId = id ||
|
|
207
|
+
const { id, couponName, description, incentiveSeriesId } = offer;
|
|
208
|
+
const couponId = id || incentiveSeriesId;
|
|
206
209
|
const couponSubTags = {};
|
|
207
210
|
couponTagsKeys.forEach((couponTagKey) => {
|
|
208
211
|
const couponSubTagsObj = withCouponId(allTags.coupon.subtags[couponTagKey], couponId);
|
|
@@ -214,7 +217,7 @@ export class TagList extends React.Component { // eslint-disable-line react/pref
|
|
|
214
217
|
'tag-header': true,
|
|
215
218
|
'name': couponNameFinal || couponId,
|
|
216
219
|
'desc': couponNameFinal || couponId,
|
|
217
|
-
'
|
|
220
|
+
'incentiveSeriesId': couponId,
|
|
218
221
|
'subtags': couponSubTags,
|
|
219
222
|
'resolved': true,
|
|
220
223
|
'couponTags': true,
|
|
@@ -306,7 +309,7 @@ TagList.propTypes = {
|
|
|
306
309
|
modalProps: PropTypes.any,
|
|
307
310
|
currentOrgDetails: PropTypes.object,
|
|
308
311
|
channel: PropTypes.string,
|
|
309
|
-
disabled: PropTypes.bool
|
|
312
|
+
disabled: PropTypes.bool,
|
|
310
313
|
};
|
|
311
314
|
|
|
312
315
|
const mapStateToProps = createStructuredSelector({
|