Files
documenso/packages/lib/api/createOrUpdateRecipient.ts
2023-03-01 15:41:43 +01:00

33 lines
782 B
TypeScript

import toast from "react-hot-toast";
export const createOrUpdateRecipient = async (recipient: any): Promise<any> => {
try {
const created = await toast.promise(
fetch("/api/documents/" + recipient.documentId + "/recipients", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(recipient),
}).then((res) => {
if (!res.ok) {
throw new Error(res.status.toString());
}
return res.json();
}),
{
loading: "Saving...",
success: "Saved.",
error: "Could not save :/",
},
{
id: "saving",
style: {
minWidth: "200px",
},
}
);
return created;
} catch (error) {}
};