# post-carousel/4.0.7/src/admin/hooks/createBlockPage.js

Smart Post – Post Grid, Post Carousel, Post Slider Gutenberg Blocks for Blog &amp; News, version 4.0.7. 39 lines.

- Page: https://pluginprobe.com/plugins/post-carousel/4.0.7/code/src/admin/hooks/createBlockPage.js
- Raw: https://pluginprobe.com/plugins/post-carousel/4.0.7/raw/src/admin/hooks/createBlockPage.js
- Modified: 2026-04-24T11:48:54+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/post-carousel/4.0.7/code/src/admin/hooks/createBlockPage.js#L10-L20`.

```javascript
import axios from "axios";
import { jsonStringify } from "../../blocks/shared/helpFn";

const useCreateBlockPage = ({ actionType, templateType, id, status, attributes, setAttributes }) => {
	const data = new FormData();
	const queryData = {
		actionType: actionType,
		templateId: id,
		status: status,
		templateType: templateType,
	};

	data.append("nonce", sp_pcp_block_settings.nonce);
	data.append("action", "sp_smart_post_create_page");
	data.append("data", jsonStringify(queryData));

	const fetchApi = async (data) => {
		try {
			const response = await axios.post(ajaxurl, data);
			if ("createBlankTemplate" === actionType) {
				const { newID } = response.data;
				location.href = `${sp_pcp_block_settings.homeUrl}wp-admin/post.php?post=${newID}&action=edit`;
			} else {
				setAttributes({
					...attributes,
					showTemplate: true,
					templateLists: response.data?.templateLists,
				});
			}
		} catch (error) {
			console.error("Error fetching posts:", error.message);
		}
	};

	return fetchApi(data);
};

export default useCreateBlockPage;

```
