mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
♻️ 🧹 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) {}
|
||||
};
|
||||
31
packages/lib/api/deleteRecipient.ts
Normal file
31
packages/lib/api/deleteRecipient.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export const deleteRecipient = (recipient: any) => {
|
||||
if (!recipient.id) {
|
||||
return;
|
||||
}
|
||||
|
||||
return toast.promise(
|
||||
fetch(
|
||||
"/api/documents/" + recipient.documentId + "/recipients/" + recipient.id,
|
||||
{
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(recipient),
|
||||
}
|
||||
),
|
||||
{
|
||||
loading: "Deleting...",
|
||||
success: "Deleted.",
|
||||
error: "Could not delete :/",
|
||||
},
|
||||
{
|
||||
id: "delete",
|
||||
style: {
|
||||
minWidth: "200px",
|
||||
},
|
||||
}
|
||||
);
|
||||
};
|
||||
@ -4,4 +4,7 @@ export { signDocument } from "./signDocument";
|
||||
export { getUser } from "./getUser";
|
||||
export { signup } from "./signup";
|
||||
export { getDocuments } from "./getDocuments";
|
||||
export { deleteDocument } from "./deleteDocument";
|
||||
export { deleteDocument } from "./deleteDocument";
|
||||
export { deleteRecipient } from "./deleteRecipient";
|
||||
export { createOrUpdateRecipient } from "./createOrUpdateRecipient";
|
||||
export { sendSigningRequests } from "./sendSigningRequests";
|
||||
32
packages/lib/api/sendSigningRequests.ts
Normal file
32
packages/lib/api/sendSigningRequests.ts
Normal file
@ -0,0 +1,32 @@
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
export const sendSigningRequests = async (
|
||||
document: any,
|
||||
resendTo: number[] = []
|
||||
) => {
|
||||
if (!document || !document.id) return;
|
||||
try {
|
||||
const sent = await toast.promise(
|
||||
fetch(`/api/documents/${document.id}/send`, {
|
||||
body: JSON.stringify({ resendTo: resendTo }),
|
||||
headers: { "Content-Type": "application/json" },
|
||||
method: "POST",
|
||||
})
|
||||
.then((res: any) => {
|
||||
if (!res.ok) {
|
||||
throw new Error(res.status.toString());
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
location.reload();
|
||||
}),
|
||||
{
|
||||
loading: "Sending...",
|
||||
success: `Sent!`,
|
||||
error: "Could not send :/",
|
||||
}
|
||||
);
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user