mirror of
https://github.com/documenso/documenso.git
synced 2025-11-19 19:21:39 +10:00
feat: some refactoring
This commit is contained in:
@ -6,6 +6,7 @@ import { useRouter } from 'next/navigation';
|
||||
|
||||
import { Loader } from 'lucide-react';
|
||||
|
||||
import { useDebouncedValue } from '@documenso/lib/client-only/hooks/use-debounced-value';
|
||||
import { DO_NOT_INVALIDATE_QUERY_ON_MUTATION } from '@documenso/lib/constants/trpc';
|
||||
import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
|
||||
import type { TRecipientActionAuth } from '@documenso/lib/types/document-auth';
|
||||
@ -42,6 +43,8 @@ export const InitialsField = ({
|
||||
const { fullName } = useRequiredSigningContext();
|
||||
const initials = extractInitials(fullName);
|
||||
|
||||
const debouncedTerm = useDebouncedValue(initials, 5000);
|
||||
|
||||
const [isPending, startTransition] = useTransition();
|
||||
|
||||
const { executeActionAuthProcedure } = useRequiredDocumentAuthContext();
|
||||
@ -58,7 +61,7 @@ export const InitialsField = ({
|
||||
|
||||
const onSign = async (authOptions?: TRecipientActionAuth) => {
|
||||
try {
|
||||
const value = initials ?? '';
|
||||
const value = debouncedTerm ?? '';
|
||||
|
||||
const payload: TSignFieldWithTokenMutationSchema = {
|
||||
token: recipient.token,
|
||||
@ -126,7 +129,7 @@ export const InitialsField = ({
|
||||
actionTarget: field.type,
|
||||
});
|
||||
}
|
||||
}, [field]);
|
||||
}, [field, debouncedTerm]);
|
||||
|
||||
return (
|
||||
<SigningFieldContainer field={field} onSign={onSign} onRemove={onRemove} type="Initials">
|
||||
|
||||
@ -67,7 +67,7 @@ export const SigningFieldContainer = ({
|
||||
const parsedFieldMeta = field.fieldMeta ? ZFieldMetaSchema.parse(field.fieldMeta) : undefined;
|
||||
const readOnlyField = parsedFieldMeta?.readOnly || false;
|
||||
|
||||
const automatedFields = ['Initials', 'Email', 'Name', 'Date'].includes(type ?? '');
|
||||
const automatedFields = ['Email', 'Date'].includes(type ?? '');
|
||||
|
||||
const handleInsertField = async () => {
|
||||
if (field.inserted || !onSign) {
|
||||
@ -147,7 +147,7 @@ export const SigningFieldContainer = ({
|
||||
</button>
|
||||
)}
|
||||
|
||||
{type === 'Date' && field.inserted && !loading && !readOnlyField && (
|
||||
{field.inserted && !automatedFields && !loading && !readOnlyField && (
|
||||
<Tooltip delayDuration={0}>
|
||||
<TooltipTrigger asChild>
|
||||
<button
|
||||
@ -173,14 +173,18 @@ export const SigningFieldContainer = ({
|
||||
</button>
|
||||
)}
|
||||
|
||||
{type !== 'Checkbox' && field.inserted && !loading && !readOnlyField && (
|
||||
<button
|
||||
className="text-destructive bg-background/50 absolute inset-0 z-10 flex h-full w-full items-center justify-center rounded-md text-sm opacity-0 duration-200 group-hover:opacity-100"
|
||||
onClick={onRemoveSignedFieldClick}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
)}
|
||||
{type !== 'Checkbox' &&
|
||||
!automatedFields &&
|
||||
field.inserted &&
|
||||
!loading &&
|
||||
!readOnlyField && (
|
||||
<button
|
||||
className="text-destructive bg-background/50 absolute inset-0 z-10 flex h-full w-full items-center justify-center rounded-md text-sm opacity-0 duration-200 group-hover:opacity-100"
|
||||
onClick={onRemoveSignedFieldClick}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
)}
|
||||
|
||||
{children}
|
||||
</FieldRootContainer>
|
||||
|
||||
Reference in New Issue
Block a user