diff --git a/apps/web/src/app/(signing)/sign/[token]/checkbox-field.tsx b/apps/web/src/app/(signing)/sign/[token]/checkbox-field.tsx index a0da6d850..a8809a910 100644 --- a/apps/web/src/app/(signing)/sign/[token]/checkbox-field.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/checkbox-field.tsx @@ -1,11 +1,10 @@ 'use client'; -import { useState, useTransition } from 'react'; +import { useCallback, useTransition } from 'react'; import { useRouter } from 'next/navigation'; import { zodResolver } from '@hookform/resolvers/zod'; -import { Loader } from 'lucide-react'; import { useForm } from 'react-hook-form'; import { z } from 'zod'; @@ -49,56 +48,41 @@ export const CheckboxField = ({ field, recipient }: CheckboxFieldProps) => { const isLoading = isSignFieldWithTokenLoading || isRemoveSignedFieldWithTokenLoading || isPending; - const [localText, setLocalCustomText] = useState(''); - const form = useForm>({ resolver: zodResolver(CheckBoxSchema), defaultValues: { - check: true, + check: false, }, }); - const onPreSign = () => { - if (!localText) { - return false; - } + const onSign = useCallback( + async (authOptions?: TRecipientActionAuth) => { + try { + await signFieldWithToken({ + token: recipient.token, + fieldId: field.id, + value: 'checked', + isBase64: true, + authOptions, + }); - return true; - }; + startTransition(() => router.refresh()); + } catch (err) { + const error = AppError.parseError(err); - const onSign = async (authOptions?: TRecipientActionAuth) => { - try { - if (!localText) { - return; + if (error.code === AppErrorCode.UNAUTHORIZED) { + throw error; + } + + toast({ + title: 'Error', + description: 'An error occurred while signing the document.', + variant: 'destructive', + }); } - - await signFieldWithToken({ - token: recipient.token, - fieldId: field.id, - value: localText, - isBase64: true, - authOptions, - }); - - setLocalCustomText(''); - - startTransition(() => router.refresh()); - } catch (err) { - const error = AppError.parseError(err); - - if (error.code === AppErrorCode.UNAUTHORIZED) { - throw error; - } - - console.error(err); - - toast({ - title: 'Error', - description: 'An error occurred while signing the document.', - variant: 'destructive', - }); - } - }; + }, + [field.id, recipient.token, router, signFieldWithToken, toast], + ); const onRemove = async () => { try { @@ -119,52 +103,26 @@ export const CheckboxField = ({ field, recipient }: CheckboxFieldProps) => { } }; - const onSubmit = (data: z.infer) => { - console.log(data); - }; - return ( - {isLoading && ( -
- -
- )} - - {!field.inserted && ( - // TODO: span with a box - //

- // Checkbox - //

- - { - console.log('clicked checkbox'); - }} - onCheckedChange={(checked) => { - setLocalCustomText(checked ? '✓' : '𐄂'); - }} - /> - )} - - {field.inserted &&

{field.customText}

} -
- + ( - + )} /> diff --git a/apps/web/src/app/(signing)/sign/[token]/signing-field-container.tsx b/apps/web/src/app/(signing)/sign/[token]/signing-field-container.tsx index 927c2b77e..9c97ffe43 100644 --- a/apps/web/src/app/(signing)/sign/[token]/signing-field-container.tsx +++ b/apps/web/src/app/(signing)/sign/[token]/signing-field-container.tsx @@ -107,7 +107,7 @@ export const SigningFieldContainer = ({ return ( - {!field.inserted && !loading && ( + {!field.inserted && !loading && !raw && ( )} - - + + {FRIENDLY_FIELD_TYPE[field.type]} + +

{field.signerEmail}

+
+
+ )} + + {isCheckboxField && ( + - {FRIENDLY_FIELD_TYPE[field.type]} - -

{field.signerEmail}

- - + /> + )} , document.body, ); diff --git a/packages/ui/primitives/document-flow/show-field-item.tsx b/packages/ui/primitives/document-flow/show-field-item.tsx index 4e4a0dc99..9cf85024b 100644 --- a/packages/ui/primitives/document-flow/show-field-item.tsx +++ b/packages/ui/primitives/document-flow/show-field-item.tsx @@ -4,9 +4,11 @@ import type { Prisma } from '@prisma/client'; import { createPortal } from 'react-dom'; import { useFieldPageCoords } from '@documenso/lib/client-only/hooks/use-field-page-coords'; +import { FieldType } from '@documenso/prisma/client'; import { cn } from '../../lib/utils'; import { Card, CardContent } from '../card'; +import { Checkbox } from '../checkbox'; import { FRIENDLY_FIELD_TYPE } from './types'; export type ShowFieldItemProps = { @@ -19,6 +21,7 @@ export const ShowFieldItem = ({ field, recipients }: ShowFieldItemProps) => { const signerEmail = recipients.find((recipient) => recipient.id === field.recipientId)?.email ?? ''; + const isCheckboxField = field.type === FieldType.CHECKBOX; return createPortal(
{ width: `${coords.width}px`, }} > - - - {FRIENDLY_FIELD_TYPE[field.type]} + {!isCheckboxField && ( + + + {FRIENDLY_FIELD_TYPE[field.type]} -

- {signerEmail} -

-
-
+

+ {signerEmail} +

+
+
+ )} + + {isCheckboxField && ( + + )}
, document.body, );