@capillarytech/creatives-library 8.0.347 → 8.0.348

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/package.json +1 -1
  2. package/services/api.js +0 -20
  3. package/services/tests/api.test.js +0 -59
  4. package/utils/tests/v2Common.test.js +1 -46
  5. package/utils/v2common.js +0 -18
  6. package/v2Components/CapCustomSkeleton/index.js +1 -1
  7. package/v2Components/CapCustomSkeleton/tests/__snapshots__/index.test.js.snap +12 -12
  8. package/v2Components/CommonTestAndPreview/UnifiedPreview/WhatsAppPreviewContent.js +18 -6
  9. package/v2Components/CommonTestAndPreview/UnifiedPreview/_unifiedPreview.scss +27 -0
  10. package/v2Components/CommonTestAndPreview/tests/UnifiedPreview/WhatsAppPreviewContent.test.js +48 -0
  11. package/v2Components/TemplatePreview/_templatePreview.scss +21 -0
  12. package/v2Components/TemplatePreview/index.js +18 -6
  13. package/v2Components/TemplatePreview/tests/__snapshots__/index.test.js.snap +1 -0
  14. package/v2Containers/CreativesContainer/SlideBoxFooter.js +1 -3
  15. package/v2Containers/CreativesContainer/index.js +9 -6
  16. package/v2Containers/CreativesContainer/messages.js +0 -4
  17. package/v2Containers/CreativesContainer/tests/__snapshots__/index.test.js.snap +0 -3
  18. package/v2Containers/Templates/ChannelTypeIllustration.js +6 -23
  19. package/v2Containers/Templates/_templates.scss +24 -179
  20. package/v2Containers/Templates/actions.js +0 -44
  21. package/v2Containers/Templates/constants.js +0 -23
  22. package/v2Containers/Templates/index.js +58 -378
  23. package/v2Containers/Templates/messages.js +0 -88
  24. package/v2Containers/Templates/reducer.js +1 -84
  25. package/v2Containers/Templates/sagas.js +0 -64
  26. package/v2Containers/Templates/selectors.js +0 -12
  27. package/v2Containers/Templates/tests/ChannelTypeIllustration.test.js +0 -12
  28. package/v2Containers/Templates/tests/__snapshots__/index.test.js.snap +1122 -1345
  29. package/v2Containers/Templates/tests/index.test.js +0 -6
  30. package/v2Containers/Templates/tests/reducer.test.js +0 -178
  31. package/v2Containers/Templates/tests/sagas.test.js +8 -390
  32. package/v2Containers/Templates/tests/selector.test.js +0 -32
  33. package/v2Containers/TemplatesV2/TemplatesV2.style.js +1 -1
  34. package/v2Containers/Whatsapp/constants.js +8 -0
  35. package/v2Containers/Whatsapp/index.js +142 -5
  36. package/v2Containers/Whatsapp/index.scss +8 -0
  37. package/v2Containers/Whatsapp/messages.js +16 -0
  38. package/v2Containers/Assets/images/archive_Empty_Illustration.svg +0 -9
@@ -319,6 +319,14 @@ export const WHATSAPP_MEDIA_TYPES = {
319
319
  DOCUMENT: 'DOCUMENT',
320
320
  CAROUSEL: 'CAROUSEL',
321
321
  };
322
+
323
+ export const WHATSAPP_IMAGE_SOURCE = {
324
+ UPLOAD: 'UPLOAD_IMAGE',
325
+ URL: 'ADD_IMAGE_URL',
326
+ };
327
+
328
+ export const ADD_IMAGE_URL_PREVIEW_MARKER = '__add_image_url__';
329
+ export const TEMPLATE_VARIABLE_REGEX = /\{\{.*?\}\}/;
322
330
  export const NONE = 'NONE';
323
331
  export const CTA = 'CTA';
324
332
  export const QUICK_REPLY = 'QUICK_REPLY';
@@ -104,7 +104,8 @@ import {
104
104
  VIDEO,
105
105
  URL,
106
106
  REQUEST,
107
- HOST_KARIX
107
+ HOST_KARIX,
108
+ WHATSAPP_IMAGE_SOURCE,
108
109
  } from './constants';
109
110
  import { transformAssetData, transformToVendorFormat, VENDOR_TYPES, resolveCarouselVideoUpdateFields } from '../../utils/vendorDataTransformers';
110
111
  import { validateCarouselCards } from '../../utils/commonUtils';
@@ -252,12 +253,15 @@ export const Whatsapp = (props) => {
252
253
  const [headerTextAreaId, setHeaderTextAreaId] = useState('');
253
254
  const [isHeaderTagValidationError, updateIsHeaderTagValidationError] =
254
255
  useState(false);
256
+ const [imageURLCursorPosition, setImageURLCursorPosition] = useState(0);
255
257
  const [showUrlPreview, setShowUrlPreview] = useState(false);
256
258
  const [previewUrl, setPreviewUrl] = useState('');
257
259
  const [carouselMediaType, setCarouselMediaType] = useState('image');
258
260
  const [carouselData, setCarouselData] = useState(CAROUSEL_INITIAL_DATA);
259
261
  const [activeIndex, setActiveIndex] = useState(defaultActiveIndex);
260
262
  const [carouselValidateTag, setCarouselValidateTag] = useState(false);
263
+ const [mediaTypeSelection, setMediaTypeSelection] = useState(WHATSAPP_IMAGE_SOURCE.UPLOAD);
264
+ const [imageURL, setImageURL] = useState('');
261
265
  // TestAndPreviewSlidebox state
262
266
  const [showTestAndPreviewSlidebox, setShowTestAndPreviewSlidebox] = useState(false);
263
267
  const [isTestAndPreviewMode, setIsTestAndPreviewMode] = useState(false);
@@ -364,6 +368,7 @@ export const Whatsapp = (props) => {
364
368
  whatsappMedia: { header = '', footer = '', headerVarMapped = [] } = {},
365
369
  isPreviewUrl = false,
366
370
  carouselData : editCarouselData = [],
371
+ isAddImageUrl = false,
367
372
  } = editContent;
368
373
  setTemplateCategory(category);
369
374
  setTemplateStatus(status);
@@ -378,6 +383,14 @@ export const Whatsapp = (props) => {
378
383
  });
379
384
  setWhatsappDocSource(documentUrl);
380
385
  setWhatsappDocParams(whatsappDocParams);
386
+ if (mediaType === WHATSAPP_MEDIA_TYPES.IMAGE) {
387
+ if (isAddImageUrl) {
388
+ setMediaTypeSelection(WHATSAPP_IMAGE_SOURCE.URL);
389
+ setImageURL(imageUrl);
390
+ } else {
391
+ setMediaTypeSelection(WHATSAPP_IMAGE_SOURCE.UPLOAD);
392
+ }
393
+ }
381
394
  if (host === HOST_HAPTIC) {
382
395
  updateAssetList(transformToVendorFormat({
383
396
  ...assetList,
@@ -800,6 +813,15 @@ export const Whatsapp = (props) => {
800
813
  });
801
814
  }
802
815
 
816
+ const onImageURLTagSelect = (data) => {
817
+ const currentURL = imageURL || '';
818
+ const tag = `{{${data}}}`;
819
+ const newURL = currentURL.slice(0, imageURLCursorPosition) + tag + currentURL.slice(imageURLCursorPosition);
820
+ setImageURL(newURL);
821
+ setWhatsappImageSrc(newURL);
822
+ setImageURLCursorPosition(imageURLCursorPosition + tag.length);
823
+ };
824
+
803
825
  //setting the id of currently selected text area, is used onTagSelect
804
826
  const setTextAreaId = ({ target: { id } }, type, carouselIndex) => {
805
827
  if (type === HEADER_TEXT) {
@@ -1151,6 +1173,9 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1151
1173
  );
1152
1174
  } else {
1153
1175
  setWhatsappImageSrc(filePath);
1176
+ if (mediaTypeSelection !== WHATSAPP_IMAGE_SOURCE.URL) {
1177
+ setMediaTypeSelection(WHATSAPP_IMAGE_SOURCE.UPLOAD);
1178
+ }
1154
1179
  if (isHaptic) {
1155
1180
  setHapticFileHandle(fileHandle);
1156
1181
  } else {
@@ -1159,7 +1184,7 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1159
1184
  }
1160
1185
  actions.clearWhatsappAsset(0);
1161
1186
  },
1162
- [whatsappImageSrc, isMediaTypeCarousel, activeIndex, carouselData, isHaptic],
1187
+ [whatsappImageSrc, isMediaTypeCarousel, activeIndex, carouselData, isHaptic, mediaTypeSelection],
1163
1188
  );
1164
1189
 
1165
1190
  const updateOnWhatsappImageReUpload = useCallback(() => {
@@ -1626,8 +1651,10 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1626
1651
  const { whatsappVideoSrc = '', whatsappVideoPreviewImg = '' } = whatsappVideoSrcAndPreview;
1627
1652
  switch (templateMediaType) {
1628
1653
  case WHATSAPP_MEDIA_TYPES.IMAGE:
1654
+ const isImageUrlMode = mediaTypeSelection === WHATSAPP_IMAGE_SOURCE.URL;
1629
1655
  mediaParams = {
1630
1656
  imageUrl: getCdnUrl({ url: whatsappImageSrc, channelName: WHATSAPP }),
1657
+ ...(isImageUrlMode && { isAddImageUrl: true }),
1631
1658
  };
1632
1659
  break;
1633
1660
  case WHATSAPP_MEDIA_TYPES.VIDEO:
@@ -1646,7 +1673,6 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1646
1673
  break;
1647
1674
  }
1648
1675
 
1649
- // Add the correct file handle based on host
1650
1676
  if (isHaptic && hapticFileHandle) {
1651
1677
  mediaParams.hapticFileHandle = hapticFileHandle;
1652
1678
  } else if (!isHaptic && karixFileHandle) {
@@ -1758,7 +1784,21 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1758
1784
  type: WHATSAPP,
1759
1785
  });
1760
1786
  };
1761
- const isMediatypeValid =()=> ((isMediaTypeImage && whatsappImageSrc === "") || (isMediaTypeVideo && whatsappVideoSrcAndPreview?.whatsappVideoSrc === "") || (isMediaTypeDoc && whatsappDocSource === ""));
1787
+ const isMediatypeValid =()=> {
1788
+ if (isMediaTypeImage) {
1789
+ if (mediaTypeSelection === WHATSAPP_IMAGE_SOURCE.URL) {
1790
+ return isEditFlow ? !imageURL?.trim() : !whatsappImageSrc?.trim();
1791
+ }
1792
+ return !whatsappImageSrc?.trim();
1793
+ }
1794
+ if (isMediaTypeVideo) {
1795
+ return !whatsappVideoSrcAndPreview?.whatsappVideoSrc?.trim();
1796
+ }
1797
+ if (isMediaTypeDoc) {
1798
+ return !whatsappDocSource?.trim();
1799
+ }
1800
+ return false;
1801
+ };
1762
1802
 
1763
1803
  const isDisableDone = () => {
1764
1804
  // Snapshot removed
@@ -1835,9 +1875,106 @@ const isAuthenticationTemplate = isEqual(templateCategory, WHATSAPP_CATEGORIES.a
1835
1875
  return false;
1836
1876
  };
1837
1877
 
1878
+ const renderImageURLComponent = () => (
1879
+ <>
1880
+ {templateStatus === WHATSAPP_STATUSES.approved && !isAuthenticationTemplate && (
1881
+ <CapRow className="whatsapp-render-heading">
1882
+ <CapHeader
1883
+ title={
1884
+ <CapHeading type="h4">
1885
+ {formatMessage(messages.mediaImage)}
1886
+ </CapHeading>
1887
+ }
1888
+ suffix={
1889
+ <TagList
1890
+ label={formatMessage(globalMessages.addLabels)}
1891
+ onTagSelect={onImageURLTagSelect}
1892
+ location={location}
1893
+ tags={tags || []}
1894
+ onContextChange={handleOnTagsContextChange}
1895
+ injectedTags={injectedTags || {}}
1896
+ selectedOfferDetails={selectedOfferDetails}
1897
+ eventContextTags={eventContextTags}
1898
+ />
1899
+ }
1900
+ />
1901
+ </CapRow>
1902
+ )}
1903
+ <CapRow className="whatsapp-image-url-container">
1904
+ <CapInput
1905
+ id="whatsapp-image-url-input"
1906
+ placeholder={formatMessage(messages.imageUrlInputPlaceholder)}
1907
+ value={imageURL}
1908
+ disabled={isEditFlow && isFullMode}
1909
+ onChange={e => {
1910
+ setImageURL(e.target.value);
1911
+ setWhatsappImageSrc(e.target.value);
1912
+ }}
1913
+ onFocus={(e) => {
1914
+ setImageURLCursorPosition(e.target.selectionStart || e.target.value.length);
1915
+ }}
1916
+ onSelect={(e) => {
1917
+ setImageURLCursorPosition(e.target.selectionStart || e.target.value.length);
1918
+ }}
1919
+ />
1920
+ </CapRow>
1921
+ </>
1922
+ );
1923
+
1924
+ const handleMediaChange = (e) => {
1925
+ if (templateStatus === WHATSAPP_STATUSES.approved || isEditFlow) {
1926
+ return;
1927
+ }
1928
+ setMediaTypeSelection(e.target.value);
1929
+ if (e.target.value === WHATSAPP_IMAGE_SOURCE.UPLOAD) {
1930
+ setImageURL('');
1931
+ } else if (e.target.value === WHATSAPP_IMAGE_SOURCE.URL) {
1932
+ setWhatsappImageSrc('');
1933
+ if (isHaptic) {
1934
+ setHapticFileHandle('');
1935
+ } else {
1936
+ setKarixFileHandle('');
1937
+ }
1938
+ }
1939
+ };
1940
+
1838
1941
  const renderMediaComponent = () => (
1839
1942
  <>
1840
- {isMediaTypeImage && renderImageComponent()}
1943
+ {isMediaTypeImage && (
1944
+ <CapRow className="whatsapp-dynamic-url-selection-container">
1945
+ <CapHeading type="h4" className="whatsapp-dynamic-url-selection-heading">
1946
+ {formatMessage(messages.mediaImage)}
1947
+ </CapHeading>
1948
+ <CapRadioGroup
1949
+ options={[
1950
+ {
1951
+ value: WHATSAPP_IMAGE_SOURCE.UPLOAD,
1952
+ label: formatMessage(messages.imageSourceUpload),
1953
+ },
1954
+ {
1955
+ value: WHATSAPP_IMAGE_SOURCE.URL,
1956
+ label: (
1957
+ <CapLabel.CapLabelInline type="label2">
1958
+ {formatMessage(messages.imageSourceUrl)}{' '}
1959
+ <CapTooltip
1960
+ placement="top"
1961
+ title={formatMessage(messages.imageSourceUrlTooltip)}
1962
+ >
1963
+ <CapIcon type="info-circle" size="s" style={{ cursor: 'pointer' }} />
1964
+ </CapTooltip>
1965
+ </CapLabel.CapLabelInline>
1966
+ ),
1967
+ },
1968
+ ]}
1969
+ value={mediaTypeSelection}
1970
+ onChange={handleMediaChange}
1971
+ className="whatsapp-media-radio"
1972
+ disabled={templateStatus === WHATSAPP_STATUSES.approved || isEditFlow}
1973
+ />
1974
+ </CapRow>
1975
+ )}
1976
+ {isMediaTypeImage && (mediaTypeSelection === WHATSAPP_IMAGE_SOURCE.UPLOAD || !isEditFlow) && renderImageComponent()}
1977
+ {isMediaTypeImage && mediaTypeSelection === WHATSAPP_IMAGE_SOURCE.URL && isEditFlow && renderImageURLComponent()}
1841
1978
  {isMediaTypeVideo && renderVideoComonent()}
1842
1979
  {isMediaTypeDoc && renderDocumentComponent()}
1843
1980
  </>
@@ -9,6 +9,14 @@
9
9
  margin-top: $CAP_SPACE_16;
10
10
  }
11
11
 
12
+ .whatsapp-dynamic-url-selection-container {
13
+ margin-bottom: $CAP_SPACE_08;
14
+ margin-top: $CAP_SPACE_32;
15
+ .whatsapp-dynamic-url-selection-heading {
16
+ margin-bottom: $CAP_SPACE_08;
17
+ }
18
+ }
19
+
12
20
  .whatsapp-render-heading {
13
21
  margin-top: $CAP_SPACE_16;
14
22
  margin-bottom: $CAP_SPACE_06;
@@ -138,6 +138,22 @@ export default defineMessages({
138
138
  id: `${prefix}.mediaCarousel`,
139
139
  defaultMessage: 'Carousel',
140
140
  },
141
+ imageSourceUpload: {
142
+ id: `${prefix}.imageSourceUpload`,
143
+ defaultMessage: 'Upload image',
144
+ },
145
+ imageSourceUrl: {
146
+ id: `${prefix}.imageSourceUrl`,
147
+ defaultMessage: 'Dynamic image',
148
+ },
149
+ imageSourceUrlTooltip: {
150
+ id: `${prefix}.imageSourceUrlTooltip`,
151
+ defaultMessage: 'Post template approval, the image placeholder is replaceable with image URL',
152
+ },
153
+ imageUrlInputPlaceholder: {
154
+ id: `${prefix}.imageUrlInputPlaceholder`,
155
+ defaultMessage: 'Enter image URL',
156
+ },
141
157
  disabledFeatureTooltip: {
142
158
  id: `${prefix}.disabledFeatureTooltip`,
143
159
  defaultMessage: 'Not yet enabled. Coming soon!',