feat: store profile signature

This commit is contained in:
Mythie
2023-09-01 18:43:53 +10:00
parent 901013fdc6
commit 7218b950fe
6 changed files with 13 additions and 11 deletions

View File

@@ -3,6 +3,7 @@ import { notFound } from 'next/navigation';
import { match } from 'ts-pattern'; import { match } from 'ts-pattern';
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer'; import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
import { getServerComponentSession } from '@documenso/lib/next-auth/get-server-session';
import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token'; import { getDocumentAndSenderByToken } from '@documenso/lib/server-only/document/get-document-by-token';
import { viewedDocument } from '@documenso/lib/server-only/document/viewed-document'; import { viewedDocument } from '@documenso/lib/server-only/document/viewed-document';
import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token'; import { getFieldsForToken } from '@documenso/lib/server-only/field/get-fields-for-token';
@@ -42,10 +43,12 @@ export default async function SigningPage({ params: { token } }: SigningPageProp
return notFound(); return notFound();
} }
const user = await getServerComponentSession();
const documentUrl = `data:application/pdf;base64,${document.document}`; const documentUrl = `data:application/pdf;base64,${document.document}`;
return ( return (
<SigningProvider email={recipient.email} fullName={recipient.name}> <SigningProvider email={recipient.email} fullName={recipient.name} signature={user?.signature}>
<div className="mx-auto w-full max-w-screen-xl px-4 md:px-8"> <div className="mx-auto w-full max-w-screen-xl px-4 md:px-8">
<h1 className="mt-4 truncate text-2xl font-semibold md:text-3xl" title={document.title}> <h1 className="mt-4 truncate text-2xl font-semibold md:text-3xl" title={document.title}>
{document.title} {document.title}

View File

@@ -28,9 +28,9 @@ export const useRequiredSigningContext = () => {
}; };
export interface SigningProviderProps { export interface SigningProviderProps {
fullName?: string; fullName?: string | null;
email?: string; email?: string | null;
signature?: string; signature?: string | null;
children: React.ReactNode; children: React.ReactNode;
} }

View File

@@ -118,6 +118,7 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => {
render={({ field: { onChange } }) => ( render={({ field: { onChange } }) => (
<SignaturePad <SignaturePad
className="h-44 w-full rounded-lg border bg-white backdrop-blur-sm dark:border-[#e2d7c5] dark:bg-[#fcf8ee]" className="h-44 w-full rounded-lg border bg-white backdrop-blur-sm dark:border-[#e2d7c5] dark:bg-[#fcf8ee]"
defaultValue={user.signature ?? undefined}
onChange={(v) => onChange(v ?? '')} onChange={(v) => onChange(v ?? '')}
/> />
)} )}

View File

@@ -6,12 +6,7 @@ export type UpdateProfileOptions = {
signature: string; signature: string;
}; };
export const updateProfile = async ({ export const updateProfile = async ({ userId, name, signature }: UpdateProfileOptions) => {
userId,
name,
// TODO: Actually use signature
signature: _signature,
}: UpdateProfileOptions) => {
// Existence check // Existence check
await prisma.user.findFirstOrThrow({ await prisma.user.findFirstOrThrow({
where: { where: {
@@ -25,7 +20,7 @@ export const updateProfile = async ({
}, },
data: { data: {
name, name,
// signature, signature,
}, },
}); });

View File

@@ -0,0 +1,2 @@
-- AlterTable
ALTER TABLE "User" ADD COLUMN "signature" TEXT;

View File

@@ -20,6 +20,7 @@ model User {
emailVerified DateTime? emailVerified DateTime?
password String? password String?
source String? source String?
signature String?
identityProvider IdentityProvider @default(DOCUMENSO) identityProvider IdentityProvider @default(DOCUMENSO)
accounts Account[] accounts Account[]
sessions Session[] sessions Session[]