Repository navigation
feat: add signing link copy - #1449
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
5 Skipped Deployments
|
WalkthroughThe changes in this pull request introduce several enhancements across multiple components related to document management. A new Changes
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 4
🧹 Outside diff range and nitpick comments (11)
packages/lib/utils/recipients.ts (1)
3-5: Add input validation and type safety to formatSigningLink.While the implementation is straightforward, consider adding these safety measures:
- Type validation for the token parameter
- URL path sanitization to handle potential trailing slashes
Consider this improved implementation:
-export const formatSigningLink = (token: string) => `${NEXT_PUBLIC_WEBAPP_URL()}/sign/${token}`; +export const formatSigningLink = (token: string): string => { + if (!token) { + throw new Error('Token is required for signing link generation'); + } + const baseUrl = NEXT_PUBLIC_WEBAPP_URL().replace(/\/+$/, ''); + return `${baseUrl}/sign/${encodeURIComponent(token)}`; +};packages/ui/components/common/copy-text-button.tsx (2)
1-19: Consider adding validation for empty values.The props interface is well-defined, but the
valueprop could benefit from runtime validation to handle empty strings gracefully.Consider adding a check in the component:
export const CopyTextButton = ({ value, onCopySuccess, badgeContentUncopied, badgeContentCopied, }: CopyTextButtonProps) => { + if (!value?.trim()) { + console.warn('CopyTextButton: Empty or whitespace-only value provided'); + }
21-82: Consider performance optimizations.The component could benefit from memoization and proper cleanup handling.
Consider these architectural improvements:
- Memoize the component for better performance:
export const CopyTextButton = memo(({...props}: CopyTextButtonProps) => { // Component implementation });
- Move timeout cleanup to useEffect:
useEffect(() => { return () => { if (copiedTimeout) { clearTimeout(copiedTimeout); } }; }, [copiedTimeout]);apps/web/src/components/document/document-recipient-link-copy-dialog.tsx (3)
37-52: Consider adding type safety for search params.While the implementation is correct, consider adding type safety for the search params to prevent potential runtime issues.
- const actionSearchParam = searchParams?.get('action'); + type ValidActions = 'view-signing-links' | null; + const actionSearchParam = searchParams?.get('action') as ValidActions;
67-72: Optimize useEffect dependencies.The current effect setup might cause unnecessary re-renders since
openandsetOpenare included in the dependency array.useEffect(() => { if (actionSearchParam === 'view-signing-links') { setOpen(true); updateSearchParams({ action: null }); } - }, [actionSearchParam, open, setOpen, updateSearchParams]); + }, [actionSearchParam, updateSearchParams]);
74-151: Consider adding loading states and list virtualization.The component could benefit from the following improvements:
- Loading states during clipboard operations
- List virtualization for better performance with large recipient lists
Consider using a virtualized list component like
react-windoworreact-virtualizedwhen dealing with large lists of recipients. This would improve performance by only rendering visible items.Also, consider adding loading states during clipboard operations:
const [open, setOpen] = useState(false); + const [isLoading, setIsLoading] = useState(false); const onBulkCopy = async () => { + setIsLoading(true); try { // ... existing copy logic } catch (error) { // ... error handling + } finally { + setIsLoading(false); } }; // In the button JSX: - <Button type="button" onClick={onBulkCopy}> + <Button type="button" onClick={onBulkCopy} disabled={isLoading}> <Trans>Bulk Copy</Trans> </Button>apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recipients.tsx (1)
77-116: Consider extracting badge rendering logic into a separate component.The badge rendering logic using pattern matching is comprehensive but could be more maintainable if extracted into a dedicated component.
Consider creating a new component like this:
type RecipientBadgeProps = { role: RecipientRole; documentStatus: DocumentStatus; }; const RecipientBadge = ({ role, documentStatus }: RecipientBadgeProps) => { return ( <Badge variant="default"> {match(role) .with(RecipientRole.APPROVER, () => ( <> <CheckIcon className="mr-1 h-3 w-3" /> <Trans>Approved</Trans> </> )) // ... other cases .exhaustive()} </Badge> ); };This would simplify the main component and make the badge logic more reusable and testable.
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-dropdown.tsx (2)
151-164: Add documentation for event handling.Consider adding a comment explaining why
preventDefault()is used in theonSelecthandler, as this might not be immediately obvious to other developers.<DropdownMenuItem disabled={!isPending || isDeleted} + // Prevent closing the dropdown when selecting this item onSelect={(e) => e.preventDefault()} >
155-158: Consider extracting the disabled condition.The disabled state combines multiple conditions. Consider extracting this into a descriptive constant for better maintainability and readability.
+ const isSigningLinksDisabled = !isPending || isDeleted; <DropdownMenuItem - disabled={!isPending || isDeleted} + disabled={isSigningLinksDisabled} onSelect={(e) => e.preventDefault()} >apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (1)
196-208: Consider accessibility and performance improvements.While the implementation is functional, consider the following improvements:
- Accessibility: Replace the
divwith abuttonorspaninside theDropdownMenuItemfor better semantic structure.- Performance: Consider passing only necessary recipient data instead of the full array.
Here's a suggested improvement:
<DocumentRecipientLinkCopyDialog - recipients={row.Recipient} + recipients={row.Recipient.map(({ id, email, name, token }) => ({ + id, + email, + name, + token, + }))} trigger={ <DropdownMenuItem disabled={!isPending} asChild onSelect={(e) => e.preventDefault()}> - <div> + <span> <Copy className="mr-2 h-4 w-4" /> <Trans>Signing Links</Trans> - </div> + </span> </DropdownMenuItem> } />apps/web/src/app/(dashboard)/documents/[id]/document-page-view.tsx (1)
138-140: Consider enhancing dialog control and positioning.While the implementation is clean, consider the following improvements:
- Add a controlled state for the dialog to manage its visibility from this component
- Consider passing additional props for positioning context, especially since this dialog appears at the page level
- {document.status === DocumentStatus.PENDING && ( - <DocumentRecipientLinkCopyDialog recipients={recipients} /> - )} + {document.status === DocumentStatus.PENDING && ( + <DocumentRecipientLinkCopyDialog + recipients={recipients} + position="top-right" + onOpenChange={(open) => { + // Handle dialog state + }} + /> + )}
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (7)
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-dropdown.tsx(3 hunks)apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recipients.tsx(4 hunks)apps/web/src/app/(dashboard)/documents/[id]/document-page-view.tsx(2 hunks)apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx(3 hunks)apps/web/src/components/document/document-recipient-link-copy-dialog.tsx(1 hunks)packages/lib/utils/recipients.ts(1 hunks)packages/ui/components/common/copy-text-button.tsx(1 hunks)
🔇 Additional comments (12)
packages/lib/utils/recipients.ts (1)
5-5: LGTM! Well-integrated with existing functionality.
The new formatSigningLink function is appropriately placed in this utility module and maintains good separation of concerns with the existing recipient-related functions.
apps/web/src/components/document/document-recipient-link-copy-dialog.tsx (1)
1-35: LGTM! Well-structured imports and type definitions.
The component follows TypeScript best practices with proper type definitions and necessary imports.
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-recipients.tsx (4)
Line range hint 1-31: LGTM! Clean import organization and component setup.
The new imports are properly organized and necessary for the enhanced functionality.
32-33: LGTM! Proper hook initialization.
The toast hook is correctly initialized at the component level following React hooks best practices.
118-124: LGTM! Clear status indication for pending recipients.
The pending status badge provides clear visual feedback with appropriate iconography.
Line range hint 1-139: Implementation aligns well with PR objectives.
The changes successfully enhance the signing link functionality by:
- Adding copy capability for relevant recipients
- Providing clear user feedback through toast notifications
- Maintaining proper access controls based on document and recipient status
apps/web/src/app/(dashboard)/documents/[id]/document-page-view-dropdown.tsx (2)
36-37: LGTM: Clean import statement.
The import follows the project's conventions and is properly organized.
67-67: LGTM: Clear and consistent state tracking.
The isPending constant follows the existing pattern of status checks and is well-named.
apps/web/src/app/(dashboard)/documents/data-table-action-dropdown.tsx (3)
40-41: LGTM: Import statement follows project conventions.
The import of DocumentRecipientLinkCopyDialog aligns with the PR objective and follows the project's module resolution pattern.
74-74: LGTM: Status variable follows existing patterns.
The isPending variable is well-placed among other status checks and correctly uses the DocumentStatus enum.
196-209: LGTM: Well-integrated within the Share section.
The new signing links feature is logically placed in the Share section and follows the established patterns for conditional rendering and user permissions.
apps/web/src/app/(dashboard)/documents/[id]/document-page-view.tsx (1)
29-29: LGTM!
The import statement is clean and follows the existing import organization pattern.
| return ( | ||
| <Button | ||
| type="button" | ||
| variant="none" | ||
| className="ml-2 h-7 rounded border bg-neutral-50 px-0.5 font-normal dark:border dark:border-neutral-500 dark:bg-neutral-600" | ||
| onClick={async () => onCopy()} | ||
| > | ||
| <AnimatePresence mode="wait" initial={false}> | ||
| <motion.div | ||
| className="flex flex-row items-center" | ||
| key={copiedTimeout ? 'copied' : 'copy'} | ||
| initial={{ opacity: 0 }} | ||
| animate={{ opacity: 1 }} | ||
| exit={{ opacity: 0, transition: { duration: 0.1 } }} | ||
| > | ||
| {copiedTimeout ? badgeContentCopied : badgeContentUncopied} | ||
|
|
||
| <div | ||
| className={cn( | ||
| 'flex h-6 w-6 items-center justify-center rounded transition-all hover:bg-neutral-200 hover:active:bg-neutral-300 dark:hover:bg-neutral-500 dark:hover:active:bg-neutral-400', | ||
| { | ||
| 'ml-1': Boolean(badgeContentCopied || badgeContentUncopied), | ||
| }, | ||
| )} | ||
| > | ||
| <div className="absolute"> | ||
| {copiedTimeout ? ( | ||
| <CheckSquareIcon className="h-3.5 w-3.5" /> | ||
| ) : ( | ||
| <CopyIcon className="h-3.5 w-3.5" /> | ||
| )} | ||
| </div> | ||
| </div> | ||
| </motion.div> | ||
| </AnimatePresence> | ||
| </Button> | ||
| ); |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance accessibility attributes.
The button needs proper ARIA attributes to improve accessibility for screen readers.
Apply these accessibility improvements:
<Button
type="button"
variant="none"
+ aria-label={`Copy ${value}`}
+ aria-pressed={Boolean(copiedTimeout)}
className="ml-2 h-7 rounded border bg-neutral-50 px-0.5 font-normal dark:border dark:border-neutral-500 dark:bg-neutral-600"
onClick={async () => onCopy()}
>Committable suggestion skipped: line range outside the PR's diff.
| const onCopy = async () => { | ||
| await copy(value).then(() => onCopySuccess?.()); | ||
|
|
||
| if (copiedTimeout) { | ||
| clearTimeout(copiedTimeout); | ||
| } | ||
|
|
||
| setCopiedTimeout( | ||
| setTimeout(() => { | ||
| setCopiedTimeout(null); | ||
| }, 2000), | ||
| ); | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Enhance error handling and configurability.
The copy operation could fail silently, and the timeout duration is hardcoded.
Consider these improvements:
+ const COPY_FEEDBACK_DURATION = 2000;
+
export const CopyTextButton = ({
value,
onCopySuccess,
+ onCopyError,
+ feedbackDuration = COPY_FEEDBACK_DURATION,
badgeContentUncopied,
badgeContentCopied,
}: CopyTextButtonProps) => {
// ...
const onCopy = async () => {
- await copy(value).then(() => onCopySuccess?.());
+ try {
+ await copy(value);
+ onCopySuccess?.();
+ } catch (error) {
+ onCopyError?.(error);
+ return;
+ }
if (copiedTimeout) {
clearTimeout(copiedTimeout);
}
setCopiedTimeout(
setTimeout(() => {
setCopiedTimeout(null);
- }, 2000),
+ }, feedbackDuration),
);
};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const onCopy = async () => { | |
| await copy(value).then(() => onCopySuccess?.()); | |
| if (copiedTimeout) { | |
| clearTimeout(copiedTimeout); | |
| } | |
| setCopiedTimeout( | |
| setTimeout(() => { | |
| setCopiedTimeout(null); | |
| }, 2000), | |
| ); | |
| }; | |
| const COPY_FEEDBACK_DURATION = 2000; | |
| export const CopyTextButton = ({ | |
| value, | |
| onCopySuccess, | |
| onCopyError, | |
| feedbackDuration = COPY_FEEDBACK_DURATION, | |
| badgeContentUncopied, | |
| badgeContentCopied, | |
| }: CopyTextButtonProps) => { | |
| // ... | |
| const onCopy = async () => { | |
| try { | |
| await copy(value); | |
| onCopySuccess?.(); | |
| } catch (error) { | |
| onCopyError?.(error); | |
| return; | |
| } | |
| if (copiedTimeout) { | |
| clearTimeout(copiedTimeout); | |
| } | |
| setCopiedTimeout( | |
| setTimeout(() => { | |
| setCopiedTimeout(null); | |
| }, feedbackDuration), | |
| ); | |
| }; |
| const onBulkCopy = async () => { | ||
| const generatedString = recipients | ||
| .filter((recipient) => recipient.role !== RecipientRole.CC) | ||
| .map((recipient) => `${recipient.email}\n${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`) | ||
| .join('\n\n'); | ||
|
|
||
| await copy(generatedString).then(() => { | ||
| toast({ | ||
| title: _(msg`Copied to clipboard`), | ||
| description: _(msg`All signing links have been copied to your clipboard.`), | ||
| }); | ||
| }); | ||
| }; |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add error handling for clipboard operations.
The bulk copy functionality should handle potential clipboard API failures to provide better user feedback.
const onBulkCopy = async () => {
const generatedString = recipients
.filter((recipient) => recipient.role !== RecipientRole.CC)
.map((recipient) => `${recipient.email}\n${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`)
.join('\n\n');
- await copy(generatedString).then(() => {
- toast({
- title: _(msg`Copied to clipboard`),
- description: _(msg`All signing links have been copied to your clipboard.`),
- });
- });
+ try {
+ await copy(generatedString);
+ toast({
+ title: _(msg`Copied to clipboard`),
+ description: _(msg`All signing links have been copied to your clipboard.`),
+ });
+ } catch (error) {
+ toast({
+ title: _(msg`Failed to copy`),
+ description: _(msg`Unable to copy signing links to clipboard. Please try again.`),
+ variant: 'destructive',
+ });
+ }
};📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const onBulkCopy = async () => { | |
| const generatedString = recipients | |
| .filter((recipient) => recipient.role !== RecipientRole.CC) | |
| .map((recipient) => `${recipient.email}\n${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`) | |
| .join('\n\n'); | |
| await copy(generatedString).then(() => { | |
| toast({ | |
| title: _(msg`Copied to clipboard`), | |
| description: _(msg`All signing links have been copied to your clipboard.`), | |
| }); | |
| }); | |
| }; | |
| const onBulkCopy = async () => { | |
| const generatedString = recipients | |
| .filter((recipient) => recipient.role !== RecipientRole.CC) | |
| .map((recipient) => `${recipient.email}\n${NEXT_PUBLIC_WEBAPP_URL()}/sign/${recipient.token}`) | |
| .join('\n\n'); | |
| try { | |
| await copy(generatedString); | |
| toast({ | |
| title: _(msg`Copied to clipboard`), | |
| description: _(msg`All signing links have been copied to your clipboard.`), | |
| }); | |
| } catch (error) { | |
| toast({ | |
| title: _(msg`Failed to copy`), | |
| description: _(msg`Unable to copy signing links to clipboard. Please try again.`), | |
| variant: 'destructive', | |
| }); | |
| } | |
| }; |
| {document.status === DocumentStatus.PENDING && | ||
| recipient.signingStatus === SigningStatus.NOT_SIGNED && | ||
| recipient.role !== RecipientRole.CC && ( | ||
| <CopyTextButton | ||
| value={formatSigningLink(recipient.token)} | ||
| onCopySuccess={() => { | ||
| toast({ | ||
| title: _(msg`Copied to clipboard`), | ||
| description: _(msg`The signing link has been copied to your clipboard.`), | ||
| }); | ||
| }} | ||
| /> | ||
| )} |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Add error handling for copy operation.
While the copy functionality works well, it should handle potential failures gracefully.
Consider adding error handling:
<CopyTextButton
value={formatSigningLink(recipient.token)}
onCopySuccess={() => {
toast({
title: _(msg`Copied to clipboard`),
description: _(msg`The signing link has been copied to your clipboard.`),
});
}}
+ onCopyError={() => {
+ toast({
+ title: _(msg`Failed to copy`),
+ description: _(msg`Please try copying the link manually.`),
+ variant: 'destructive',
+ });
+ }}
/>📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| {document.status === DocumentStatus.PENDING && | |
| recipient.signingStatus === SigningStatus.NOT_SIGNED && | |
| recipient.role !== RecipientRole.CC && ( | |
| <CopyTextButton | |
| value={formatSigningLink(recipient.token)} | |
| onCopySuccess={() => { | |
| toast({ | |
| title: _(msg`Copied to clipboard`), | |
| description: _(msg`The signing link has been copied to your clipboard.`), | |
| }); | |
| }} | |
| /> | |
| )} | |
| {document.status === DocumentStatus.PENDING && | |
| recipient.signingStatus === SigningStatus.NOT_SIGNED && | |
| recipient.role !== RecipientRole.CC && ( | |
| <CopyTextButton | |
| value={formatSigningLink(recipient.token)} | |
| onCopySuccess={() => { | |
| toast({ | |
| title: _(msg`Copied to clipboard`), | |
| description: _(msg`The signing link has been copied to your clipboard.`), | |
| }); | |
| }} | |
| onCopyError={() => { | |
| toast({ | |
| title: _(msg`Failed to copy`), | |
| description: _(msg`Please try copying the link manually.`), | |
| variant: 'destructive', | |
| }); | |
| }} | |
| /> | |
| )} |
Description
Add more options to copy signing links.
Summary by CodeRabbit
Release Notes
New Features
Bug Fixes
Documentation
Chores