From 0b8e84b6b7018412c714654db287575498bd5caf Mon Sep 17 00:00:00 2001 From: Adithya Krishna Date: Fri, 12 Jan 2024 17:13:00 +0530 Subject: [PATCH] refactor: singature pad & provider stuff Signed-off-by: Adithya Krishna --- .../app/(dashboard)/settings/profile/page.tsx | 17 ++++++--- apps/web/src/components/forms/profile.tsx | 8 +++- .../signature-pad/signature-pad.tsx | 37 ++++++++----------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/apps/web/src/app/(dashboard)/settings/profile/page.tsx b/apps/web/src/app/(dashboard)/settings/profile/page.tsx index cb64fb9cd..460b0b8bb 100644 --- a/apps/web/src/app/(dashboard)/settings/profile/page.tsx +++ b/apps/web/src/app/(dashboard)/settings/profile/page.tsx @@ -1,19 +1,24 @@ import { getRequiredServerComponentSession } from '@documenso/lib/next-auth/get-server-component-session'; +import { SigningProvider } from '~/app/(signing)/sign/[token]/provider'; import { ProfileForm } from '~/components/forms/profile'; export default async function ProfileSettingsPage() { const { user } = await getRequiredServerComponentSession(); return ( -
-

Profile

+ +
+

Profile

-

Here you can edit your personal details.

+

+ Here you can edit your personal details. +

-
+
- -
+ +
+ ); } diff --git a/apps/web/src/components/forms/profile.tsx b/apps/web/src/components/forms/profile.tsx index 6f611bed9..c8a3d5505 100644 --- a/apps/web/src/components/forms/profile.tsx +++ b/apps/web/src/components/forms/profile.tsx @@ -7,7 +7,7 @@ import { Loader } from 'lucide-react'; import { Controller, useForm } from 'react-hook-form'; import { z } from 'zod'; -import { User } from '@documenso/prisma/client'; +import type { User } from '@documenso/prisma/client'; import { TRPCClientError } from '@documenso/trpc/client'; import { trpc } from '@documenso/trpc/react'; import { cn } from '@documenso/ui/lib/utils'; @@ -17,6 +17,8 @@ import { Label } from '@documenso/ui/primitives/label'; import { SignaturePad } from '@documenso/ui/primitives/signature-pad'; import { useToast } from '@documenso/ui/primitives/use-toast'; +import { useRequiredSigningContext } from '~/app/(signing)/sign/[token]/provider'; + import { FormErrorMessage } from '../form/form-error-message'; export const ZProfileFormSchema = z.object({ @@ -36,6 +38,8 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => { const { toast } = useToast(); + const { signature, setSignature } = useRequiredSigningContext(); + const { register, control, @@ -121,6 +125,8 @@ export const ProfileForm = ({ className, user }: ProfileFormProps) => { containerClassName="rounded-lg border bg-background" defaultValue={user.signature ?? undefined} onChange={(v) => onChange(v ?? '')} + signature={signature} + setSignature={setSignature} /> )} /> diff --git a/packages/ui/primitives/signature-pad/signature-pad.tsx b/packages/ui/primitives/signature-pad/signature-pad.tsx index 39e70c8a2..cb23b0c3d 100644 --- a/packages/ui/primitives/signature-pad/signature-pad.tsx +++ b/packages/ui/primitives/signature-pad/signature-pad.tsx @@ -9,7 +9,6 @@ import { getStroke } from 'perfect-freehand'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; -import { useRequiredSigningContext } from '../../../../apps/web/src/app/(signing)/sign/[token]/provider'; import { cn } from '../../lib/utils'; import { Input } from '../input'; import { getSvgPathFromStroke } from './helper'; @@ -18,6 +17,8 @@ import { Point } from './point'; const DPI = 2; export type SignaturePadProps = Omit, 'onChange'> & { + signature: string | null; + setSignature: (_value: string | null) => void; onChange?: (_signatureDataUrl: string | null) => void; containerClassName?: string; clearSignatureClassName?: string; @@ -44,6 +45,8 @@ export const SignaturePad = ({ clearSignatureClassName, onFormSubmit, onChange, + signature, + setSignature, ...props }: SignaturePadProps) => { const $el = useRef(null); @@ -51,8 +54,6 @@ export const SignaturePad = ({ const [isPressed, setIsPressed] = useState(false); const [points, setPoints] = useState([]); - const { signature, setSignature } = useRequiredSigningContext(); - const { register, handleSubmit, @@ -68,7 +69,7 @@ export const SignaturePad = ({ resolver: zodResolver(ZSigningpadSchema), }); - const signatureDataUrl = watch('signatureDataUrl'); + // const signatureDataUrl = watch('signatureDataUrl'); const signatureText = watch('signatureText'); const perfectFreehandOptions = useMemo(() => { @@ -248,26 +249,18 @@ export const SignaturePad = ({ return (
undefined))}>
- onMouseMove(event)} - onPointerDown={(event) => onMouseDown(event)} - onPointerUp={(event) => onMouseUp(event)} - onPointerLeave={(event) => onMouseLeave(event)} - onPointerEnter={(event) => onMouseEnter(event)} - {...props} - /> -
{!signatureText && signature && ( - { - setSignature(value); - }} + onMouseMove(event)} + onPointerDown={(event) => onMouseDown(event)} + onPointerUp={(event) => onMouseUp(event)} + onPointerLeave={(event) => onMouseLeave(event)} + onPointerEnter={(event) => onMouseEnter(event)} + {...props} /> )}