@antscorp/antsomi-ui 1.3.3-beta.69 → 1.3.3-beta.70

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 (134) hide show
  1. package/es/components/atoms/InputDynamic/InputDynamic.d.ts +5 -25
  2. package/es/components/atoms/InputDynamic/InputDynamic.js +200 -16
  3. package/es/components/atoms/InputDynamic/PopupShortLink.d.ts +1 -1
  4. package/es/components/atoms/InputDynamic/constants.d.ts +71 -0
  5. package/es/components/atoms/InputDynamic/constants.js +71 -0
  6. package/es/components/atoms/InputDynamic/index.d.ts +1 -1
  7. package/es/components/atoms/InputDynamic/styled.d.ts +1 -0
  8. package/es/components/atoms/InputDynamic/styled.js +14 -2
  9. package/es/components/atoms/InputDynamic/types.d.ts +110 -0
  10. package/es/components/atoms/InputDynamic/types.js +1 -0
  11. package/es/components/atoms/InputDynamic/utils.d.ts +8 -0
  12. package/es/components/atoms/InputDynamic/utils.js +123 -2
  13. package/es/components/atoms/Spin/styled.d.ts +1 -1
  14. package/es/components/common/ConfigProvider/GlobalStyle.js +10 -0
  15. package/es/components/molecules/AddDynamicContent/AddDynamicContent.d.ts +35 -0
  16. package/es/components/molecules/AddDynamicContent/AddDynamicContent.js +1245 -0
  17. package/es/components/molecules/AddDynamicContent/components/DisplayFormat/DisplayFormat.d.ts +12 -0
  18. package/es/components/molecules/AddDynamicContent/components/DisplayFormat/DisplayFormat.js +25 -0
  19. package/es/components/molecules/AddDynamicContent/components/DisplayFormat/index.d.ts +3 -0
  20. package/es/components/molecules/AddDynamicContent/components/DisplayFormat/index.js +3 -0
  21. package/es/components/molecules/AddDynamicContent/components/FormatDatetime/FormatDatetime.d.ts +19 -0
  22. package/es/components/molecules/AddDynamicContent/components/FormatDatetime/FormatDatetime.js +101 -0
  23. package/es/components/molecules/AddDynamicContent/components/FormatDatetime/index.d.ts +1 -0
  24. package/es/components/molecules/AddDynamicContent/components/FormatDatetime/index.js +1 -0
  25. package/es/components/molecules/AddDynamicContent/components/FormatNumber/FormatNumber.d.ts +52 -0
  26. package/es/components/molecules/AddDynamicContent/components/FormatNumber/FormatNumber.js +132 -0
  27. package/es/components/molecules/AddDynamicContent/components/FormatNumber/index.d.ts +1 -0
  28. package/es/components/molecules/AddDynamicContent/components/FormatNumber/index.js +1 -0
  29. package/es/components/molecules/AddDynamicContent/components/index.d.ts +3 -0
  30. package/es/components/molecules/AddDynamicContent/components/index.js +3 -0
  31. package/es/components/molecules/AddDynamicContent/constants.d.ts +101 -0
  32. package/es/components/molecules/AddDynamicContent/constants.js +152 -0
  33. package/es/components/molecules/AddDynamicContent/currencies.json +1523 -0
  34. package/es/components/molecules/AddDynamicContent/index.d.ts +2 -0
  35. package/es/components/molecules/AddDynamicContent/index.js +2 -0
  36. package/es/components/molecules/AddDynamicContent/styled.d.ts +9 -0
  37. package/es/components/molecules/AddDynamicContent/styled.js +18 -0
  38. package/es/components/molecules/AddDynamicContent/types.d.ts +13 -0
  39. package/es/components/molecules/AddDynamicContent/types.js +1 -0
  40. package/es/components/molecules/AddDynamicContent/utils.d.ts +42 -0
  41. package/es/components/molecules/AddDynamicContent/utils.js +398 -0
  42. package/es/components/molecules/Modal/Modal.d.ts +2 -2
  43. package/es/components/molecules/Modal/styled.d.ts +1 -1
  44. package/es/components/molecules/Modal/styled.js +2 -0
  45. package/es/components/molecules/ModalV2/styled.d.ts +1 -1
  46. package/es/components/molecules/Select/Select.d.ts +2 -4
  47. package/es/components/molecules/ShareAccess/components/ModalTransferOwnerShip/styled.d.ts +1 -1
  48. package/es/components/molecules/TreeSelect/TreeSelect.d.ts +3 -5
  49. package/es/components/molecules/UploadImage/MediaThumb.d.ts +11 -0
  50. package/es/components/molecules/UploadImage/MediaThumb.js +31 -0
  51. package/es/components/molecules/UploadImage/index.d.ts +6 -2
  52. package/es/components/molecules/UploadImage/index.js +101 -77
  53. package/es/components/molecules/UploadImage/styled.js +0 -4
  54. package/es/components/molecules/UploadImage/utils.d.ts +3 -0
  55. package/es/components/molecules/UploadImage/utils.js +24 -0
  56. package/es/components/organism/Help/styled.d.ts +2 -6
  57. package/es/constants/queries.d.ts +14 -0
  58. package/es/constants/queries.js +21 -0
  59. package/es/hooks/index.d.ts +1 -0
  60. package/es/hooks/index.js +1 -0
  61. package/es/hooks/useDeepCompareMemo.d.ts +2 -0
  62. package/es/hooks/useDeepCompareMemo.js +21 -0
  63. package/es/locales/en/translation.json +151 -0
  64. package/es/locales/i18n.d.ts +151 -0
  65. package/es/locales/translations.d.ts +151 -0
  66. package/es/models/BusinessObject.d.ts +116 -0
  67. package/es/models/BusinessObject.js +113 -0
  68. package/es/models/Currency.d.ts +9 -0
  69. package/es/models/Currency.js +10 -0
  70. package/es/models/CustomFunction.d.ts +19 -0
  71. package/es/models/CustomFunction.js +25 -0
  72. package/es/models/DynamicContentAttribute.d.ts +34 -0
  73. package/es/models/DynamicContentAttribute.js +9 -0
  74. package/es/models/EventTrackingAttribute.d.ts +11 -0
  75. package/es/models/EventTrackingAttribute.js +13 -0
  76. package/es/models/PromotionPool.d.ts +11 -0
  77. package/es/models/PromotionPool.js +12 -0
  78. package/es/models/{SavedImage.d.ts → SavedMedia.d.ts} +5 -5
  79. package/es/models/{SavedImage.js → SavedMedia.js} +3 -3
  80. package/es/queries/BusinessObject/index.d.ts +6 -0
  81. package/es/queries/BusinessObject/index.js +6 -0
  82. package/es/queries/BusinessObject/useGetListAllEvents.d.ts +11 -0
  83. package/es/queries/BusinessObject/useGetListAllEvents.js +14 -0
  84. package/es/queries/BusinessObject/useGetListAttributeBO.d.ts +17 -0
  85. package/es/queries/BusinessObject/useGetListAttributeBO.js +41 -0
  86. package/es/queries/BusinessObject/useGetListBO.d.ts +6 -0
  87. package/es/queries/BusinessObject/useGetListBO.js +19 -0
  88. package/es/queries/BusinessObject/useGetListEventAttr.d.ts +4 -0
  89. package/es/queries/BusinessObject/useGetListEventAttr.js +15 -0
  90. package/es/queries/BusinessObject/useGetListPromotionCodeAttr.d.ts +6 -0
  91. package/es/queries/BusinessObject/useGetListPromotionCodeAttr.js +26 -0
  92. package/es/queries/BusinessObject/useGetListSourceByEvent.d.ts +13 -0
  93. package/es/queries/BusinessObject/useGetListSourceByEvent.js +11 -0
  94. package/es/queries/CustomFunction/index.d.ts +2 -0
  95. package/es/queries/CustomFunction/index.js +2 -0
  96. package/es/queries/CustomFunction/useCustomFunction.d.ts +19 -0
  97. package/es/queries/CustomFunction/useCustomFunction.js +53 -0
  98. package/es/queries/DynamicContentAttribute/index.d.ts +1 -0
  99. package/es/queries/DynamicContentAttribute/index.js +1 -0
  100. package/es/queries/DynamicContentAttribute/useGetDynamicContentAttr.d.ts +10 -0
  101. package/es/queries/DynamicContentAttribute/useGetDynamicContentAttr.js +21 -0
  102. package/es/queries/PromotionPool/index.d.ts +1 -0
  103. package/es/queries/PromotionPool/index.js +1 -0
  104. package/es/queries/PromotionPool/useGetListPromotionPool.d.ts +9 -0
  105. package/es/queries/PromotionPool/useGetListPromotionPool.js +62 -0
  106. package/es/queries/ThirdParty/index.d.ts +1 -0
  107. package/es/queries/ThirdParty/index.js +1 -0
  108. package/es/queries/ThirdParty/useGetEventTrackingAttributes.d.ts +14 -0
  109. package/es/queries/ThirdParty/useGetEventTrackingAttributes.js +15 -0
  110. package/es/queries/configs.d.ts +4 -0
  111. package/es/queries/configs.js +13 -0
  112. package/es/queries/index.d.ts +6 -0
  113. package/es/queries/index.js +6 -0
  114. package/es/services/MediaTemplateDesign/BusinessObject/index.d.ts +8 -0
  115. package/es/services/MediaTemplateDesign/BusinessObject/index.js +100 -0
  116. package/es/services/MediaTemplateDesign/CustomFunction/index.d.ts +15 -0
  117. package/es/services/MediaTemplateDesign/CustomFunction/index.js +135 -0
  118. package/es/services/MediaTemplateDesign/DynamicContentAttribute/index.d.ts +4 -0
  119. package/es/services/MediaTemplateDesign/DynamicContentAttribute/index.js +39 -0
  120. package/es/services/MediaTemplateDesign/ListCurrency/index.d.ts +6 -0
  121. package/es/services/MediaTemplateDesign/ListCurrency/index.js +34 -0
  122. package/es/services/MediaTemplateDesign/PromotionPool/index.d.ts +3 -0
  123. package/es/services/MediaTemplateDesign/PromotionPool/index.js +31 -0
  124. package/es/services/MediaTemplateDesign/UploadFile/index.d.ts +5 -5
  125. package/es/services/MediaTemplateDesign/UploadFile/index.js +36 -19
  126. package/es/services/ThirParty/index.d.ts +8 -0
  127. package/es/services/ThirParty/index.js +26 -0
  128. package/es/services/index.d.ts +14 -5
  129. package/es/services/index.js +45 -1
  130. package/es/test.js +50 -10
  131. package/es/types/index.d.ts +5 -0
  132. package/es/utils/common.d.ts +1 -0
  133. package/es/utils/common.js +1 -0
  134. package/package.json +9 -2
@@ -7,6 +7,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
+ /* eslint-disable jsx-a11y/media-has-caption */
11
+ /* eslint-disable @typescript-eslint/no-use-before-define */
10
12
  /* eslint-disable react-hooks/exhaustive-deps */
11
13
  // Libraries
12
14
  import React, { useEffect, useState, useRef } from 'react';
@@ -17,15 +19,18 @@ import { useDeepCompareEffect } from '@antscorp/antsomi-ui/es/hooks';
17
19
  import PlaceholderImage from '@antscorp/antsomi-ui/es/assets/images/placeholder-image.png';
18
20
  import MediaIcon from './MediaIcon';
19
21
  // Service
20
- import { uploadFile, createSavedImage, deleteSavedImage, getListingSavedImage, } from '@antscorp/antsomi-ui/es/services/MediaTemplateDesign/UploadFile';
22
+ import { uploadFile, createSavedMedia, deleteSavedMedia, getListingSavedMedia, } from '@antscorp/antsomi-ui/es/services/MediaTemplateDesign/UploadFile';
21
23
  // Atoms
22
24
  import { Button, Icon, Text, message, Spin, Input, Space, } from '@antscorp/antsomi-ui/es/components/atoms';
23
25
  // Molecules
24
26
  import { Modal, InputSearch, Select } from '@antscorp/antsomi-ui/es/components/molecules';
27
+ // Components
28
+ import { MediaThumb } from './MediaThumb';
25
29
  // Styled
26
30
  import { Boxed, ErrorMessage, Image, Overlay, Paragraph, TextStyled, UploadImageWrapper, WrapperBtn, WrapperIcon, WrapperInputMode, WrapperListImages, } from './styled';
27
31
  // Utils
28
32
  import { handleError, safeParse } from '@antscorp/antsomi-ui/es/utils';
33
+ import { getMediaTypeByMode, getReplacementExtension } from './utils';
29
34
  // Constants
30
35
  import { THEME } from '@antscorp/antsomi-ui/es/constants';
31
36
  const flexStyleCenter = {
@@ -47,56 +52,63 @@ const SORT_OPTIONS = {
47
52
  const PATH = '@antscorp/antsomi-ui/es/components/molecules/UploadImage/index.tsx';
48
53
  export const UploadImage = props => {
49
54
  var _a, _b, _c, _d, _e;
50
- const { labelHeadingModal, labelButtonSelect, searchPlaceholder, onRemoveImage, onChangeImage, isOpen, isInputMode, width, placeholder, extensions, maxSize, title, showImageURL, required, focused, domainMedia, slug, paramConfigs, errors, } = props;
55
+ const { labelHeadingModal, labelButtonSelect, labelModalDelete, searchPlaceholder, onRemoveImage, onChangeImage: onChangeMedia, isOpen, isInputMode, width, placeholder, extensions, maxSize, title, showImageURL: showMediaURL, selectedImage: selectedMediaProp, required, focused, domainMedia, slug, paramConfigs, errors, iconName, mode, } = props;
51
56
  const { Dragger } = Upload;
52
- const [storeSavedImages, setStoreSavedImages] = useState([]);
53
- const [selectedImage, setSelectedImage] = useState(props.selectedImage || { url: '' });
57
+ const [storeSavedMedia, setStoreSavedMedia] = useState([]);
58
+ const [selectedMedia, setSelectedMedia] = useState(selectedMediaProp || { url: '' });
54
59
  const [isModalVisible, setIsModalVisible] = useState(isOpen);
55
- const [listImages, setListImages] = useState(storeSavedImages || []);
60
+ const [listMedia, setListMedia] = useState(storeSavedMedia || []);
56
61
  const [sortOption, setSortOption] = useState(SORT_OPTIONS.BY_UPLOAD_DATE.value);
57
62
  const [loading, setLoading] = useState(false);
58
63
  const [isOpenConfirmDelete, setOpenConfirmDelete] = useState(false);
59
64
  const [triggerRefresh, setTriggerRefresh] = useState(1);
65
+ const [posters, setPosters] = useState([]);
60
66
  const uploadFilesRef = useRef([]);
61
67
  const uploadFilesTimeoutRef = useRef();
62
- const deleteImageRef = useRef();
68
+ const deleteMediaRef = useRef();
63
69
  const isError = safeParse(errors, []).length > 0;
64
70
  useDeepCompareEffect(() => {
65
- setListImages(storeSavedImages || []);
71
+ setListMedia(storeSavedMedia || []);
66
72
  setLoading(false);
67
- }, [storeSavedImages]);
68
- // When selectedImage onChange
73
+ }, [storeSavedMedia]);
74
+ useDeepCompareEffect(() => {
75
+ if (mode === 'video') {
76
+ const genPosters = Array.from({ length: (listMedia === null || listMedia === void 0 ? void 0 : listMedia.length) || 0 }, () => PlaceholderImage);
77
+ setPosters(genPosters);
78
+ }
79
+ }, [listMedia]);
80
+ // When selectedMediaProp onChange
69
81
  useEffect(() => {
70
- // eslint-disable-next-line react/destructuring-assignment
71
- setSelectedImage(props.selectedImage || { url: '' });
72
- // eslint-disable-next-line react/destructuring-assignment
73
- }, [props.selectedImage]);
82
+ setSelectedMedia(selectedMediaProp || { url: '' });
83
+ }, [selectedMediaProp]);
74
84
  useEffect(() => {
75
85
  if (sortOption === SORT_OPTIONS.BY_SIZE.value) {
76
- setListImages(listImages ? [...listImages].sort((image1, image2) => image1.size - image2.size) : []);
86
+ setListMedia(listMedia ? [...listMedia].sort((media1, media2) => media1.size - media2.size) : []);
77
87
  }
78
88
  else {
79
- setListImages(listImages
80
- ? [...listImages].sort((image1, image2) => image1.createdAt && image2.createdAt
81
- ? image1.createdAt.isAfter(image2.createdAt)
89
+ setListMedia(listMedia
90
+ ? [...listMedia].sort((media1, media2) => media1.createdAt && media2.createdAt
91
+ ? media1.createdAt.isAfter(media2.createdAt)
82
92
  ? -1
83
93
  : 1
84
94
  : 0)
85
95
  : []);
86
96
  }
87
97
  }, [sortOption]);
88
- const handleGetStoreSavedImages = (domain, slug, paramConfigs) => __awaiter(void 0, void 0, void 0, function* () {
98
+ const handleGetStoreSavedMedia = (domain, slug, paramConfigs) => __awaiter(void 0, void 0, void 0, function* () {
89
99
  try {
90
100
  setLoading(true);
91
- const result = yield getListingSavedImage(domain, slug, paramConfigs);
101
+ const type = getMediaTypeByMode(mode);
102
+ const params = Object.assign(Object.assign({}, paramConfigs), { type });
103
+ const result = yield getListingSavedMedia(domain, slug, params);
92
104
  if (result) {
93
- setStoreSavedImages(result || []);
105
+ setStoreSavedMedia(result || []);
94
106
  }
95
107
  }
96
108
  catch (error) {
97
109
  handleError(error, {
98
110
  path: PATH,
99
- name: 'handleGetStoreSavedImages',
111
+ name: 'handleGetStoreSavedMedia',
100
112
  args: {
101
113
  error,
102
114
  },
@@ -109,7 +121,7 @@ export const UploadImage = props => {
109
121
  }
110
122
  });
111
123
  useEffect(() => {
112
- handleGetStoreSavedImages(domainMedia, slug, paramConfigs);
124
+ handleGetStoreSavedMedia(domainMedia, slug, paramConfigs);
113
125
  }, [triggerRefresh]);
114
126
  const showModal = (e) => {
115
127
  e.stopPropagation();
@@ -118,24 +130,24 @@ export const UploadImage = props => {
118
130
  const handleCancel = () => {
119
131
  setIsModalVisible(false);
120
132
  };
121
- const handleSelectImage = image => {
122
- if (typeof onChangeImage === 'function') {
123
- onChangeImage(image);
133
+ const handleSelectMedia = (media) => {
134
+ if (typeof onChangeMedia === 'function') {
135
+ onChangeMedia(media);
124
136
  }
125
- setSelectedImage(image);
137
+ setSelectedMedia(media);
126
138
  handleCancel();
127
139
  };
128
- const onChangeSort = option => {
140
+ const onChangeSort = (option) => {
129
141
  setSortOption(option);
130
142
  };
131
- const renderListImages = listImagesRender => listImagesRender.map((image, idx) => {
143
+ const renderListMedia = (listMediaRender) => listMediaRender.map((media, idx) => {
132
144
  var _a;
133
145
  return (React.createElement(WrapperListImages, { className: "ants-group", key: idx },
134
146
  React.createElement(Boxed, null,
135
- React.createElement(Image, { src: image.url, alt: "img" }),
147
+ React.createElement(MediaThumb, { index: idx, posters: posters, mode: mode, media: media, onSetPosters: setPosters }),
136
148
  React.createElement(WrapperBtn, { className: "group-hover" },
137
- React.createElement(Button, { onClick: () => handleSelectImage(image), style: { backgroundColor: 'rgb(255,255,255)' } }, "USE"),
138
- React.createElement(Button, { onClick: () => handleRemoveUploadedImage(image), style: { backgroundColor: 'rgb(255,255,255)' } },
149
+ React.createElement(Button, { onClick: () => handleSelectMedia(media), style: { backgroundColor: 'rgb(255,255,255)' } }, "USE"),
150
+ React.createElement(Button, { onClick: () => handleRemoveUploadedMedia(media), style: { backgroundColor: 'rgb(255,255,255)' } },
139
151
  React.createElement(Icon, { type: "icon-ants-remove-trash", size: 15, style: { color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorPrimary } }))),
140
152
  React.createElement(Overlay, { className: "group-hover" })),
141
153
  React.createElement(Paragraph, { style: {
@@ -144,63 +156,65 @@ export const UploadImage = props => {
144
156
  display: '-webkit-box',
145
157
  WebkitLineClamp: 2,
146
158
  WebkitBoxOrient: 'vertical',
147
- }, title: image.name }, image.name),
159
+ }, title: media.name }, media.name),
148
160
  React.createElement(Paragraph, null,
149
161
  "Uploaded: ",
150
- image.createdAt.format('DD/MM/YYYY'),
162
+ media.createdAt.format('DD/MM/YYYY'),
151
163
  " at ",
152
- image.createdAt.format('hh:mm:ss A')),
164
+ media.createdAt.format('hh:mm:ss A')),
153
165
  React.createElement(Paragraph, null,
154
166
  "Size: ",
155
- image.sizeString)));
167
+ media.sizeString)));
156
168
  });
157
- const onChangeSearchImage = e => {
169
+ const onChangeSearchImage = (e) => {
158
170
  const { value } = e.target;
159
171
  if (value && value.trim()) {
160
- setListImages(storeSavedImages
161
- ? storeSavedImages
172
+ setListMedia(storeSavedMedia
173
+ ? storeSavedMedia
162
174
  .filter(item => item.name.toLocaleLowerCase().includes(value.trim().toLocaleLowerCase()))
163
175
  .slice(0, 15)
164
176
  : []);
165
177
  }
166
178
  else {
167
- setListImages(storeSavedImages);
179
+ setListMedia(storeSavedMedia);
168
180
  }
169
181
  };
170
- const handleRemoveImage = () => {
182
+ const handleRemoveMedia = () => {
171
183
  if (onRemoveImage) {
172
184
  onRemoveImage();
173
185
  }
174
- setSelectedImage({ url: '' });
186
+ setSelectedMedia({ url: '' });
175
187
  };
176
- const handleRemoveUploadedImage = (image, isConfirm = true) => __awaiter(void 0, void 0, void 0, function* () {
188
+ const handleRemoveUploadedMedia = (media, isConfirm = true) => __awaiter(void 0, void 0, void 0, function* () {
177
189
  if (isConfirm) {
178
- deleteImageRef.current = image;
190
+ deleteMediaRef.current = media;
179
191
  setOpenConfirmDelete(true);
180
192
  }
181
- else if (image) {
182
- const res = yield deleteSavedImage(domainMedia, slug, paramConfigs, +image.id);
193
+ else if (media) {
194
+ const res = yield deleteSavedMedia(domainMedia, slug, paramConfigs, +media.id);
183
195
  if (res && res.data && res.data.code === 200 && res.data.data) {
184
- const { success_image = [] } = res.data.data;
185
- if (Array.isArray(success_image) && success_image.length) {
196
+ const { success_media = [] } = res.data.data;
197
+ if (Array.isArray(success_media) && success_media.length) {
186
198
  setTriggerRefresh(triggerRefresh + 1);
187
199
  }
188
200
  }
189
201
  setOpenConfirmDelete(false);
190
- deleteImageRef.current = undefined;
202
+ deleteMediaRef.current = undefined;
191
203
  }
192
204
  });
193
- const renderSelectedImage = () => selectedImage && selectedImage.url ? (React.createElement(Image, { src: selectedImage.url, alt: "", style: { position: 'absolute' }, onError: (e) => {
194
- e.target.src = PlaceholderImage;
195
- } })) : null;
205
+ const renderSelectedMedia = () => {
206
+ if (!selectedMedia || !selectedMedia.url)
207
+ return null;
208
+ if (mode === 'video') {
209
+ return (React.createElement("video", { controls: false, autoPlay: false, muted: true, style: { width: '100%', height: '100%', position: 'absolute' }, src: selectedMedia.url }));
210
+ }
211
+ return (React.createElement(Image, { src: selectedMedia.url, alt: "", style: { position: 'absolute' }, onError: (e) => {
212
+ e.target.src = PlaceholderImage;
213
+ } }));
214
+ };
196
215
  const customRequestUpload = (options) => __awaiter(void 0, void 0, void 0, function* () {
197
216
  try {
198
- const {
199
- // onSuccess,
200
- // onError,
201
- file,
202
- // onProgress
203
- } = options;
217
+ const { file } = options;
204
218
  uploadFilesRef.current.push(file);
205
219
  if (uploadFilesTimeoutRef.current) {
206
220
  clearTimeout(uploadFilesTimeoutRef.current);
@@ -211,12 +225,15 @@ export const UploadImage = props => {
211
225
  return;
212
226
  }
213
227
  if (uploadFilesRef.current.length > 10) {
214
- message.error('Maximum number of file to upload is 10!');
228
+ const defaultMaxSize = mode === 'video' ? 200 : 10;
229
+ const error = `Maximum number of file to upload is ${maxSize || defaultMaxSize}!`;
230
+ message.error(error);
215
231
  uploadFilesRef.current = [];
216
232
  return false;
217
233
  }
218
234
  for (const file of uploadFilesRef.current) {
219
- if (!(extensions === null || extensions === void 0 ? void 0 : extensions.map(extension => extension.replace('.', 'image/')).includes(file.type))) {
235
+ const replacement = getReplacementExtension(mode);
236
+ if (!(extensions === null || extensions === void 0 ? void 0 : extensions.map(extension => extension.replace('.', replacement)).includes(file.type))) {
220
237
  message.error('Invalid file extension');
221
238
  uploadFilesRef.current = [];
222
239
  return false;
@@ -228,16 +245,18 @@ export const UploadImage = props => {
228
245
  }
229
246
  }
230
247
  setLoading(true);
231
- const result = yield uploadFile(domainMedia, slug, paramConfigs, uploadFilesRef.current).finally(() => {
248
+ const result = yield uploadFile(domainMedia, slug, Object.assign(Object.assign({}, paramConfigs), { mode }), uploadFilesRef.current).finally(() => {
232
249
  uploadFilesRef.current = [];
233
250
  });
234
251
  if (result === null || result === void 0 ? void 0 : result.length) {
235
252
  const arrPromise = [];
236
- result.forEach(data => arrPromise.push(createSavedImage(domainMedia, slug, paramConfigs, {
237
- image_name: data.fileName,
253
+ const type = getMediaTypeByMode(mode);
254
+ result.forEach(data => arrPromise.push(createSavedMedia(domainMedia, slug, paramConfigs, {
255
+ type,
256
+ name: data.fileName,
238
257
  properties: {
239
258
  url: data.url,
240
- image: data.file,
259
+ file: data.file,
241
260
  extension: data.extension,
242
261
  dimensions_file: data.dimensionsFile,
243
262
  size: data.size,
@@ -265,23 +284,25 @@ export const UploadImage = props => {
265
284
  });
266
285
  return (React.createElement(React.Fragment, null,
267
286
  isInputMode ? (React.createElement(WrapperInputMode, { width: width },
268
- React.createElement(Input, { required: required, status: errors && (errors === null || errors === void 0 ? void 0 : errors.length) > 0 ? 'error' : '', placeholder: placeholder, value: selectedImage.url ? selectedImage.url : '', focused: focused, style: { paddingRight: 40 }, onAfterChange: value => handleSelectImage({
287
+ React.createElement(Input, { required: required, status: errors && (errors === null || errors === void 0 ? void 0 : errors.length) > 0 ? 'error' : '', placeholder: placeholder, value: selectedMedia.url ? selectedMedia.url : '', focused: focused, style: { paddingRight: 40 }, onAfterChange: value => handleSelectMedia({
269
288
  url: value,
270
289
  }) }),
271
290
  React.createElement(WrapperIcon, { onClick: showModal },
272
291
  React.createElement(MediaIcon, null)),
273
292
  isError && React.createElement(ErrorMessage, null, errors && (errors === null || errors === void 0 ? void 0 : errors.length) > 0 ? errors[0] : ''))) : (React.createElement(UploadImageWrapper, null,
274
293
  title ? React.createElement(Text, { style: { marginTop: 10 } }, title) : null,
275
- React.createElement("div", { className: `image-upload-content ${selectedImage && selectedImage.url ? 'uploaded' : ''}` },
276
- renderSelectedImage(),
277
- !selectedImage || !selectedImage.url ? (React.createElement(Icon, { type: "icon-ants-image-3", size: 36, style: {
294
+ React.createElement("div", { className: `image-upload-content ${selectedMedia && selectedMedia.url ? 'uploaded' : ''}` },
295
+ renderSelectedMedia(),
296
+ !selectedMedia || !selectedMedia.url ? (React.createElement(Icon, { type: `icon-ants-${iconName}`, size: 36, style: {
278
297
  zIndex: 1,
279
298
  marginLeft: 25,
280
299
  color: (_a = THEME.token) === null || _a === void 0 ? void 0 : _a.colorIcon,
281
300
  } })) : null,
282
301
  React.createElement("div", { style: flexStyleCenter },
283
- React.createElement(Button, { onClick: showModal, style: { backgroundColor: '#ffffff' } }, "Browse Image"),
284
- selectedImage && selectedImage.url ? (React.createElement(Button, { onClick: handleRemoveImage, style: { backgroundColor: '#ffffff' } },
302
+ React.createElement(Button, { onClick: showModal, style: { backgroundColor: '#ffffff' } },
303
+ "Browse ",
304
+ mode === 'video' ? 'Video' : 'Image'),
305
+ selectedMedia && selectedMedia.url ? (React.createElement(Button, { onClick: handleRemoveMedia, style: { backgroundColor: '#ffffff' } },
285
306
  React.createElement(Icon, { type: "icon-ants-remove-trash", size: 15, style: { color: (_b = THEME.token) === null || _b === void 0 ? void 0 : _b.colorPrimary } }))) : null)),
286
307
  React.createElement("div", { className: "upload-file-info", style: { marginTop: 12 } },
287
308
  React.createElement(Text, null,
@@ -291,17 +312,17 @@ export const UploadImage = props => {
291
312
  "File size: under ",
292
313
  maxSize,
293
314
  "MB")),
294
- showImageURL && (React.createElement(Space, { size: 5, direction: "vertical", style: { marginTop: 12 } },
295
- React.createElement(Input, { label: "Image URL", required: required, placeholder: placeholder, value: selectedImage.url ? selectedImage.url : '', focused: focused, onAfterChange: value => handleSelectImage({
315
+ showMediaURL && (React.createElement(Space, { size: 5, direction: "vertical", style: { marginTop: 12 } },
316
+ React.createElement(Input, { label: mode === 'video' ? 'Video URL' : 'Image URL', required: required, placeholder: placeholder, value: selectedMedia.url ? selectedMedia.url : '', focused: focused, onAfterChange: value => handleSelectMedia({
296
317
  url: value,
297
318
  }) }))))),
298
- React.createElement(Modal, { title: "Delete Image", visible: isOpenConfirmDelete, onOk: () => handleRemoveUploadedImage(deleteImageRef.current, false), onCancel: () => setOpenConfirmDelete(prev => !prev), okText: "OK", cancelText: "Cancel" },
319
+ React.createElement(Modal, { title: labelModalDelete, visible: isOpenConfirmDelete, onOk: () => handleRemoveUploadedMedia(deleteMediaRef.current, false), onCancel: () => setOpenConfirmDelete(prev => !prev), okText: "OK", cancelText: "Cancel" },
299
320
  React.createElement("p", null,
300
- "Are you sure you want to delete the image ", (_c = deleteImageRef.current) === null || _c === void 0 ? void 0 :
321
+ "Are you sure you want to delete ", (_c = deleteMediaRef.current) === null || _c === void 0 ? void 0 :
301
322
  _c.name,
302
323
  "?")),
303
324
  React.createElement(Modal, { wrapClassName: "icons-selection-modal", title: React.createElement("div", { style: { display: 'flex', gap: '8px', alignItems: 'center' } },
304
- React.createElement(Icon, { type: "icon-ants-image-3", size: 20 }),
325
+ React.createElement(Icon, { type: `icon-ants-${iconName}`, size: 20 }),
305
326
  labelHeadingModal), centered: true, headerStyle: {
306
327
  padding: '20px 20px 0',
307
328
  border: 'none',
@@ -326,12 +347,12 @@ export const UploadImage = props => {
326
347
  // onChange={onChangeFileUpload}
327
348
  showUploadList: false, multiple: true, customRequest: customRequestUpload }),
328
349
  React.createElement("div", { style: Object.assign(Object.assign({}, flexStyleCenter), { height: 80 }) },
329
- React.createElement(Icon, { type: "icon-ants-image-3", size: 36, style: { color: (_d = THEME.token) === null || _d === void 0 ? void 0 : _d.colorIcon } }),
350
+ React.createElement(Icon, { type: `icon-ants-${iconName}`, size: 36, style: { color: (_d = THEME.token) === null || _d === void 0 ? void 0 : _d.colorIcon } }),
330
351
  React.createElement("div", { style: Object.assign(Object.assign({}, flexStyleCenter), { justifyContent: 'flex-start' }) },
331
352
  React.createElement(TextStyled, { className: "ant-upload-text" }, "Drag & Drop file here"),
332
353
  React.createElement("span", null, "or"),
333
354
  React.createElement(Button, { style: { backgroundColor: '#ffffff' } }, labelButtonSelect),
334
- React.createElement(Button, { onClick: handleRemoveImage, style: {
355
+ React.createElement(Button, { onClick: handleRemoveMedia, style: {
335
356
  display: 'none !important',
336
357
  backgroundColor: '#ffffff',
337
358
  } },
@@ -342,16 +363,19 @@ export const UploadImage = props => {
342
363
  gap: '35px',
343
364
  paddingTop: 20,
344
365
  width: '100%',
345
- } }, renderListImages(listImages)))));
366
+ } }, renderListMedia(listMedia)))));
346
367
  };
347
368
  UploadImage.defaultProps = {
348
369
  isOpen: false,
349
370
  labelHeadingModal: 'Image Selection',
350
371
  labelButtonSelect: 'Select Image from computer',
372
+ labelModalDelete: 'Delete Image',
351
373
  searchPlaceholder: 'Search image...',
352
374
  domainMedia: 'https://sandbox-media-template.antsomi.com/cdp',
353
375
  slug: 'api/v1',
354
376
  isInputMode: true,
377
+ iconName: 'image-3',
378
+ mode: 'image',
355
379
  width: '100%',
356
380
  errors: [],
357
381
  placeholder: 'Enter image URL',
@@ -29,10 +29,6 @@ export const Boxed = styled.div `
29
29
  border-style: solid;
30
30
  --tw-border-opacity: 1;
31
31
  border-color: rgb(224 224 224 / var(--tw-border-opacity));
32
-
33
- &:hover {
34
- border-width: 2px;
35
- }
36
32
  `;
37
33
  export const Image = styled.img `
38
34
  object-fit: contain;
@@ -0,0 +1,3 @@
1
+ import type { MediaMode } from '.';
2
+ export declare const getMediaTypeByMode: (mode: MediaMode | undefined) => number;
3
+ export declare const getReplacementExtension: (mode: MediaMode | undefined) => string;
@@ -0,0 +1,24 @@
1
+ /*
2
+ * NOTE:
3
+ * 1 -> Image
4
+ * 2 -> Video
5
+ *
6
+ */
7
+ export const getMediaTypeByMode = (mode) => {
8
+ if (!mode || mode === 'image')
9
+ return 1;
10
+ return 2;
11
+ };
12
+ export const getReplacementExtension = (mode) => {
13
+ switch (mode) {
14
+ case 'image': {
15
+ return 'image/';
16
+ }
17
+ case 'video': {
18
+ return 'video/';
19
+ }
20
+ default: {
21
+ return 'image/';
22
+ }
23
+ }
24
+ };
@@ -58,15 +58,11 @@ export declare const TitleSearch: import("styled-components").StyledComponent<"s
58
58
  export declare const WrapperSearch: import("styled-components").StyledComponent<import("react").ForwardRefExoticComponent<import("antd/es/input").SearchProps & import("react").RefAttributes<import("antd").InputRef>>, any, {}, never>;
59
59
  export declare const TreeContent: import("styled-components").StyledComponent<(<T extends import("rc-tree").BasicDataNode | import("antd").TreeDataNode = import("antd").TreeDataNode>(props: import("antd").TreeProps<T> & {
60
60
  children?: import("react").ReactNode;
61
- } & {
62
- ref?: import("react").Ref<import("rc-tree/lib/Tree").default<import("antd").TreeDataNode>> | undefined;
63
- }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
61
+ } & import("react").RefAttributes<import("rc-tree/lib/Tree").default<import("antd").TreeDataNode>>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
64
62
  TreeNode: import("react").FC<import("rc-tree").TreeNodeProps<import("antd").TreeDataNode>>;
65
63
  DirectoryTree: (<T_1 extends import("rc-tree").BasicDataNode | import("antd").TreeDataNode = import("antd").TreeDataNode>(props: import("antd/es/tree").DirectoryTreeProps<T_1> & {
66
64
  children?: import("react").ReactNode;
67
- } & {
68
- ref?: import("react").Ref<import("rc-tree/lib/Tree").default<import("antd").TreeDataNode>> | undefined;
69
- }) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
65
+ } & import("react").RefAttributes<import("rc-tree/lib/Tree").default<import("antd").TreeDataNode>>) => import("react").ReactElement<any, string | import("react").JSXElementConstructor<any>>) & {
70
66
  displayName?: string | undefined;
71
67
  };
72
68
  }, any, {}, never>;
@@ -0,0 +1,14 @@
1
+ export declare const QUERY_KEYS: {
2
+ GET_LIST_EVENT_ATTR: string;
3
+ GET_LIST_EVENT_BY_SOURCE: string;
4
+ GET_LIST_SOURCE_BY_EVENT: string;
5
+ GET_LIST_ALL_EVENT: string;
6
+ GET_LIST_BO: string;
7
+ GET_EVENT_ATTRIBUTE_BO: string;
8
+ GET_LIST_PROMOTION_CODE_ATTR: string;
9
+ GET_EVENT_TRACKING_ATTRIBUTES: string;
10
+ GET_LIST_DYNAMIC_CONTENT_ATTR: string;
11
+ GET_LIST_PROMOTION_POOL: string;
12
+ GET_LIST_CUSTOM: string;
13
+ GET_SAVE_CUSTOM_FUNCTION: string;
14
+ };
@@ -0,0 +1,21 @@
1
+ export const QUERY_KEYS = {
2
+ // Event attr
3
+ GET_LIST_EVENT_ATTR: 'GET_LIST_EVENT_ATTR',
4
+ GET_LIST_EVENT_BY_SOURCE: 'GET_LIST_EVENT_BY_SOURCE',
5
+ GET_LIST_SOURCE_BY_EVENT: 'GET_SOURCE_BY_EVENT',
6
+ GET_LIST_ALL_EVENT: 'GET_LIST_ALL_EVENT',
7
+ // BUSINESS OBJECT
8
+ GET_LIST_BO: 'GET_LIST_BO',
9
+ GET_EVENT_ATTRIBUTE_BO: 'GET_EVENT_ATTRIBUTE_BO',
10
+ // Promotion Code Attr
11
+ GET_LIST_PROMOTION_CODE_ATTR: 'GET_LIST_PROMOTION_CODE_ATTR',
12
+ // Event tracking attributes
13
+ GET_EVENT_TRACKING_ATTRIBUTES: 'GET_EVENT_TRACKING_ATTRIBUTES',
14
+ // Dynamic content Attr
15
+ GET_LIST_DYNAMIC_CONTENT_ATTR: 'GET_LIST_DYNAMIC_CONTENT_ATTR',
16
+ // Event Pool
17
+ GET_LIST_PROMOTION_POOL: 'GET_LIST_PROMOTION_POOL',
18
+ // Custom Function
19
+ GET_LIST_CUSTOM: 'GET_LIST_CUSTOM',
20
+ GET_SAVE_CUSTOM_FUNCTION: 'GET_SAVE_CUSTOM_FUNCTION',
21
+ };
@@ -1,2 +1,3 @@
1
1
  /// <reference types="react" />
2
2
  export declare function useDeepCompareEffect(callback: React.EffectCallback, dependencies: React.DependencyList | undefined): void;
3
+ export { useDeepCompareMemo } from './useDeepCompareMemo';
package/es/hooks/index.js CHANGED
@@ -19,3 +19,4 @@ export function useDeepCompareEffect(callback, dependencies) {
19
19
  // eslint-disable-next-line react-hooks/exhaustive-deps
20
20
  useEffect(callback, dependencies === null || dependencies === void 0 ? void 0 : dependencies.map(useDeepCompareMemoize));
21
21
  }
22
+ export { useDeepCompareMemo } from './useDeepCompareMemo';
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function useDeepCompareMemo<T>(callback: () => T, dependencies: React.DependencyList | undefined): T;
@@ -0,0 +1,21 @@
1
+ import { useMemo, useRef } from 'react';
2
+ import isEqual from 'react-fast-compare';
3
+ function deepCompareEquals(a, b) {
4
+ // TODO: implement deep comparison here
5
+ // something like lodash
6
+ // return _.isEqual(a, b);
7
+ return isEqual(a, b);
8
+ }
9
+ function useDeepCompareMemoize(value) {
10
+ const ref = useRef();
11
+ // it can be done by using useMemo as well
12
+ // but useRef is rather cleaner and easier
13
+ if (!deepCompareEquals(value, ref.current)) {
14
+ ref.current = value;
15
+ }
16
+ return ref.current;
17
+ }
18
+ export function useDeepCompareMemo(callback, dependencies) {
19
+ // eslint-disable-next-line react-hooks/exhaustive-deps
20
+ return useMemo(callback, dependencies === null || dependencies === void 0 ? void 0 : dependencies.map(useDeepCompareMemoize));
21
+ }