♻️ upsertField and delete Field to package

This commit is contained in:
Timur Ercan
2023-02-28 16:55:16 +01:00
parent 103f9cbe36
commit 31cd1fd625
5 changed files with 84 additions and 134 deletions

View File

@@ -0,0 +1,35 @@
import toast from "react-hot-toast";
export const createOrUpdateField = async (
document: any,
field: any
): Promise<any> => {
try {
const created = await toast.promise(
fetch("/api/documents/" + document.id + "/fields", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(field),
}).then((res) => {
if (!res.ok) {
throw new Error(res.status.toString());
}
return res.json();
}),
{
loading: "Adding...",
success: "Added.",
error: "Could not add :/",
},
{
id: "saving field",
style: {
minWidth: "200px",
},
}
);
return created;
} catch (error) {}
};