2025-01-02 15:33:37 +11:00
|
|
|
import { msg } from '@lingui/core/macro';
|
2024-08-27 20:34:39 +09:00
|
|
|
import { useLingui } from '@lingui/react';
|
2025-01-02 15:33:37 +11:00
|
|
|
import type { Recipient } from '@prisma/client';
|
|
|
|
|
import { DocumentStatus } from '@prisma/client';
|
2024-08-27 20:34:39 +09:00
|
|
|
|
2023-11-17 05:12:47 +00:00
|
|
|
import { useCopyToClipboard } from '@documenso/lib/client-only/hooks/use-copy-to-clipboard';
|
|
|
|
|
import { getRecipientType } from '@documenso/lib/client-only/recipient-type';
|
2024-01-31 22:32:42 +11:00
|
|
|
import { NEXT_PUBLIC_WEBAPP_URL } from '@documenso/lib/constants/app';
|
2024-02-01 18:45:02 -05:00
|
|
|
import { RECIPIENT_ROLES_DESCRIPTION } from '@documenso/lib/constants/recipient-roles';
|
2023-11-17 05:12:47 +00:00
|
|
|
import { recipientAbbreviation } from '@documenso/lib/utils/recipient-formatter';
|
2024-01-20 01:14:34 +00:00
|
|
|
import { cn } from '@documenso/ui/lib/utils';
|
2023-11-17 05:12:47 +00:00
|
|
|
import { useToast } from '@documenso/ui/primitives/use-toast';
|
|
|
|
|
|
|
|
|
|
import { StackAvatar } from './stack-avatar';
|
|
|
|
|
|
|
|
|
|
export type AvatarWithRecipientProps = {
|
|
|
|
|
recipient: Recipient;
|
2024-04-19 16:17:32 +07:00
|
|
|
documentStatus: DocumentStatus;
|
2023-11-17 05:12:47 +00:00
|
|
|
};
|
|
|
|
|
|
2024-04-19 16:17:32 +07:00
|
|
|
export function AvatarWithRecipient({ recipient, documentStatus }: AvatarWithRecipientProps) {
|
2023-11-17 05:12:47 +00:00
|
|
|
const [, copy] = useCopyToClipboard();
|
2024-08-27 20:34:39 +09:00
|
|
|
|
|
|
|
|
const { _ } = useLingui();
|
2023-11-17 05:12:47 +00:00
|
|
|
const { toast } = useToast();
|
|
|
|
|
|
2024-04-19 16:17:32 +07:00
|
|
|
const signingToken = documentStatus === DocumentStatus.PENDING ? recipient.token : null;
|
|
|
|
|
|
2023-11-17 05:12:47 +00:00
|
|
|
const onRecipientClick = () => {
|
2024-04-19 16:17:32 +07:00
|
|
|
if (!signingToken) {
|
2024-01-20 01:14:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-19 16:17:32 +07:00
|
|
|
void copy(`${NEXT_PUBLIC_WEBAPP_URL()}/sign/${signingToken}`).then(() => {
|
2023-11-17 05:12:47 +00:00
|
|
|
toast({
|
2024-08-27 20:34:39 +09:00
|
|
|
title: _(msg`Copied to clipboard`),
|
|
|
|
|
description: _(msg`The signing link has been copied to your clipboard.`),
|
2023-11-17 05:12:47 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
2024-01-20 01:14:34 +00:00
|
|
|
<div
|
|
|
|
|
className={cn('my-1 flex items-center gap-2', {
|
2024-04-19 16:17:32 +07:00
|
|
|
'cursor-pointer hover:underline': signingToken,
|
2024-01-20 01:14:34 +00:00
|
|
|
})}
|
2024-04-19 16:17:32 +07:00
|
|
|
role={signingToken ? 'button' : undefined}
|
2024-08-27 20:34:39 +09:00
|
|
|
title={signingToken ? _(msg`Click to copy signing link for sending to recipient`) : undefined}
|
2024-01-20 01:14:34 +00:00
|
|
|
onClick={onRecipientClick}
|
|
|
|
|
>
|
2023-11-17 05:12:47 +00:00
|
|
|
<StackAvatar
|
|
|
|
|
first={true}
|
|
|
|
|
key={recipient.id}
|
|
|
|
|
type={getRecipientType(recipient)}
|
|
|
|
|
fallbackText={recipientAbbreviation(recipient)}
|
|
|
|
|
/>
|
2024-04-19 16:17:32 +07:00
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
className="text-muted-foreground text-sm"
|
2024-08-27 20:34:39 +09:00
|
|
|
title={
|
|
|
|
|
signingToken ? _(msg`Click to copy signing link for sending to recipient`) : undefined
|
|
|
|
|
}
|
2024-04-19 16:17:32 +07:00
|
|
|
>
|
|
|
|
|
<p>{recipient.email}</p>
|
|
|
|
|
<p className="text-muted-foreground/70 text-xs">
|
2024-08-27 20:34:39 +09:00
|
|
|
{_(RECIPIENT_ROLES_DESCRIPTION[recipient.role].roleName)}
|
2024-04-19 16:17:32 +07:00
|
|
|
</p>
|
2024-02-01 18:45:02 -05:00
|
|
|
</div>
|
2023-11-17 05:12:47 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|