The Open Source DocuSign Alternative.
TypeScript digital-signaturedocument-signingdocusign-alternativee-signatureesignesignaturenext-authnextjsopen-sourcepades-standardpdfpdf-signpdf-signaturepostgresqlprismaself-hostedsigningtypescript
feat: add cta on complete page (#1028)
Catalin Pit8b58f10cbe71
diff --git a/apps/web/src/app/(signing)/sign/[token]/complete/claim-account.tsx b/apps/web/src/app/(signing)/sign/[token]/complete/claim-account.tsxnew file mode 100644index 000000000..b5f7c0ca8--- /dev/null+++ b/apps/web/src/app/(signing)/sign/[token]/complete/claim-account.tsx@@ -0,0 +1,155 @@+'use client';++import { useRouter } from 'next/navigation';++import { zodResolver } from '@hookform/resolvers/zod';+import { useForm } from 'react-hook-form';+import { z } from 'zod';++import { useAnalytics } from '@documenso/lib/client-only/hooks/use-analytics';+import { TRPCClientError } from '@documenso/trpc/client';+import { trpc } from '@documenso/trpc/react';+import { ZPasswordSchema } from '@documenso/trpc/server/auth-router/schema';+import { Button } from '@documenso/ui/primitives/button';+import {+ Form,+ FormControl,+ FormField,+ FormItem,+ FormLabel,+ FormMessage,+} from '@documenso/ui/primitives/form/form';+import { Input } from '@documenso/ui/primitives/input';+import { PasswordInput } from '@documenso/ui/primitives/password-input';+import { useToast } from '@documenso/ui/primitives/use-toast';++export type ClaimAccountProps = {+ defaultName: string;+ defaultEmail: string;+ trigger?: React.ReactNode;+};++export const ZClaimAccountFormSchema = z+ .object({+ name: z.string().trim().min(1, { message: 'Please enter a valid name.' }),+ email: z.string().email().min(1),+ password: ZPasswordSchema,+ })+ .refine(+ (data) => {+ const { name, email, password } = data;+ return !password.includes(name) && !password.includes(email.split('@')[0]);+ },+ {+ message: 'Password should not be common or based on personal information',+ path: ['password'],+ },+ );++export type TClaimAccountFormSchema = z.infer<typeof ZClaimAccountFormSchema>;++export const ClaimAccount = ({ defaultName, defaultEmail }: ClaimAccountProps) => {+ const analytics = useAnalytics();+ const { toast } = useToast();+ const router = useRouter();++ const { mutateAsync: signup } = trpc.auth.signup.useMutation();++ const form = useForm<TClaimAccountFormSchema>({+ values: {+ name: defaultName ?? '',+ email: defaultEmail,+ password: '',+ },+ resolver: zodResolver(ZClaimAccountFormSchema),+ });++ const onFormSubmit = async ({ name, email, password }: TClaimAccountFormSchema) => {+ try {+ await signup({ name, email, password });++ router.push(`/unverified-account`);++ toast({+ title: 'Registration Successful',+ description:+ 'You have successfully registered. Please verify your account by clicking on the link you received in the email.',+ duration: 5000,+ });++ analytics.capture('App: User Claim Account', {+ email,+ timestamp: new Date().toISOString(),+ });+ } catch (error) {+ if (error instanceof TRPCClientError && error.data?.code === 'BAD_REQUEST') {+ toast({+ title: 'An error occurred',+ description: error.message,+ variant: 'destructive',+ });+ } else {+ toast({+ title: 'An unknown error occurred',+ description:+ 'We encountered an unknown error while attempting to sign you up. Please try again later.',+ variant: 'destructive',+ });+ }+ }+ };++ return (+ <div className="mt-2 w-full">+ <Form {...form}>+ <form onSubmit={form.handleSubmit(onFormSubmit)}>+ <fieldset disabled={form.formState.isSubmitting} className="mt-4">+ <FormField+ name="name"+ control={form.control}+ render={({ field }) => (+ <FormItem>+ <FormLabel>Name</FormLabel>+ <FormControl>+ <Input {...field} placeholder="Enter your name" />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ name="email"+ control={form.control}+ render={({ field }) => (+ <FormItem className="mt-4">+ <FormLabel>Email address</FormLabel>+ <FormControl>+ <Input {...field} placeholder="Enter your email" />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ <FormField+ name="password"+ control={form.control}+ render={({ field }) => (+ <FormItem className="mt-4">+ <FormLabel>Set a password</FormLabel>+ <FormControl>+ <PasswordInput {...field} placeholder="Pick a password" />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ <Button type="submit" className="mt-6 w-full" loading={form.formState.isSubmitting}>+ Claim account+ </Button>+ </fieldset>+ </form>+ </Form>+ </div>+ );+};diff --git a/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx b/apps/web/src/app/(signing)/sign/[token]/complete/page.tsxindex c13d8636b..cfed976e5 100644--- a/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx+++ b/apps/web/src/app/(signing)/sign/[token]/complete/page.tsx@@ -3,6 +3,7 @@ import { notFound } from 'next/navigation';import { CheckCircle2, Clock8 } from 'lucide-react';import { getServerSession } from 'next-auth';+import { env } from 'next-runtime-env';import { match } from 'ts-pattern';import signingCelebration from '@documenso/assets/images/signing-celebration.png';@@ -16,10 +17,13 @@ import { DocumentStatus, FieldType, RecipientRole } from '@documenso/prisma/clieimport { DocumentDownloadButton } from '@documenso/ui/components/document/document-download-button';import { DocumentShareButton } from '@documenso/ui/components/document/document-share-button';import { SigningCard3D } from '@documenso/ui/components/signing-card';+import { cn } from '@documenso/ui/lib/utils';+import { Badge } from '@documenso/ui/primitives/badge';import { truncateTitle } from '~/helpers/truncate-title';import { SigningAuthPageView } from '../signing-auth-page';+import { ClaimAccount } from './claim-account';import { DocumentPreviewButton } from './document-preview-button';export type CompletedSigningPageProps = {@@ -31,6 +35,8 @@ export type CompletedSigningPageProps = {export default async function CompletedSigningPage({params: { token },}: CompletedSigningPageProps) {+ const NEXT_PUBLIC_DISABLE_SIGNUP = env('NEXT_PUBLIC_DISABLE_SIGNUP');+if (!token) {return notFound();}@@ -79,96 +85,120 @@ export default async function CompletedSigningPage({const sessionData = await getServerSession();const isLoggedIn = !!sessionData?.user;+ const canSignUp = !isLoggedIn && NEXT_PUBLIC_DISABLE_SIGNUP !== 'true';return (- <div className="-mx-4 flex max-w-[100vw] flex-col items-center overflow-x-hidden px-4 pt-24 md:-mx-8 md:px-8 lg:pt-36 xl:pt-44">- {/* Card with recipient */}- <SigningCard3D- name={recipientName}- signature={signatures.at(0)}- signingCelebrationImage={signingCelebration}- />-- <div className="relative mt-6 flex w-full flex-col items-center">- {match({ status: document.status, deletedAt: document.deletedAt })- .with({ status: DocumentStatus.COMPLETED }, () => (- <div className="text-documenso-700 flex items-center text-center">- <CheckCircle2 className="mr-2 h-5 w-5" />- <span className="text-sm">Everyone has signed</span>- </div>- ))- .with({ deletedAt: null }, () => (- <div className="flex items-center text-center text-blue-600">- <Clock8 className="mr-2 h-5 w-5" />- <span className="text-sm">Waiting for others to sign</span>- </div>- ))- .otherwise(() => (- <div className="flex items-center text-center text-red-600">- <Clock8 className="mr-2 h-5 w-5" />- <span className="text-sm">Document no longer available to sign</span>- </div>- ))}-- <h2 className="mt-6 max-w-[35ch] text-center text-2xl font-semibold leading-normal md:text-3xl lg:text-4xl">- You have- {recipient.role === RecipientRole.SIGNER && ' signed '}- {recipient.role === RecipientRole.VIEWER && ' viewed '}- {recipient.role === RecipientRole.APPROVER && ' approved '}- <span className="mt-1.5 block">"{truncatedTitle}"</span>- </h2>-- {match({ status: document.status, deletedAt: document.deletedAt })- .with({ status: DocumentStatus.COMPLETED }, () => (- <p className="text-muted-foreground/60 mt-2.5 max-w-[60ch] text-center text-sm font-medium md:text-base">- Everyone has signed! You will receive an Email copy of the signed document.- </p>- ))- .with({ deletedAt: null }, () => (- <p className="text-muted-foreground/60 mt-2.5 max-w-[60ch] text-center text-sm font-medium md:text-base">- You will receive an Email copy of the signed document once everyone has signed.- </p>- ))- .otherwise(() => (- <p className="text-muted-foreground/60 mt-2.5 max-w-[60ch] text-center text-sm font-medium md:text-base">- This document has been cancelled by the owner and is no longer available for others to- sign.- </p>- ))}-- <div className="mt-8 flex w-full max-w-sm items-center justify-center gap-4">- <DocumentShareButton documentId={document.id} token={recipient.token} />-- {document.status === DocumentStatus.COMPLETED ? (- <DocumentDownloadButton- className="flex-1"- fileName={document.title}- documentData={documentData}- disabled={document.status !== DocumentStatus.COMPLETED}- />- ) : (- <DocumentPreviewButton- className="text-[11px]"- title="Signatures will appear once the document has been completed"- documentData={documentData}- />- )}+ <div+ className={cn(+ '-mx-4 flex flex-col items-center overflow-x-hidden px-4 pt-24 md:-mx-8 md:px-8 lg:pt-36 xl:pt-44',+ { 'pt-0 lg:pt-0 xl:pt-0': canSignUp },+ )}+ >+ <div+ className={cn('relative mt-6 flex w-full flex-col items-center justify-center', {+ 'mt-0 flex-col divide-y overflow-hidden pt-6 md:pt-16 lg:flex-row lg:divide-x lg:divide-y-0 lg:pt-20 xl:pt-24':+ canSignUp,+ })}+ >+ <div+ className={cn('flex flex-col items-center', {+ 'mb-8 p-4 md:mb-0 md:p-12': canSignUp,+ })}+ >+ <Badge variant="neutral" size="default" className="mb-6 rounded-xl border bg-transparent">+ {truncatedTitle}+ </Badge>++ {/* Card with recipient */}+ <SigningCard3D+ name={recipientName}+ signature={signatures.at(0)}+ signingCelebrationImage={signingCelebration}+ />++ <h2 className="mt-6 max-w-[35ch] text-center text-2xl font-semibold leading-normal md:text-3xl lg:text-4xl">+ Document+ {recipient.role === RecipientRole.SIGNER && ' Signed '}+ {recipient.role === RecipientRole.VIEWER && ' Viewed '}+ {recipient.role === RecipientRole.APPROVER && ' Approved '}+ </h2>++ {match({ status: document.status, deletedAt: document.deletedAt })+ .with({ status: DocumentStatus.COMPLETED }, () => (+ <div className="text-documenso-700 mt-4 flex items-center text-center">+ <CheckCircle2 className="mr-2 h-5 w-5" />+ <span className="text-sm">Everyone has signed</span>+ </div>+ ))+ .with({ deletedAt: null }, () => (+ <div className="flex items-center text-center text-blue-600">+ <Clock8 className="mr-2 h-5 w-5" />+ <span className="text-sm">Waiting for others to sign</span>+ </div>+ ))+ .otherwise(() => (+ <div className="flex items-center text-center text-red-600">+ <Clock8 className="mr-2 h-5 w-5" />+ <span className="text-sm">Document no longer available to sign</span>+ </div>+ ))}++ {match({ status: document.status, deletedAt: document.deletedAt })+ .with({ status: DocumentStatus.COMPLETED }, () => (+ <p className="text-muted-foreground/60 mt-2.5 max-w-[60ch] text-center text-sm font-medium md:text-base">+ Everyone has signed! You will receive an Email copy of the signed document.+ </p>+ ))+ .with({ deletedAt: null }, () => (+ <p className="text-muted-foreground/60 mt-2.5 max-w-[60ch] text-center text-sm font-medium md:text-base">+ You will receive an Email copy of the signed document once everyone has signed.+ </p>+ ))+ .otherwise(() => (+ <p className="text-muted-foreground/60 mt-2.5 max-w-[60ch] text-center text-sm font-medium md:text-base">+ This document has been cancelled by the owner and is no longer available for others+ to sign.+ </p>+ ))}++ <div className="mt-8 flex w-full max-w-sm items-center justify-center gap-4">+ <DocumentShareButton documentId={document.id} token={recipient.token} />++ {document.status === DocumentStatus.COMPLETED ? (+ <DocumentDownloadButton+ className="flex-1"+ fileName={document.title}+ documentData={documentData}+ disabled={document.status !== DocumentStatus.COMPLETED}+ />+ ) : (+ <DocumentPreviewButton+ className="text-[11px]"+ title="Signatures will appear once the document has been completed"+ documentData={documentData}+ />+ )}+ </div></div>- {isLoggedIn ? (+ {canSignUp && (+ <div className={`flex max-w-xl flex-col items-center justify-center p-4 md:p-12`}>+ <h2 className="mt-8 text-center text-xl font-semibold md:mt-0">+ Need to sign documents?+ </h2>++ <p className="text-muted-foreground/60 mt-4 max-w-[55ch] text-center leading-normal">+ Create your account and start using state-of-the-art document signing.+ </p>++ <ClaimAccount defaultName={recipientName} defaultEmail={recipient.email} />+ </div>+ )}++ {isLoggedIn && (<Link href="/documents" className="text-documenso-700 hover:text-documenso-600 mt-36">Go Back Home</Link>- ) : (- <p className="text-muted-foreground/60 mt-36 text-sm">- Want to send slick signing links like this one?{' '}- <Link- href="https://documenso.com"- className="text-documenso-700 hover:text-documenso-600"- >- Check out Documenso.- </Link>- </p>)}</div></div>diff --git a/packages/app-tests/e2e/document-flow/stepper-component.spec.ts b/packages/app-tests/e2e/document-flow/stepper-component.spec.tsindex ee6b160cc..c2ae0618c 100644--- a/packages/app-tests/e2e/document-flow/stepper-component.spec.ts+++ b/packages/app-tests/e2e/document-flow/stepper-component.spec.ts@@ -254,7 +254,7 @@ test('[DOCUMENT_FLOW]: should be able to create, send and sign a document', asynawait page.getByRole('button', { name: 'Sign' }).click();await page.waitForURL(`/sign/${token}/complete`);- await expect(page.getByText('You have signed')).toBeVisible();+ await expect(page.getByText('Document Signed')).toBeVisible();// Check if document has been signedconst { status: completedStatus } = await getDocumentByToken(token);diff --git a/packages/trpc/server/auth-router/router.ts b/packages/trpc/server/auth-router/router.tsindex f9a1795d7..645690905 100644--- a/packages/trpc/server/auth-router/router.ts+++ b/packages/trpc/server/auth-router/router.ts@@ -56,7 +56,7 @@ export const authRouter = router({return user;} catch (err) {- console.log(err);+ console.error(err);const error = AppError.parseError(err);diff --git a/packages/trpc/server/auth-router/schema.ts b/packages/trpc/server/auth-router/schema.tsindex b84c5e1c9..71734d734 100644--- a/packages/trpc/server/auth-router/schema.ts+++ b/packages/trpc/server/auth-router/schema.ts@@ -23,7 +23,7 @@ export const ZSignUpMutationSchema = z.object({name: z.string().min(1),email: z.string().email(),password: ZPasswordSchema,- signature: z.string().min(1, { message: 'A signature is required.' }),+ signature: z.string().nullish(),url: z.string().trim()