@capillarytech/creatives-library 7.17.82-alpha.1 → 7.17.83
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
|
@@ -346,28 +346,29 @@ export class TemplatePreview extends React.Component { // eslint-disable-line re
|
|
|
346
346
|
const renderUrlPreview = (metaTags) => {
|
|
347
347
|
const renderArray = [];
|
|
348
348
|
if (!isEmpty(metaTags)) {
|
|
349
|
-
|
|
349
|
+
const { image = '', title = '', description = '', url = '' } = metaTags || {};
|
|
350
|
+
if (image) {
|
|
350
351
|
renderArray.push(
|
|
351
352
|
<CapImage
|
|
352
|
-
src={
|
|
353
|
+
src={image}
|
|
353
354
|
alt={formatMessage(messages.previewUrlMetaImage)}
|
|
354
355
|
className="url-preview-image"
|
|
355
356
|
/>
|
|
356
357
|
);
|
|
357
358
|
}
|
|
358
|
-
if (
|
|
359
|
+
if (title) {
|
|
359
360
|
renderArray.push(
|
|
360
|
-
<CapLabel type="label8">{
|
|
361
|
+
<CapLabel type="label8">{title}</CapLabel>
|
|
361
362
|
);
|
|
362
363
|
}
|
|
363
|
-
if (
|
|
364
|
+
if (description) {
|
|
364
365
|
renderArray.push(
|
|
365
|
-
<CapLabel className="url-preview-description">{
|
|
366
|
+
<CapLabel className="url-preview-description">{description}</CapLabel>
|
|
366
367
|
);
|
|
367
368
|
}
|
|
368
|
-
if (
|
|
369
|
+
if (url) {
|
|
369
370
|
renderArray.push(
|
|
370
|
-
<CapLabel className="url-preview">{
|
|
371
|
+
<CapLabel className="url-preview">{url}</CapLabel>
|
|
371
372
|
);
|
|
372
373
|
}
|
|
373
374
|
}
|
|
@@ -788,7 +789,7 @@ export class TemplatePreview extends React.Component { // eslint-disable-line re
|
|
|
788
789
|
<div className="msg-container whatsapp-message-container">
|
|
789
790
|
<div className="message-pop align-left" style={whatsappSectionStyle}>
|
|
790
791
|
<div className="whatsapp-content">
|
|
791
|
-
{content?.
|
|
792
|
+
{content?.showUrlPreview && (
|
|
792
793
|
renderUrlPreview(content?.metaTagsDetails)
|
|
793
794
|
)}
|
|
794
795
|
{content?.whatsappImageSrc && (
|
|
@@ -25,6 +25,7 @@ import CapAlert from '@capillarytech/cap-ui-library/CapAlert';
|
|
|
25
25
|
import CapCheckbox from '@capillarytech/cap-ui-library/CapCheckbox';
|
|
26
26
|
import CapLink from '@capillarytech/cap-ui-library/CapLink';
|
|
27
27
|
import moment from 'moment';
|
|
28
|
+
import debounce from 'lodash/debounce';
|
|
28
29
|
import {
|
|
29
30
|
CAP_SPACE_04,
|
|
30
31
|
CAP_SPACE_16,
|
|
@@ -181,12 +182,12 @@ export const Whatsapp = (props) => {
|
|
|
181
182
|
const [headerTextAreaId, setHeaderTextAreaId] = useState('');
|
|
182
183
|
const [isHeaderTagValidationError, updateIsHeaderTagValidationError] =
|
|
183
184
|
useState(false);
|
|
184
|
-
const [
|
|
185
|
+
const [showUrlPreview, setShowUrlPreview] = useState(false);
|
|
185
186
|
const [previewUrl, setPreviewUrl] = useState('');
|
|
186
187
|
|
|
187
188
|
const validVarRegex = /{{([1-9]|1[0-9])}}/g;
|
|
188
189
|
const headerValidVarRegex = /{{(1)}}/g;
|
|
189
|
-
const
|
|
190
|
+
const previewUrlMatchingRegex = /(http|ftp|https):\/\/([\w_-]+(?:(?:\.[\w_-]+)+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])/g;
|
|
190
191
|
|
|
191
192
|
const isBtnTypeCta = buttonType === WHATSAPP_BUTTON_TYPES.CTA;
|
|
192
193
|
const isBtnTypeQuickReply = buttonType === WHATSAPP_BUTTON_TYPES.QUICK_REPLY;
|
|
@@ -271,7 +272,7 @@ export const Whatsapp = (props) => {
|
|
|
271
272
|
videoPreviewImg = '',
|
|
272
273
|
whatsappDocParams = {},
|
|
273
274
|
whatsappMedia: { header = '', footer = '' } = {},
|
|
274
|
-
isPreviewUrl
|
|
275
|
+
isPreviewUrl = false,
|
|
275
276
|
} = editContent;
|
|
276
277
|
setTemplateCategory(category);
|
|
277
278
|
setTemplateStatus(status);
|
|
@@ -295,7 +296,7 @@ export const Whatsapp = (props) => {
|
|
|
295
296
|
setButtonType(btnType);
|
|
296
297
|
setTemplateFooter(footer);
|
|
297
298
|
setTemplateHeader(header);
|
|
298
|
-
|
|
299
|
+
setShowUrlPreview(isPreviewUrl);
|
|
299
300
|
if (btnType === WHATSAPP_BUTTON_TYPES.CTA && buttons.length > 0) {
|
|
300
301
|
setCtadata(
|
|
301
302
|
buttons.map((cta) => {
|
|
@@ -430,11 +431,10 @@ export const Whatsapp = (props) => {
|
|
|
430
431
|
arr[key.slice(key.indexOf('_') + 1)] = varMap[key];
|
|
431
432
|
}
|
|
432
433
|
}
|
|
434
|
+
// extract preview url from message
|
|
433
435
|
if (arr?.length) {
|
|
434
|
-
const validUrls = arr.join("").match(
|
|
435
|
-
|
|
436
|
-
setPreviewUrl(validUrls?.[0] || '')
|
|
437
|
-
}
|
|
436
|
+
const validUrls = arr.join("").match(previewUrlMatchingRegex) || [];
|
|
437
|
+
setPreviewUrl(validUrls?.[0] || '')
|
|
438
438
|
}
|
|
439
439
|
setUpdatedSmsEditor(arr);
|
|
440
440
|
}
|
|
@@ -478,7 +478,7 @@ export const Whatsapp = (props) => {
|
|
|
478
478
|
|
|
479
479
|
const tagValidation = (contentData, regex, type) => {
|
|
480
480
|
if (contentData?.length > 0 && !contentData.join("").match(regex)) {
|
|
481
|
-
|
|
481
|
+
const validationResponse =
|
|
482
482
|
validateTags({
|
|
483
483
|
content: contentData.join(""),
|
|
484
484
|
tagsParam: tags,
|
|
@@ -486,24 +486,23 @@ export const Whatsapp = (props) => {
|
|
|
486
486
|
location,
|
|
487
487
|
tagModule: getDefaultTags,
|
|
488
488
|
}) || {};
|
|
489
|
+
const unsupportedTagsLengthCheck =
|
|
490
|
+
validationResponse?.unsupportedTags?.length > 0;
|
|
489
491
|
if (type === HEADER_TEXT) {
|
|
490
492
|
headerTagValidationResponse = validationResponse;
|
|
491
|
-
updateIsHeaderTagValidationError(
|
|
492
|
-
validationResponse?.unsupportedTags?.length > 0
|
|
493
|
-
);
|
|
493
|
+
updateIsHeaderTagValidationError(unsupportedTagsLengthCheck);
|
|
494
494
|
} else {
|
|
495
495
|
tagValidationResponse = validationResponse;
|
|
496
|
-
updateIsTagValidationError(
|
|
497
|
-
validationResponse?.unsupportedTags?.length > 0
|
|
498
|
-
);
|
|
496
|
+
updateIsTagValidationError(unsupportedTagsLengthCheck);
|
|
499
497
|
}
|
|
500
498
|
}
|
|
501
499
|
};
|
|
502
500
|
|
|
501
|
+
// as per change in message body we filter out url using regex
|
|
503
502
|
useEffect(() => {
|
|
504
503
|
if (updatedSmsEditor?.length > 0) {
|
|
505
|
-
const previewUrlArr = updatedSmsEditor.join("").match(
|
|
506
|
-
if (previewUrlArr
|
|
504
|
+
const previewUrlArr = updatedSmsEditor.join("").match(previewUrlMatchingRegex) || [];
|
|
505
|
+
if (previewUrlArr?.length > 0) {
|
|
507
506
|
setPreviewUrl(previewUrlArr[0]);
|
|
508
507
|
} else {
|
|
509
508
|
setPreviewUrl('');
|
|
@@ -511,19 +510,24 @@ export const Whatsapp = (props) => {
|
|
|
511
510
|
}
|
|
512
511
|
}, [updatedSmsEditor])
|
|
513
512
|
|
|
513
|
+
const debounceFn = useCallback(
|
|
514
|
+
debounce(url => {
|
|
515
|
+
actions.getMetaTags({
|
|
516
|
+
previewUrl: url,
|
|
517
|
+
callBack: actionCallback,
|
|
518
|
+
})
|
|
519
|
+
}, 500),
|
|
520
|
+
[],
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
// as per change in url and preview checkbox we call api and extract the meta information of url
|
|
514
524
|
useEffect(() => {
|
|
515
|
-
if (!isEmpty(previewUrl) &&
|
|
516
|
-
|
|
517
|
-
actions.getMetaTags({
|
|
518
|
-
previewUrl,
|
|
519
|
-
callBack: actionCallback,
|
|
520
|
-
})
|
|
521
|
-
}, 1000);
|
|
522
|
-
return () => clearTimeout(watingTimeFn);
|
|
525
|
+
if (!isEmpty(previewUrl) && showUrlPreview) {
|
|
526
|
+
debounceFn(previewUrl);
|
|
523
527
|
} else {
|
|
524
528
|
actions.resetMetaTags();
|
|
525
529
|
}
|
|
526
|
-
}, [previewUrl,
|
|
530
|
+
}, [previewUrl, showUrlPreview])
|
|
527
531
|
|
|
528
532
|
//performs tag validation
|
|
529
533
|
useEffect(() => {
|
|
@@ -828,7 +832,7 @@ export const Whatsapp = (props) => {
|
|
|
828
832
|
};
|
|
829
833
|
|
|
830
834
|
const previewUrlHandler = ({ target: { checked } }) => {
|
|
831
|
-
|
|
835
|
+
setShowUrlPreview(checked);
|
|
832
836
|
}
|
|
833
837
|
|
|
834
838
|
const renderUnsubscribeText = () => {
|
|
@@ -1291,7 +1295,7 @@ export const Whatsapp = (props) => {
|
|
|
1291
1295
|
}),
|
|
1292
1296
|
},
|
|
1293
1297
|
...(isEditFlow && !isFullMode && {
|
|
1294
|
-
isPreviewUrl
|
|
1298
|
+
isPreviewUrl: showUrlPreview
|
|
1295
1299
|
})
|
|
1296
1300
|
},
|
|
1297
1301
|
},
|
|
@@ -1910,11 +1914,11 @@ export const Whatsapp = (props) => {
|
|
|
1910
1914
|
<CapCheckbox
|
|
1911
1915
|
className={`whatsapp-unsubscribe-checkbox ${'whatsapp-create-unsubscribe-checkbox'}`}
|
|
1912
1916
|
onChange={previewUrlHandler}
|
|
1913
|
-
checked={
|
|
1917
|
+
checked={showUrlPreview}
|
|
1914
1918
|
disabled={!isMediaTypeText}
|
|
1915
1919
|
autoFocus={true}
|
|
1916
1920
|
>
|
|
1917
|
-
<span className="whatsapp-render-url-preview-
|
|
1921
|
+
<span className="whatsapp-render-url-preview-text">
|
|
1918
1922
|
{formatMessage(messages.showUrlPreview)}
|
|
1919
1923
|
</span>
|
|
1920
1924
|
</CapCheckbox>
|
|
@@ -2034,8 +2038,8 @@ export const Whatsapp = (props) => {
|
|
|
2034
2038
|
...(isBtnTypeQuickReply && {
|
|
2035
2039
|
quickReplyData,
|
|
2036
2040
|
}),
|
|
2037
|
-
...(isMediaTypeText &&
|
|
2038
|
-
|
|
2041
|
+
...(isMediaTypeText && showUrlPreview && {
|
|
2042
|
+
showUrlPreview,
|
|
2039
2043
|
metaTagsDetails,
|
|
2040
2044
|
}),
|
|
2041
2045
|
}}
|
|
@@ -127365,7 +127365,7 @@ T&C'
|
|
|
127365
127365
|
type="h4"
|
|
127366
127366
|
>
|
|
127367
127367
|
<span
|
|
127368
|
-
className="whatsapp-render-url-preview-
|
|
127368
|
+
className="whatsapp-render-url-preview-text"
|
|
127369
127369
|
/>
|
|
127370
127370
|
</span>
|
|
127371
127371
|
</CapHeading__CapHeadingSpan>
|
|
@@ -141131,7 +141131,7 @@ T&C'
|
|
|
141131
141131
|
type="h4"
|
|
141132
141132
|
>
|
|
141133
141133
|
<span
|
|
141134
|
-
className="whatsapp-render-url-preview-
|
|
141134
|
+
className="whatsapp-render-url-preview-text"
|
|
141135
141135
|
/>
|
|
141136
141136
|
</span>
|
|
141137
141137
|
</CapHeading__CapHeadingSpan>
|
|
@@ -152929,7 +152929,7 @@ new message content.",
|
|
|
152929
152929
|
type="h4"
|
|
152930
152930
|
>
|
|
152931
152931
|
<span
|
|
152932
|
-
className="whatsapp-render-url-preview-
|
|
152932
|
+
className="whatsapp-render-url-preview-text"
|
|
152933
152933
|
/>
|
|
152934
152934
|
</span>
|
|
152935
152935
|
</CapHeading__CapHeadingSpan>
|
|
@@ -167284,7 +167284,7 @@ T&C'
|
|
|
167284
167284
|
type="h4"
|
|
167285
167285
|
>
|
|
167286
167286
|
<span
|
|
167287
|
-
className="whatsapp-render-url-preview-
|
|
167287
|
+
className="whatsapp-render-url-preview-text"
|
|
167288
167288
|
/>
|
|
167289
167289
|
</span>
|
|
167290
167290
|
</CapHeading__CapHeadingSpan>
|
|
@@ -187132,7 +187132,7 @@ Click {{unsubscribe}} to unsubscribe",
|
|
|
187132
187132
|
type="h4"
|
|
187133
187133
|
>
|
|
187134
187134
|
<span
|
|
187135
|
-
className="whatsapp-render-url-preview-
|
|
187135
|
+
className="whatsapp-render-url-preview-text"
|
|
187136
187136
|
/>
|
|
187137
187137
|
</span>
|
|
187138
187138
|
</CapHeading__CapHeadingSpan>
|
|
@@ -199514,7 +199514,7 @@ new message content.",
|
|
|
199514
199514
|
type="h4"
|
|
199515
199515
|
>
|
|
199516
199516
|
<span
|
|
199517
|
-
className="whatsapp-render-url-preview-
|
|
199517
|
+
className="whatsapp-render-url-preview-text"
|
|
199518
199518
|
/>
|
|
199519
199519
|
</span>
|
|
199520
199520
|
</CapHeading__CapHeadingSpan>
|