PluginProbe
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News / 4.0.4
Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News v4.0.4
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 / admin / hooks / createBlockPage.js

createBlockPage.js in Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog & News 4.0.4, at src/admin/hooks/createBlockPage.js

39 lines 1.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import axios from "axios";
2 import { jsonStringify } from "../../blocks/shared/helpFn";
3
4 const useCreateBlockPage = ({ actionType, templateType, id, status, attributes, setAttributes }) => {
5 const data = new FormData();
6 const queryData = {
7 actionType: actionType,
8 templateId: id,
9 status: status,
10 templateType: templateType,
11 };
12
13 data.append("nonce", sp_pcp_block_settings.nonce);
14 data.append("action", "sp_smart_post_create_page");
15 data.append("data", jsonStringify(queryData));
16
17 const fetchApi = async (data) => {
18 try {
19 const response = await axios.post(ajaxurl, data);
20 if ("createBlankTemplate" === actionType) {
21 const { newID } = response.data;
22 location.href = `${sp_pcp_block_settings.homeUrl}wp-admin/post.php?post=${newID}&action=edit`;
23 } else {
24 setAttributes({
25 ...attributes,
26 showTemplate: true,
27 templateLists: response.data?.templateLists,
28 });
29 }
30 } catch (error) {
31 console.error("Error fetching posts:", error.message);
32 }
33 };
34
35 return fetchApi(data);
36 };
37
38 export default useCreateBlockPage;
39