Skip to content

The Open Source DocuSign Alternative.

feat(ui): redesign recipient field hover card (#3070)

Ephraim Duncan0099dd672a20
diff --git a/packages/ui/components/document/envelope-recipient-field-tooltip.tsx b/packages/ui/components/document/envelope-recipient-field-tooltip.tsx
index b9a79586e..74c60ed13 100644
--- a/packages/ui/components/document/envelope-recipient-field-tooltip.tsx
+++ b/packages/ui/components/document/envelope-recipient-field-tooltip.tsx
@@ -2,16 +2,27 @@ import { getBoundingClientRect } from '@documenso/lib/client-only/get-bounding-c
import { PDF_VIEWER_PAGE_SELECTOR } from '@documenso/lib/constants/pdf-viewer';
import { Trans, useLingui } from '@lingui/react/macro';
import type { Field, Recipient } from '@prisma/client';
-import { SigningStatus } from '@prisma/client';
-import { ClockIcon, EyeOffIcon, LockIcon } from 'lucide-react';
-import { useCallback, useEffect, useState } from 'react';
+import { FieldType, SigningStatus } from '@prisma/client';
+import {
+ CalendarDaysIcon,
+ CheckSquareIcon,
+ ChevronDownIcon,
+ ContactIcon,
+ DiscIcon,
+ EyeOffIcon,
+ HashIcon,
+ LockIcon,
+ MailIcon,
+ TypeIcon,
+ UserIcon,
+} from 'lucide-react';
+import { type ElementType, useCallback, useEffect, useState } from 'react';
import { isTemplateRecipientEmailPlaceholder } from '../../../lib/constants/template';
import { extractInitials } from '../../../lib/utils/recipient-formatter';
import { SignatureIcon } from '../../icons/signature';
import { cn } from '../../lib/utils';
import { Avatar, AvatarFallback } from '../../primitives/avatar';
-import { Badge } from '../../primitives/badge';
import { FRIENDLY_FIELD_TYPE } from '../../primitives/document-flow/types';
import { PopoverHover } from '../../primitives/popover';
@@ -27,16 +38,18 @@ interface EnvelopeRecipientFieldTooltipProps {
showRecipientColors?: boolean;
}
-const getRecipientDisplayText = (recipient: { name: string; email: string }) => {
- if (recipient.name && !isTemplateRecipientEmailPlaceholder(recipient.email)) {
- return `${recipient.name} (${recipient.email})`;
- }
-
- if (recipient.name && isTemplateRecipientEmailPlaceholder(recipient.email)) {
- return recipient.name;
- }
-
- return recipient.email;
+const FIELD_TYPE_ICONS: Record<FieldType, ElementType> = {
+ [FieldType.SIGNATURE]: SignatureIcon,
+ [FieldType.FREE_SIGNATURE]: SignatureIcon,
+ [FieldType.INITIALS]: ContactIcon,
+ [FieldType.TEXT]: TypeIcon,
+ [FieldType.DATE]: CalendarDaysIcon,
+ [FieldType.EMAIL]: MailIcon,
+ [FieldType.NAME]: UserIcon,
+ [FieldType.NUMBER]: HashIcon,
+ [FieldType.RADIO]: DiscIcon,
+ [FieldType.CHECKBOX]: CheckSquareIcon,
+ [FieldType.DROPDOWN]: ChevronDownIcon,
};
/**
@@ -50,6 +63,8 @@ export function EnvelopeRecipientFieldTooltip({
}: EnvelopeRecipientFieldTooltipProps) {
const { t } = useLingui();
+ const FieldIcon = FIELD_TYPE_ICONS[field.type];
+
const [hideField, setHideField] = useState<boolean>(!showRecipientTooltip);
const [coords, setCoords] = useState({
@@ -138,54 +153,64 @@ export function EnvelopeRecipientFieldTooltip({
</Avatar>
}
contentProps={{
- className: 'relative flex mb-4 w-fit flex-col p-4 text-sm',
+ className: 'flex w-64 flex-col overflow-hidden p-0 text-sm',
+ sideOffset: 20,
+ onOpenAutoFocus: (event) => event.preventDefault(),
}}
>
- {showFieldStatus && (
- <Badge
- className="mx-auto mb-1 py-0.5"
- variant={
- field?.fieldMeta?.readOnly
- ? 'neutral'
- : field.recipient.signingStatus === SigningStatus.SIGNED
- ? 'default'
- : 'secondary'
- }
- >
- {field?.fieldMeta?.readOnly ? (
- <>
- <LockIcon className="mr-1 h-3 w-3" />
- <Trans>Read Only</Trans>
- </>
- ) : field.recipient.signingStatus === SigningStatus.SIGNED ? (
- <>
- <SignatureIcon className="mr-1 h-3 w-3" />
- <Trans>Signed</Trans>
- </>
- ) : (
- <>
- <ClockIcon className="mr-1 h-3 w-3" />
- <Trans>Pending</Trans>
- </>
- )}
- </Badge>
- )}
+ <div className="flex items-center gap-2 p-3">
+ <FieldIcon className="h-4 w-4 shrink-0 text-muted-foreground" />
- <p className="text-center font-semibold">
- <span>
+ <p className="min-w-0 flex-1 truncate font-medium">
<Trans>{t(FRIENDLY_FIELD_TYPE[field.type])} field</Trans>
- </span>
- </p>
-
- <p className="mt-1 text-center text-muted-foreground text-xs">{getRecipientDisplayText(field.recipient)}</p>
-
- <button
- className="absolute top-0 right-0 my-1 p-2 focus:outline-none focus-visible:ring-0"
- onClick={() => setHideField(true)}
- title="Hide field"
- >
- <EyeOffIcon className="h-3 w-3" />
- </button>
+ </p>
+
+ {showFieldStatus && (
+ <div className="flex shrink-0 items-center gap-1.5 text-xs">
+ {field?.fieldMeta?.readOnly ? (
+ <>
+ <LockIcon className="h-3 w-3 text-muted-foreground" />
+ <span className="text-muted-foreground">
+ <Trans>Read Only</Trans>
+ </span>
+ </>
+ ) : field.recipient.signingStatus === SigningStatus.SIGNED ? (
+ <>
+ <span className="h-1.5 w-1.5 rounded-full bg-green-500" />
+ <span className="text-green-600 dark:text-green-400">
+ <Trans>Signed</Trans>
+ </span>
+ </>
+ ) : (
+ <>
+ <span className="h-1.5 w-1.5 rounded-full bg-amber-400" />
+ <span className="text-amber-600 dark:text-amber-400">
+ <Trans>Pending</Trans>
+ </span>
+ </>
+ )}
+ </div>
+ )}
+ </div>
+
+ <div className="flex items-center gap-3 border-border/50 border-t bg-muted/50 px-3 py-2.5">
+ <div className="min-w-0 flex-1">
+ <p className="truncate font-medium text-xs">{field.recipient.name || field.recipient.email}</p>
+
+ {!isTemplateRecipientEmailPlaceholder(field.recipient.email) && field.recipient.name && (
+ <p className="truncate text-muted-foreground text-xs">{field.recipient.email}</p>
+ )}
+ </div>
+
+ <button
+ type="button"
+ className="-m-1 shrink-0 rounded-sm p-1 text-muted-foreground hover:bg-background hover:text-foreground"
+ onClick={() => setHideField(true)}
+ title={t`Hide field`}
+ >
+ <EyeOffIcon className="h-3.5 w-3.5" />
+ </button>
+ </div>
</PopoverHover>
</div>
);