onProjectNew
Project creation handler
This example demonstrates how the onProjectNew callback
sends a request using the Fetch API to create a new project. Once the request completes, the
result is returned to the widget through the
onResponse
callback.
Project creation handler
onProjectNew = async function(project: DIQ_Project, onResponse: (result: DIQ_Result) => void ) {
try {
const res = await fetch("/api/projects", {
method: "POST",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(project)
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
await res.json();
onResponse({ ok: true });
} catch (err) {
onResponse({
ok: false,
message: err.message || "Failed to create project"
});
}
};