I’m trying to make a button that will create a page when you click it. But I am missing something basic. Here’s my code. It properly displays the macro, but when I click the button, no page is created.
Any hints would be greatly appreciated. Thank you.
import ForgeUI, { render, useState, ModalDialog, Macro, Fragment, Button } from "@forge/ui";
import { Form, Select, Option } from "@forge/react";
import api, { route } from "@forge/api";
var bodyData = `{
"spaceId": "ForgeTest",
"title": "Test Page",
}`;
const clickthebutton = async () => {await api.asUser().requestConfluence(route`/wiki/rest/api/page`, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: bodyData
})};
// Boilerplate to operate the macro
const App = () => {
return (
<Button
text="Create page"
onClick={async () => {
await clickthebutton;
}}
/>
);
};
// Boilerplate to display the macro
export const run = render(
<Macro
app={<App />}
/>
);