🚧 ondelete to editor

This commit is contained in:
Timur Ercan
2023-02-14 17:04:53 +01:00
parent 6a1c75b165
commit 2f0fd4757e
3 changed files with 57 additions and 29 deletions

View File

@ -18,6 +18,7 @@ type FieldPropsType = {
recipient: string;
};
onPositionChanged: any;
onDelete: any;
};
export default function Field(props: FieldPropsType) {
@ -56,9 +57,9 @@ export default function Field(props: FieldPropsType) {
<div className="m-auto w-auto flex-row-reverse text-lg font-bold text-center">
<IconButton
icon={TrashIcon}
onClick={(e: any) => {
onClick={(event: any) => {
if (confirm("Delete field?")) {
deleteField(e, props.field);
props.onDelete(props.field.id);
}
}}
></IconButton>
@ -70,30 +71,3 @@ export default function Field(props: FieldPropsType) {
</Draggable>
);
}
function deleteField(event: any, field: any) {
if (!field.id) {
return;
}
return toast.promise(
fetch("/api/documents/" + 0 + "/fields/" + field.id, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(field),
}),
{
loading: "Deleting...",
success: "Deleted.",
error: "Could not delete :/",
},
{
id: "delete",
style: {
minWidth: "200px",
},
}
);
}