recipients

This commit is contained in:
Timur Ercan
2023-02-03 19:57:54 +01:00
parent 8bbf40005c
commit dfdeffc289
3 changed files with 11 additions and 12 deletions

View File

@ -56,7 +56,10 @@ const DocumentsDetailPage: NextPageWithLayout = (props: any) => {
className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400"
aria-hidden="true"
/>
<Link href={`/documents/${props.document.id}/recipients`}>
{props?.document?.Recipient?.length} Recipients
</Link>
</div>
<div className="mt-2 flex items-center text-sm text-gray-500">
<InformationCircleIcon

View File

@ -159,19 +159,13 @@ const RecipientsPage: NextPageWithLayout = (props: any) => {
icon={UserPlusIcon}
className="mt-3"
onClick={() => {
setSigners(
signers.concat({
id: "",
email: "",
name: "",
documentId: props.document.id,
})
);
upsertRecipient({
id: "",
email: "",
name: "",
documentId: props.document.id,
}).then((res) => {
setSigners(signers.concat(res));
});
}}
>
@ -218,9 +212,9 @@ async function deleteRecipient(recipient: any) {
);
}
async function upsertRecipient(recipient: any) {
async function upsertRecipient(recipient: any): Promise<any> {
try {
await toast.promise(
const created = await toast.promise(
fetch("/api/documents/" + recipient.documentId + "/recipients", {
method: "POST",
headers: {
@ -231,6 +225,7 @@ async function upsertRecipient(recipient: any) {
if (!res.ok) {
throw new Error(res.status.toString());
}
return res.json();
}),
{
loading: "Saving...",
@ -244,6 +239,7 @@ async function upsertRecipient(recipient: any) {
},
}
);
return created;
} catch (error) {}
}

View File

@ -20,7 +20,7 @@ model Document {
model Recipient {
id Int @id @default(autoincrement())
documentId Int
email String @unique @db.VarChar(255)
email String @db.VarChar(255)
name String @default("") @db.VarChar(255)
token String
readStatus ReadStatus @default(NOT_OPENED)