Files
documenso/apps/remix/app/utils/field-signing/dropdown-field.ts
T
ephraimduncan 138d663c25 chore: merge main, resolve biome formatting conflicts
Merge origin/main into feat/external-2fa-codes. Resolve formatting
conflicts caused by biome rollout; preserve both feature streams:
PR's external 2FA token + signing-session 2FA proof additions plus
main's RateLimit/RecipientExpired/signingReminders/date-auto-insert.

In complete-document-with-token.ts, drop the duplicate early
field-fetching block introduced when main moved that logic later
with date auto-insert support; keep the EXTERNAL_TWO_FACTOR_AUTH
check using derivedRecipientActionAuth.
2026-05-12 11:46:11 +00:00

48 lines
1.2 KiB
TypeScript

import { AppError, AppErrorCode } from '@documenso/lib/errors/app-error';
import type { TFieldDropdown } from '@documenso/lib/types/field';
import type { TSignEnvelopeFieldValue } from '@documenso/trpc/server/envelope-router/sign-envelope-field.types';
import { FieldType } from '@prisma/client';
import { SignFieldDropdownDialog } from '~/components/dialogs/sign-field-dropdown-dialog';
type HandleDropdownFieldClickOptions = {
field: TFieldDropdown;
text: string | null;
};
export const handleDropdownFieldClick = async (
options: HandleDropdownFieldClickOptions,
): Promise<Extract<TSignEnvelopeFieldValue, { type: typeof FieldType.DROPDOWN }> | null> => {
const { field, text } = options;
if (field.type !== FieldType.DROPDOWN || !field.fieldMeta) {
throw new AppError(AppErrorCode.INVALID_REQUEST, {
message: 'Invalid field type',
});
}
if (field.inserted) {
return {
type: FieldType.DROPDOWN,
value: null,
};
}
let textToInsert = text;
if (!textToInsert) {
textToInsert = await SignFieldDropdownDialog.call({
fieldMeta: field.fieldMeta,
});
}
if (!textToInsert) {
return null;
}
return {
type: FieldType.DROPDOWN,
value: textToInsert,
};
};