♻️ sig document to api

This commit is contained in:
Timur Ercan
2023-02-28 19:53:22 +01:00
parent 00d8724be5
commit 9741959d09
3 changed files with 40 additions and 27 deletions

View File

@ -1,2 +1,3 @@
export { createOrUpdateField } from "./createOrUpdateField";
export { deleteField } from "./deleteField";
export { signDocument } from "./signDocument";

View File

@ -0,0 +1,25 @@
import { useRouter } from "next/router";
import toast from "react-hot-toast";
export const signDocument = (
document: any,
signatures: any[],
token: string
): Promise<any> => {
const body = { documentId: document.id, signatures };
return toast.promise(
fetch(`/api/documents/${document.id}/sign?token=${token}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(body),
}),
{
loading: "Signing...",
success: `"${document.title}" signed successfully.`,
error: "Could not sign :/",
}
);
};