fix: checkbox error
This commit is contained in:
@@ -106,6 +106,7 @@ export const DirectTemplateConfigureForm = ({
|
|||||||
directTemplateRecipient.fields,
|
directTemplateRecipient.fields,
|
||||||
recipientsWithBlankDirectRecipientEmail,
|
recipientsWithBlankDirectRecipientEmail,
|
||||||
)}
|
)}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -97,6 +97,11 @@ export const DocumentSigningCheckboxField = ({
|
|||||||
|
|
||||||
const onSign = async (authOptions?: TRecipientActionAuth) => {
|
const onSign = async (authOptions?: TRecipientActionAuth) => {
|
||||||
try {
|
try {
|
||||||
|
// Do nothing, since the user clicked on a non checkbox area.
|
||||||
|
if (checkedValues.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const payload: TSignFieldWithTokenMutationSchema = {
|
const payload: TSignFieldWithTokenMutationSchema = {
|
||||||
token: recipient.token,
|
token: recipient.token,
|
||||||
fieldId: field.id,
|
fieldId: field.id,
|
||||||
|
|||||||
@@ -206,6 +206,7 @@ export default function DocumentPage() {
|
|||||||
documentMeta={documentMeta || undefined}
|
documentMeta={documentMeta || undefined}
|
||||||
showRecipientTooltip={true}
|
showRecipientTooltip={true}
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
|||||||
@@ -153,6 +153,7 @@ export default function TemplatePage() {
|
|||||||
showFieldStatus={false}
|
showFieldStatus={false}
|
||||||
showRecipientTooltip={true}
|
showRecipientTooltip={true}
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
documentMeta={mockedDocumentMeta}
|
documentMeta={mockedDocumentMeta}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { useMemo, useState } from 'react';
|
import { useState } from 'react';
|
||||||
|
|
||||||
import { useLingui } from '@lingui/react';
|
import { useLingui } from '@lingui/react';
|
||||||
import { Trans } from '@lingui/react/macro';
|
import { Trans } from '@lingui/react/macro';
|
||||||
@@ -18,7 +18,7 @@ import { FRIENDLY_FIELD_TYPE } from '@documenso/ui/primitives/document-flow/type
|
|||||||
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
import { ElementVisible } from '@documenso/ui/primitives/element-visible';
|
||||||
import { PopoverHover } from '@documenso/ui/primitives/popover';
|
import { PopoverHover } from '@documenso/ui/primitives/popover';
|
||||||
|
|
||||||
import { buildRecipientsColorMap } from '../../lib/recipient-colors';
|
import { getRecipientColorStyles } from '../../lib/recipient-colors';
|
||||||
import { FieldContent } from '../../primitives/document-flow/field-content';
|
import { FieldContent } from '../../primitives/document-flow/field-content';
|
||||||
|
|
||||||
export type DocumentReadOnlyFieldsProps = {
|
export type DocumentReadOnlyFieldsProps = {
|
||||||
@@ -27,6 +27,14 @@ export type DocumentReadOnlyFieldsProps = {
|
|||||||
|
|
||||||
showFieldStatus?: boolean;
|
showFieldStatus?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Required if you want to show colors.
|
||||||
|
*
|
||||||
|
* Can't derive this from the fields because sometimes recipients don't have fields
|
||||||
|
* yet.
|
||||||
|
*/
|
||||||
|
recipientIds?: number[];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to show the recipient tooltip.
|
* Whether to show the recipient tooltip.
|
||||||
*
|
*
|
||||||
@@ -61,6 +69,7 @@ export const mapFieldsWithRecipients = (
|
|||||||
export const DocumentReadOnlyFields = ({
|
export const DocumentReadOnlyFields = ({
|
||||||
documentMeta,
|
documentMeta,
|
||||||
fields,
|
fields,
|
||||||
|
recipientIds = [],
|
||||||
showFieldStatus = true,
|
showFieldStatus = true,
|
||||||
showRecipientTooltip = false,
|
showRecipientTooltip = false,
|
||||||
showRecipientColors = false,
|
showRecipientColors = false,
|
||||||
@@ -73,17 +82,6 @@ export const DocumentReadOnlyFields = ({
|
|||||||
setHiddenFieldIds((prev) => ({ ...prev, [fieldId]: true }));
|
setHiddenFieldIds((prev) => ({ ...prev, [fieldId]: true }));
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a map of recipient IDs to their color styles.
|
|
||||||
*/
|
|
||||||
const recipientColors = useMemo(() => {
|
|
||||||
if (!showRecipientColors) {
|
|
||||||
return {};
|
|
||||||
}
|
|
||||||
|
|
||||||
return buildRecipientsColorMap(fields);
|
|
||||||
}, [fields, showRecipientColors]);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ElementVisible target={PDF_VIEWER_PAGE_SELECTOR}>
|
<ElementVisible target={PDF_VIEWER_PAGE_SELECTOR}>
|
||||||
{fields.map(
|
{fields.map(
|
||||||
@@ -92,7 +90,16 @@ export const DocumentReadOnlyFields = ({
|
|||||||
<FieldRootContainer
|
<FieldRootContainer
|
||||||
field={field}
|
field={field}
|
||||||
key={field.id}
|
key={field.id}
|
||||||
color={recipientColors[field.recipientId]}
|
color={
|
||||||
|
showRecipientColors
|
||||||
|
? getRecipientColorStyles(
|
||||||
|
Math.max(
|
||||||
|
recipientIds.findIndex((id) => id === field.recipientId),
|
||||||
|
0,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: undefined
|
||||||
|
}
|
||||||
>
|
>
|
||||||
{showRecipientTooltip && (
|
{showRecipientTooltip && (
|
||||||
<div className="absolute -right-3 -top-3">
|
<div className="absolute -right-3 -top-3">
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
// !: therefore doing this at runtime is not possible without whitelisting a set of classnames.
|
// !: therefore doing this at runtime is not possible without whitelisting a set of classnames.
|
||||||
// !:
|
// !:
|
||||||
// !: This will later be improved as we move to a CSS variable approach and rotate the lightness
|
// !: This will later be improved as we move to a CSS variable approach and rotate the lightness
|
||||||
import type { DocumentField } from '@documenso/lib/server-only/field/get-fields-for-document';
|
|
||||||
|
export type RecipientColorMap = Record<number, RecipientColorStyles>;
|
||||||
|
|
||||||
export type RecipientColorStyles = {
|
export type RecipientColorStyles = {
|
||||||
base: string;
|
base: string;
|
||||||
@@ -92,20 +93,3 @@ export const getRecipientColorStyles = (index: number) => {
|
|||||||
// eslint-disable-next-line react-hooks/rules-of-hooks
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
||||||
return useRecipientColors(index);
|
return useRecipientColors(index);
|
||||||
};
|
};
|
||||||
|
|
||||||
export type RecipientColorMap = Record<number, RecipientColorStyles>;
|
|
||||||
|
|
||||||
export const buildRecipientsColorMap = (fields: DocumentField[]): RecipientColorMap => {
|
|
||||||
// Unique recipient IDs sorted from lowest to highest.
|
|
||||||
const recipientIds = [...new Set(fields.map((field) => field.recipientId))].sort();
|
|
||||||
|
|
||||||
return recipientIds.reduce(
|
|
||||||
(acc, recipientId, index) => {
|
|
||||||
acc[recipientId] = getRecipientColorStyles(index);
|
|
||||||
|
|
||||||
return acc;
|
|
||||||
},
|
|
||||||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions
|
|
||||||
{} as RecipientColorMap,
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -151,6 +151,7 @@ export const AddSettingsFormPartial = ({
|
|||||||
{isDocumentPdfLoaded && (
|
{isDocumentPdfLoaded && (
|
||||||
<DocumentReadOnlyFields
|
<DocumentReadOnlyFields
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
fields={mapFieldsWithRecipients(fields, recipients)}
|
fields={mapFieldsWithRecipients(fields, recipients)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -367,6 +367,7 @@ export const AddSignersFormPartial = ({
|
|||||||
{isDocumentPdfLoaded && (
|
{isDocumentPdfLoaded && (
|
||||||
<DocumentReadOnlyFields
|
<DocumentReadOnlyFields
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
fields={mapFieldsWithRecipients(fields, recipients)}
|
fields={mapFieldsWithRecipients(fields, recipients)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -107,6 +107,7 @@ export const AddSubjectFormPartial = ({
|
|||||||
{isDocumentPdfLoaded && (
|
{isDocumentPdfLoaded && (
|
||||||
<DocumentReadOnlyFields
|
<DocumentReadOnlyFields
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
fields={mapFieldsWithRecipients(fields, recipients)}
|
fields={mapFieldsWithRecipients(fields, recipients)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -392,6 +392,7 @@ export const AddTemplatePlaceholderRecipientsFormPartial = ({
|
|||||||
{isDocumentPdfLoaded && (
|
{isDocumentPdfLoaded && (
|
||||||
<DocumentReadOnlyFields
|
<DocumentReadOnlyFields
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
fields={mapFieldsWithRecipients(fields, recipients)}
|
fields={mapFieldsWithRecipients(fields, recipients)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ export const AddTemplateSettingsFormPartial = ({
|
|||||||
{isDocumentPdfLoaded && (
|
{isDocumentPdfLoaded && (
|
||||||
<DocumentReadOnlyFields
|
<DocumentReadOnlyFields
|
||||||
showRecipientColors={true}
|
showRecipientColors={true}
|
||||||
|
recipientIds={recipients.map((recipient) => recipient.id)}
|
||||||
fields={mapFieldsWithRecipients(fields, recipients)}
|
fields={mapFieldsWithRecipients(fields, recipients)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user