2024-11-01 08:57:32 +09:00
|
|
|
import { useLingui } from '@lingui/react';
|
2025-01-02 15:33:37 +11:00
|
|
|
import { FieldType, type Prisma } from '@prisma/client';
|
2024-01-29 00:47:11 +00:00
|
|
|
import { createPortal } from 'react-dom';
|
|
|
|
|
|
2024-02-01 01:10:50 +00:00
|
|
|
import { useFieldPageCoords } from '@documenso/lib/client-only/hooks/use-field-page-coords';
|
2024-11-01 08:57:32 +09:00
|
|
|
import { parseMessageDescriptor } from '@documenso/lib/utils/i18n';
|
2024-01-29 00:47:11 +00:00
|
|
|
|
|
|
|
|
import { cn } from '../../lib/utils';
|
|
|
|
|
import { Card, CardContent } from '../card';
|
|
|
|
|
import { FRIENDLY_FIELD_TYPE } from './types';
|
|
|
|
|
|
2024-01-30 00:09:22 +00:00
|
|
|
export type ShowFieldItemProps = {
|
2024-01-29 00:59:08 +00:00
|
|
|
field: Prisma.FieldGetPayload<null>;
|
2024-01-29 00:47:11 +00:00
|
|
|
recipients: Prisma.RecipientGetPayload<null>[];
|
|
|
|
|
};
|
|
|
|
|
|
2025-01-02 15:33:37 +11:00
|
|
|
export const ShowFieldItem = ({ field }: ShowFieldItemProps) => {
|
2024-11-01 08:57:32 +09:00
|
|
|
const { _ } = useLingui();
|
|
|
|
|
|
2024-02-01 01:10:50 +00:00
|
|
|
const coords = useFieldPageCoords(field);
|
2024-01-29 00:47:11 +00:00
|
|
|
|
|
|
|
|
return createPortal(
|
2024-02-01 01:10:50 +00:00
|
|
|
<div
|
|
|
|
|
className={cn('pointer-events-none absolute z-10 opacity-75')}
|
|
|
|
|
style={{
|
|
|
|
|
top: `${coords.y}px`,
|
|
|
|
|
left: `${coords.x}px`,
|
|
|
|
|
height: `${coords.height}px`,
|
|
|
|
|
width: `${coords.width}px`,
|
2024-01-29 00:47:11 +00:00
|
|
|
}}
|
|
|
|
|
>
|
2024-11-20 22:49:30 +11:00
|
|
|
<Card className={cn('bg-background h-full w-full [container-type:size]')}>
|
2024-01-29 00:47:11 +00:00
|
|
|
<CardContent
|
|
|
|
|
className={cn(
|
2024-11-20 22:49:30 +11:00
|
|
|
'text-muted-foreground/50 flex h-full w-full flex-col items-center justify-center p-0 text-[clamp(0.575rem,1.8cqw,1.2rem)] leading-none',
|
2025-01-02 15:33:37 +11:00
|
|
|
field.type === FieldType.SIGNATURE && 'font-signature',
|
2024-01-29 00:47:11 +00:00
|
|
|
)}
|
|
|
|
|
>
|
2024-11-01 08:57:32 +09:00
|
|
|
{parseMessageDescriptor(_, FRIENDLY_FIELD_TYPE[field.type])}
|
2024-01-29 00:47:11 +00:00
|
|
|
|
2024-11-20 22:49:30 +11:00
|
|
|
{/* <p className="text-muted-foreground/50 w-full truncate text-center text-xs">
|
2024-01-29 00:47:11 +00:00
|
|
|
{signerEmail}
|
2024-11-20 22:49:30 +11:00
|
|
|
</p> */}
|
2024-01-29 00:47:11 +00:00
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
2024-02-01 01:10:50 +00:00
|
|
|
</div>,
|
2024-01-29 00:47:11 +00:00
|
|
|
document.body,
|
|
|
|
|
);
|
|
|
|
|
};
|