♻️ 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,36 @@
import toast from "react-hot-toast";
export const deleteField = async (field: any) => {
if (!field.id) {
return;
}
try {
const deleted = toast.promise(
fetch("/api/documents/" + 0 + "/fields/" + field.id, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(field),
}).then((res) => {
if (!res.ok) {
throw new Error(res.status.toString());
}
return res;
}),
{
loading: "Deleting...",
success: "Deleted.",
error: "Could not delete :/",
},
{
id: "delete",
style: {
minWidth: "200px",
},
}
);
return deleted;
} catch (error) {}
};