♻️ 🧹 upsert reciient, deleteRecipient, send
This commit is contained in:
32
packages/lib/api/createOrUpdateRecipient.ts
Normal file
32
packages/lib/api/createOrUpdateRecipient.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
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) {}
|
||||
};
|
||||
Reference in New Issue
Block a user