@knovator/pagecreator-admin 1.6.8 → 1.6.10
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 +34 -50
- package/index.js +34 -50
- package/package.json +1 -1
package/index.cjs
CHANGED
|
@@ -7200,6 +7200,8 @@ 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);
|
|
7204
|
+
const blogCategoryInitialized = React.useRef(false);
|
|
7203
7205
|
React.useEffect(() => {
|
|
7204
7206
|
if (data && formState === 'UPDATE') {
|
|
7205
7207
|
const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
|
|
@@ -7264,78 +7266,44 @@ const WidgetForm = ({
|
|
|
7264
7266
|
}, [currentItemsType, baseUrl, token, widgetRoutesPrefix, blogCategories.length]);
|
|
7265
7267
|
// Set blog category and limit when editing a widget
|
|
7266
7268
|
React.useEffect(() => {
|
|
7267
|
-
if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0) {
|
|
7269
|
+
if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0 && !blogCategoryInitialized.current) {
|
|
7268
7270
|
// Set blog category if it exists in the data
|
|
7269
|
-
if (data.blogCategory
|
|
7271
|
+
if (data.blogCategory) {
|
|
7270
7272
|
const savedCategory = blogCategories.find(cat => cat.value === data.blogCategory);
|
|
7271
7273
|
if (savedCategory) {
|
|
7272
7274
|
setBlogCategory(savedCategory);
|
|
7275
|
+
blogCategoryInitialized.current = true;
|
|
7273
7276
|
}
|
|
7274
7277
|
}
|
|
7275
7278
|
// Set blog limit if it exists in the data
|
|
7276
|
-
if (data.blogLimit
|
|
7279
|
+
if (data.blogLimit) {
|
|
7277
7280
|
setBlogLimit(data.blogLimit);
|
|
7278
7281
|
}
|
|
7279
7282
|
}
|
|
7280
|
-
}, [formState, data, currentItemsType, blogCategories
|
|
7281
|
-
//
|
|
7283
|
+
}, [formState, data, currentItemsType, blogCategories]);
|
|
7284
|
+
// Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
|
|
7282
7285
|
React.useEffect(() => {
|
|
7283
7286
|
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
|
|
7287
|
+
if (blogCategory || blogLimit > 0) {
|
|
7288
|
+
// Clear selected collection items since server will fetch latest blogs based on category/limit
|
|
7326
7289
|
setSelectedCollectionItems([]);
|
|
7327
7290
|
setCollectionItemsUpdated(true);
|
|
7328
7291
|
}
|
|
7329
7292
|
}
|
|
7330
|
-
}, [blogCategory, blogLimit, currentItemsType
|
|
7293
|
+
}, [blogCategory, blogLimit, currentItemsType]);
|
|
7331
7294
|
// Reset blog category and limit when itemsType changes away from 'blogs'
|
|
7332
7295
|
React.useEffect(() => {
|
|
7333
7296
|
if (currentItemsType !== 'blog') {
|
|
7334
7297
|
setBlogCategory(null);
|
|
7335
7298
|
setBlogLimit(10);
|
|
7336
7299
|
setBlogCategories([]);
|
|
7300
|
+
blogCategoryInitialized.current = false;
|
|
7337
7301
|
}
|
|
7338
7302
|
}, [currentItemsType]);
|
|
7303
|
+
// Reset initialization flag when opening a different widget or changing form state
|
|
7304
|
+
React.useEffect(() => {
|
|
7305
|
+
blogCategoryInitialized.current = false;
|
|
7306
|
+
}, [data === null || data === void 0 ? void 0 : data._id, formState]);
|
|
7339
7307
|
// Watch blogLimit form value and update state
|
|
7340
7308
|
const watchedBlogLimit = watch('blogLimit');
|
|
7341
7309
|
React.useEffect(() => {
|
|
@@ -7344,6 +7312,18 @@ const WidgetForm = ({
|
|
|
7344
7312
|
setBlogLimit(limit);
|
|
7345
7313
|
}
|
|
7346
7314
|
}, [watchedBlogLimit, currentItemsType]);
|
|
7315
|
+
// Load pages data when Links widget type is selected
|
|
7316
|
+
React.useEffect(() => {
|
|
7317
|
+
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) {
|
|
7318
|
+
// Trigger initial load of pages
|
|
7319
|
+
pagesLoadedRef.current = true;
|
|
7320
|
+
getCollectionData(constants.pagesItemsTypeValue, '');
|
|
7321
|
+
}
|
|
7322
|
+
// Reset ref when widget type changes away from Links
|
|
7323
|
+
if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) !== constants.linksWidgetTypeValue) {
|
|
7324
|
+
pagesLoadedRef.current = false;
|
|
7325
|
+
}
|
|
7326
|
+
}, [selectedWidgetType, selectedCollectionType, getCollectionData]);
|
|
7347
7327
|
const onChangeSearch = (str, callback, collectionName) => {
|
|
7348
7328
|
let collectionItems = [];
|
|
7349
7329
|
let valueToSet = '';
|
|
@@ -7533,8 +7513,12 @@ const WidgetForm = ({
|
|
|
7533
7513
|
}
|
|
7534
7514
|
return item;
|
|
7535
7515
|
});
|
|
7536
|
-
const submitPayload = Object.assign(Object.assign({}, formData), {
|
|
7516
|
+
const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
|
|
7537
7517
|
items
|
|
7518
|
+
}), blogCategory && {
|
|
7519
|
+
blogCategory: blogCategory.value
|
|
7520
|
+
}), blogLimit && {
|
|
7521
|
+
blogLimit
|
|
7538
7522
|
});
|
|
7539
7523
|
onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(undefined, submitPayload);
|
|
7540
7524
|
onWidgetFormSubmit(submitPayload);
|
|
@@ -7780,7 +7764,7 @@ const WidgetForm = ({
|
|
|
7780
7764
|
loadOptions: onChangeSearch,
|
|
7781
7765
|
isLoading: collectionDataLoading,
|
|
7782
7766
|
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),
|
|
7767
|
+
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
7768
|
formatOptionLabel: formatOptionLabel,
|
|
7785
7769
|
listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
|
|
7786
7770
|
customStyles: reactSelectStyles || {},
|
package/index.js
CHANGED
|
@@ -7188,6 +7188,8 @@ 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);
|
|
7192
|
+
const blogCategoryInitialized = useRef(false);
|
|
7191
7193
|
useEffect(() => {
|
|
7192
7194
|
if (data && formState === 'UPDATE') {
|
|
7193
7195
|
const widgetType = widgetTypes.find(type => type.value === (data === null || data === void 0 ? void 0 : data.widgetType));
|
|
@@ -7252,78 +7254,44 @@ const WidgetForm = ({
|
|
|
7252
7254
|
}, [currentItemsType, baseUrl, token, widgetRoutesPrefix, blogCategories.length]);
|
|
7253
7255
|
// Set blog category and limit when editing a widget
|
|
7254
7256
|
useEffect(() => {
|
|
7255
|
-
if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0) {
|
|
7257
|
+
if (formState === 'UPDATE' && data && currentItemsType === 'blog' && blogCategories.length > 0 && !blogCategoryInitialized.current) {
|
|
7256
7258
|
// Set blog category if it exists in the data
|
|
7257
|
-
if (data.blogCategory
|
|
7259
|
+
if (data.blogCategory) {
|
|
7258
7260
|
const savedCategory = blogCategories.find(cat => cat.value === data.blogCategory);
|
|
7259
7261
|
if (savedCategory) {
|
|
7260
7262
|
setBlogCategory(savedCategory);
|
|
7263
|
+
blogCategoryInitialized.current = true;
|
|
7261
7264
|
}
|
|
7262
7265
|
}
|
|
7263
7266
|
// Set blog limit if it exists in the data
|
|
7264
|
-
if (data.blogLimit
|
|
7267
|
+
if (data.blogLimit) {
|
|
7265
7268
|
setBlogLimit(data.blogLimit);
|
|
7266
7269
|
}
|
|
7267
7270
|
}
|
|
7268
|
-
}, [formState, data, currentItemsType, blogCategories
|
|
7269
|
-
//
|
|
7271
|
+
}, [formState, data, currentItemsType, blogCategories]);
|
|
7272
|
+
// Clear collectionItems when using blog category/limit (server will handle fetching latest blogs)
|
|
7270
7273
|
useEffect(() => {
|
|
7271
7274
|
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
|
|
7275
|
+
if (blogCategory || blogLimit > 0) {
|
|
7276
|
+
// Clear selected collection items since server will fetch latest blogs based on category/limit
|
|
7314
7277
|
setSelectedCollectionItems([]);
|
|
7315
7278
|
setCollectionItemsUpdated(true);
|
|
7316
7279
|
}
|
|
7317
7280
|
}
|
|
7318
|
-
}, [blogCategory, blogLimit, currentItemsType
|
|
7281
|
+
}, [blogCategory, blogLimit, currentItemsType]);
|
|
7319
7282
|
// Reset blog category and limit when itemsType changes away from 'blogs'
|
|
7320
7283
|
useEffect(() => {
|
|
7321
7284
|
if (currentItemsType !== 'blog') {
|
|
7322
7285
|
setBlogCategory(null);
|
|
7323
7286
|
setBlogLimit(10);
|
|
7324
7287
|
setBlogCategories([]);
|
|
7288
|
+
blogCategoryInitialized.current = false;
|
|
7325
7289
|
}
|
|
7326
7290
|
}, [currentItemsType]);
|
|
7291
|
+
// Reset initialization flag when opening a different widget or changing form state
|
|
7292
|
+
useEffect(() => {
|
|
7293
|
+
blogCategoryInitialized.current = false;
|
|
7294
|
+
}, [data === null || data === void 0 ? void 0 : data._id, formState]);
|
|
7327
7295
|
// Watch blogLimit form value and update state
|
|
7328
7296
|
const watchedBlogLimit = watch('blogLimit');
|
|
7329
7297
|
useEffect(() => {
|
|
@@ -7332,6 +7300,18 @@ const WidgetForm = ({
|
|
|
7332
7300
|
setBlogLimit(limit);
|
|
7333
7301
|
}
|
|
7334
7302
|
}, [watchedBlogLimit, currentItemsType]);
|
|
7303
|
+
// Load pages data when Links widget type is selected
|
|
7304
|
+
useEffect(() => {
|
|
7305
|
+
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) {
|
|
7306
|
+
// Trigger initial load of pages
|
|
7307
|
+
pagesLoadedRef.current = true;
|
|
7308
|
+
getCollectionData(constants.pagesItemsTypeValue, '');
|
|
7309
|
+
}
|
|
7310
|
+
// Reset ref when widget type changes away from Links
|
|
7311
|
+
if ((selectedWidgetType === null || selectedWidgetType === void 0 ? void 0 : selectedWidgetType.value) !== constants.linksWidgetTypeValue) {
|
|
7312
|
+
pagesLoadedRef.current = false;
|
|
7313
|
+
}
|
|
7314
|
+
}, [selectedWidgetType, selectedCollectionType, getCollectionData]);
|
|
7335
7315
|
const onChangeSearch = (str, callback, collectionName) => {
|
|
7336
7316
|
let collectionItems = [];
|
|
7337
7317
|
let valueToSet = '';
|
|
@@ -7521,8 +7501,12 @@ const WidgetForm = ({
|
|
|
7521
7501
|
}
|
|
7522
7502
|
return item;
|
|
7523
7503
|
});
|
|
7524
|
-
const submitPayload = Object.assign(Object.assign({}, formData), {
|
|
7504
|
+
const submitPayload = Object.assign(Object.assign(Object.assign(Object.assign({}, formData), {
|
|
7525
7505
|
items
|
|
7506
|
+
}), blogCategory && {
|
|
7507
|
+
blogCategory: blogCategory.value
|
|
7508
|
+
}), blogLimit && {
|
|
7509
|
+
blogLimit
|
|
7526
7510
|
});
|
|
7527
7511
|
onPrimaryButtonClick === null || onPrimaryButtonClick === void 0 ? void 0 : onPrimaryButtonClick(undefined, submitPayload);
|
|
7528
7512
|
onWidgetFormSubmit(submitPayload);
|
|
@@ -7768,7 +7752,7 @@ const WidgetForm = ({
|
|
|
7768
7752
|
loadOptions: onChangeSearch,
|
|
7769
7753
|
isLoading: collectionDataLoading,
|
|
7770
7754
|
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),
|
|
7755
|
+
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
7756
|
formatOptionLabel: formatOptionLabel,
|
|
7773
7757
|
listCode: selectedCollectionType === null || selectedCollectionType === void 0 ? void 0 : selectedCollectionType.value,
|
|
7774
7758
|
customStyles: reactSelectStyles || {},
|