@knovator/pagecreator-admin 1.6.8 → 1.6.9
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/index.cjs +23 -46
- package/index.js +23 -46
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -7200,6 +7200,7 @@ const WidgetForm = ({
|
|
|
7200
7200
|
const [blogLimit, setBlogLimit] = React.useState(10);
|
|
7201
7201
|
const [blogCategories, setBlogCategories] = React.useState([]);
|
|
7202
7202
|
const [blogCategoriesLoading, setBlogCategoriesLoading] = React.useState(false);
|
|
7203
|
+
const pagesLoadedRef = React.useRef(false);
|
|
7203
7204
|
React.useEffect(() => {
|
|
7204
7205
|
if (data && formState === 'UPDATE') {
|
|
7205
7206
|
const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
|
|
@@ -7278,56 +7279,16 @@ const WidgetForm = ({
|
|
|
7278
7279
|
}
|
|
7279
7280
|
}
|
|
7280
7281
|
}, [formState, data, currentItemsType, blogCategories, blogCategory, blogLimit]);
|
|
7281
|
-
//
|
|
7282
|
+
// Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
|
|
7282
7283
|
React.useEffect(() => {
|
|
7283
7284
|
if (currentItemsType === 'blog') {
|
|
7284
|
-
if (blogCategory
|
|
7285
|
-
//
|
|
7286
|
-
const fetchBlogsByCategory = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
7287
|
-
var _a;
|
|
7288
|
-
try {
|
|
7289
|
-
setCollectionItemsUpdated(false);
|
|
7290
|
-
const response = yield commonApi({
|
|
7291
|
-
baseUrl,
|
|
7292
|
-
token,
|
|
7293
|
-
method: 'POST',
|
|
7294
|
-
url: `${widgetRoutesPrefix}/collection-data`,
|
|
7295
|
-
data: {
|
|
7296
|
-
search: '',
|
|
7297
|
-
collectionName: 'blog',
|
|
7298
|
-
collectionItems: []
|
|
7299
|
-
},
|
|
7300
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7301
|
-
onError: error => console.error('Error fetching blogs:', error)
|
|
7302
|
-
});
|
|
7303
|
-
if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS' && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.docs)) {
|
|
7304
|
-
// Filter blogs by selected category
|
|
7305
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7306
|
-
const filteredBlogs = response.data.docs
|
|
7307
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7308
|
-
.filter(blog => Array.isArray(blog.category) &&
|
|
7309
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7310
|
-
blog.category.some(cat => cat.id === blogCategory.value)).slice(0, blogLimit)
|
|
7311
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7312
|
-
.map(blog => Object.assign(Object.assign({}, blog), {
|
|
7313
|
-
value: blog._id,
|
|
7314
|
-
label: blog.name || blog.title
|
|
7315
|
-
}));
|
|
7316
|
-
setSelectedCollectionItems(filteredBlogs);
|
|
7317
|
-
setCollectionItemsUpdated(true);
|
|
7318
|
-
}
|
|
7319
|
-
} catch (error) {
|
|
7320
|
-
console.error('Error fetching blogs:', error);
|
|
7321
|
-
}
|
|
7322
|
-
});
|
|
7323
|
-
fetchBlogsByCategory();
|
|
7324
|
-
} else if (!blogCategory) {
|
|
7325
|
-
// Clear selected blogs when category is cleared
|
|
7285
|
+
if (blogCategory || blogLimit > 0) {
|
|
7286
|
+
// Clear selected collection items since server will fetch latest blogs based on category/limit
|
|
7326
7287
|
setSelectedCollectionItems([]);
|
|
7327
7288
|
setCollectionItemsUpdated(true);
|
|
7328
7289
|
}
|
|
7329
7290
|
}
|
|
7330
|
-
}, [blogCategory, blogLimit, currentItemsType
|
|
7291
|
+
}, [blogCategory, blogLimit, currentItemsType]);
|
|
7331
7292
|
// Reset blog category and limit when itemsType changes away from 'blogs'
|
|
7332
7293
|
React.useEffect(() => {
|
|
7333
7294
|
if (currentItemsType !== 'blog') {
|
|
@@ -7344,6 +7305,18 @@ const WidgetForm = ({
|
|
|
7344
7305
|
setBlogLimit(limit);
|
|
7345
7306
|
}
|
|
7346
7307
|
}, [watchedBlogLimit, currentItemsType]);
|
|
7308
|
+
// Load pages data when Links widget type is selected
|
|
7309
|
+
React.useEffect(() => {
|
|
7310
|
+
if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue && (selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value) === constants.pagesItemsTypeValue && !pagesLoadedRef.current) {
|
|
7311
|
+
// Trigger initial load of pages
|
|
7312
|
+
pagesLoadedRef.current = true;
|
|
7313
|
+
getCollectionData(constants.pagesItemsTypeValue, '');
|
|
7314
|
+
}
|
|
7315
|
+
// Reset ref when widget type changes away from Links
|
|
7316
|
+
if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) !== constants.linksWidgetTypeValue) {
|
|
7317
|
+
pagesLoadedRef.current = false;
|
|
7318
|
+
}
|
|
7319
|
+
}, [selectedWidgetType, selectedCollectionType, getCollectionData]);
|
|
7347
7320
|
const onChangeSearch = (str, callback, collectionName) => {
|
|
7348
7321
|
let collectionItems = [];
|
|
7349
7322
|
let valueToSet = '';
|
|
@@ -7533,8 +7506,12 @@ const WidgetForm = ({
|
|
|
7533
7506
|
}
|
|
7534
7507
|
return item;
|
|
7535
7508
|
});
|
|
7536
|
-
const submitPayload = Object.assign(Object.assign({}, formData), {
|
|
7509
|
+
const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
|
|
7537
7510
|
items
|
|
7511
|
+
}), blogCategory && {
|
|
7512
|
+
blogCategory: blogCategory.value
|
|
7513
|
+
}), blogLimit && {
|
|
7514
|
+
blogLimit
|
|
7538
7515
|
});
|
|
7539
7516
|
onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(undefined, submitPayload);
|
|
7540
7517
|
onWidgetFormSubmit(submitPayload);
|
|
@@ -7780,7 +7757,7 @@ const WidgetForm = ({
|
|
|
7780
7757
|
loadOptions: onChangeSearch,
|
|
7781
7758
|
isLoading: collectionDataLoading,
|
|
7782
7759
|
disabled: currentItemsType === 'blog' && !!blogCategory,
|
|
7783
|
-
show: !itemsEnabled && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
|
|
7760
|
+
show: !itemsEnabled && currentItemsType !== 'blog' && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
|
|
7784
7761
|
formatOptionLabel: formatOptionLabel,
|
|
7785
7762
|
listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
|
|
7786
7763
|
customStyles: reactSelectStyles || {},
|
package/index.js
CHANGED
|
@@ -7188,6 +7188,7 @@ const WidgetForm = ({
|
|
|
7188
7188
|
const [blogLimit, setBlogLimit] = useState(10);
|
|
7189
7189
|
const [blogCategories, setBlogCategories] = useState([]);
|
|
7190
7190
|
const [blogCategoriesLoading, setBlogCategoriesLoading] = useState(false);
|
|
7191
|
+
const pagesLoadedRef = useRef(false);
|
|
7191
7192
|
useEffect(() => {
|
|
7192
7193
|
if (data && formState === 'UPDATE') {
|
|
7193
7194
|
const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
|
|
@@ -7266,56 +7267,16 @@ const WidgetForm = ({
|
|
|
7266
7267
|
}
|
|
7267
7268
|
}
|
|
7268
7269
|
}, [formState, data, currentItemsType, blogCategories, blogCategory, blogLimit]);
|
|
7269
|
-
//
|
|
7270
|
+
// Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
|
|
7270
7271
|
useEffect(() => {
|
|
7271
7272
|
if (currentItemsType === 'blog') {
|
|
7272
|
-
if (blogCategory
|
|
7273
|
-
//
|
|
7274
|
-
const fetchBlogsByCategory = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
7275
|
-
var _a;
|
|
7276
|
-
try {
|
|
7277
|
-
setCollectionItemsUpdated(false);
|
|
7278
|
-
const response = yield commonApi({
|
|
7279
|
-
baseUrl,
|
|
7280
|
-
token,
|
|
7281
|
-
method: 'POST',
|
|
7282
|
-
url: `${widgetRoutesPrefix}/collection-data`,
|
|
7283
|
-
data: {
|
|
7284
|
-
search: '',
|
|
7285
|
-
collectionName: 'blog',
|
|
7286
|
-
collectionItems: []
|
|
7287
|
-
},
|
|
7288
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7289
|
-
onError: error => console.error('Error fetching blogs:', error)
|
|
7290
|
-
});
|
|
7291
|
-
if ((response === null || response === void 0 ? void 0 : response.code) === 'SUCCESS' && Array.isArray((_a = response.data) === null || _a === void 0 ? void 0 : _a.docs)) {
|
|
7292
|
-
// Filter blogs by selected category
|
|
7293
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7294
|
-
const filteredBlogs = response.data.docs
|
|
7295
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7296
|
-
.filter(blog => Array.isArray(blog.category) &&
|
|
7297
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7298
|
-
blog.category.some(cat => cat.id === blogCategory.value)).slice(0, blogLimit)
|
|
7299
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
7300
|
-
.map(blog => Object.assign(Object.assign({}, blog), {
|
|
7301
|
-
value: blog._id,
|
|
7302
|
-
label: blog.name || blog.title
|
|
7303
|
-
}));
|
|
7304
|
-
setSelectedCollectionItems(filteredBlogs);
|
|
7305
|
-
setCollectionItemsUpdated(true);
|
|
7306
|
-
}
|
|
7307
|
-
} catch (error) {
|
|
7308
|
-
console.error('Error fetching blogs:', error);
|
|
7309
|
-
}
|
|
7310
|
-
});
|
|
7311
|
-
fetchBlogsByCategory();
|
|
7312
|
-
} else if (!blogCategory) {
|
|
7313
|
-
// Clear selected blogs when category is cleared
|
|
7273
|
+
if (blogCategory || blogLimit > 0) {
|
|
7274
|
+
// Clear selected collection items since server will fetch latest blogs based on category/limit
|
|
7314
7275
|
setSelectedCollectionItems([]);
|
|
7315
7276
|
setCollectionItemsUpdated(true);
|
|
7316
7277
|
}
|
|
7317
7278
|
}
|
|
7318
|
-
}, [blogCategory, blogLimit, currentItemsType
|
|
7279
|
+
}, [blogCategory, blogLimit, currentItemsType]);
|
|
7319
7280
|
// Reset blog category and limit when itemsType changes away from 'blogs'
|
|
7320
7281
|
useEffect(() => {
|
|
7321
7282
|
if (currentItemsType !== 'blog') {
|
|
@@ -7332,6 +7293,18 @@ const WidgetForm = ({
|
|
|
7332
7293
|
setBlogLimit(limit);
|
|
7333
7294
|
}
|
|
7334
7295
|
}, [watchedBlogLimit, currentItemsType]);
|
|
7296
|
+
// Load pages data when Links widget type is selected
|
|
7297
|
+
useEffect(() => {
|
|
7298
|
+
if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue && (selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value) === constants.pagesItemsTypeValue && !pagesLoadedRef.current) {
|
|
7299
|
+
// Trigger initial load of pages
|
|
7300
|
+
pagesLoadedRef.current = true;
|
|
7301
|
+
getCollectionData(constants.pagesItemsTypeValue, '');
|
|
7302
|
+
}
|
|
7303
|
+
// Reset ref when widget type changes away from Links
|
|
7304
|
+
if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) !== constants.linksWidgetTypeValue) {
|
|
7305
|
+
pagesLoadedRef.current = false;
|
|
7306
|
+
}
|
|
7307
|
+
}, [selectedWidgetType, selectedCollectionType, getCollectionData]);
|
|
7335
7308
|
const onChangeSearch = (str, callback, collectionName) => {
|
|
7336
7309
|
let collectionItems = [];
|
|
7337
7310
|
let valueToSet = '';
|
|
@@ -7521,8 +7494,12 @@ const WidgetForm = ({
|
|
|
7521
7494
|
}
|
|
7522
7495
|
return item;
|
|
7523
7496
|
});
|
|
7524
|
-
const submitPayload = Object.assign(Object.assign({}, formData), {
|
|
7497
|
+
const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
|
|
7525
7498
|
items
|
|
7499
|
+
}), blogCategory && {
|
|
7500
|
+
blogCategory: blogCategory.value
|
|
7501
|
+
}), blogLimit && {
|
|
7502
|
+
blogLimit
|
|
7526
7503
|
});
|
|
7527
7504
|
onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(undefined, submitPayload);
|
|
7528
7505
|
onWidgetFormSubmit(submitPayload);
|
|
@@ -7768,7 +7745,7 @@ const WidgetForm = ({
|
|
|
7768
7745
|
loadOptions: onChangeSearch,
|
|
7769
7746
|
isLoading: collectionDataLoading,
|
|
7770
7747
|
disabled: currentItemsType === 'blog' && !!blogCategory,
|
|
7771
|
-
show: !itemsEnabled && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
|
|
7748
|
+
show: !itemsEnabled && currentItemsType !== 'blog' && ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.carouselWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.fixedCardWidgetTypeValue || (selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) === constants.linksWidgetTypeValue || !selectedWidgetType) && !!(selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value),
|
|
7772
7749
|
formatOptionLabel: formatOptionLabel,
|
|
7773
7750
|
listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
|
|
7774
7751
|
customStyles: reactSelectStyles || {},
|