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" className="mr-1.5 h-5 w-5 flex-shrink-0 text-gray-400"
aria-hidden="true" aria-hidden="true"
/> />
{props?.document?.Recipient?.length} Recipients
<Link href={`/documents/${props.document.id}/recipients`}>
{props?.document?.Recipient?.length} Recipients
</Link>
</div> </div>
<div className="mt-2 flex items-center text-sm text-gray-500"> <div className="mt-2 flex items-center text-sm text-gray-500">
<InformationCircleIcon <InformationCircleIcon

View File

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

View File

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