PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.8
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.8
4.0.8 4.0.7 4.0.6 4.0.5 4.0.4 4.0.3 4.0.2 4.0.1 2.3.5 2.3.6 2.4.0 2.4.1 2.4.10 2.4.11 2.4.12 2.4.13 2.4.14 2.4.15 2.4.16 2.4.17 2.4.18 2.4.19 2.4.2 2.4.20 2.4.21 All 88 releases
post-carousel / src / divi-5 / settings-content.jsx

settings-content.jsx in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.8, at src/divi-5/settings-content.jsx

70 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * Settings Content Component
3 *
4 * Handles dynamic options for select fields in Divi 5 module settings
5 *
6 * @package Smart_Post_Show_Pro
7 */
8
9 // Access Divi globals
10 const { useState, useEffect } = window?.vendor?.wp?.element;
11 const { set } = window?.lodash;
12 const loggedFetch = window?.divi?.rest?.loggedFetch;
13 const ModuleGroups = window?.divi?.module?.ModuleGroups;
14
15 /**
16 * Settings Content Panel Component
17 *
18 * @param {Object} props Component props
19 * @returns {JSX.Element}
20 */
21 const SettingsContent = ({ groupConfiguration }) => {
22 const [templates, setTemplates] = useState({
23 0: { label: "- Select Template -" },
24 });
25
26 // Fetch templates from REST API
27 useEffect(() => {
28 const fetchTemplates = async () => {
29 try {
30 const result = await loggedFetch({
31 method: "GET",
32 restRoute: "/spsp/divi5/v1/saved-templates",
33 });
34
35 // loggedFetch returns the data directly or wrapped in response object
36 const data = result?.data || result;
37
38 if (data && typeof data === "object") {
39 // Transform to the format expected by Divi select field
40 const options = {};
41 options["0"] = { label: "- Select Template -" };
42 Object.entries(data).forEach(([id, label]) => {
43 options[id] = { label: label };
44 });
45
46 setTemplates(options);
47 }
48 } catch (error) {
49 console.error("Failed to fetch templates:", error);
50 }
51 };
52
53 fetchTemplates();
54 }, []); // Empty dependency array - fetch only once on mount
55
56 // Update the select field options dynamically
57 if (groupConfiguration?.mainContent?.component) {
58 set(
59 groupConfiguration,
60 ["mainContent", "component", "props", "fields", "templateIdInnerContent", "component", "props", "options"],
61 templates
62 );
63 }
64
65 return <ModuleGroups groups={groupConfiguration} />;
66 };
67
68 // Export the component
69 export { SettingsContent };
70