Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

refactor: use react-hotkeys-hook for Command+Enter shortcut

Cursor Agent9da853f6379c
diff --git a/components/links/link-sheet/index.tsx b/components/links/link-sheet/index.tsx
index 4d812fd7..c671f9e6 100644
--- a/components/links/link-sheet/index.tsx
+++ b/components/links/link-sheet/index.tsx
@@ -1,14 +1,9 @@
import Link from "next/link";
import { useRouter } from "next/router";
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useEffect,
- useRef,
- useState,
-} from "react";
+import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
+
+import { useHotkeys } from "react-hotkeys-hook";
import { useTeam } from "@/context/team-context";
import { PlanEnum } from "@/ee/stripe/constants";
@@ -209,27 +204,18 @@ export default function LinkSheet({
}, [currentLink]);
// Handle Command+Enter (Mac) or Ctrl+Enter (Windows/Linux) to submit the form
- const handleKeyDown = useCallback(
- (event: KeyboardEvent) => {
- if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
- event.preventDefault();
- if (!isSaving && formRef.current) {
- formRef.current.requestSubmit();
- }
+ useHotkeys(
+ "mod+enter",
+ (e) => {
+ e.preventDefault();
+ if (!isSaving && formRef.current) {
+ formRef.current.requestSubmit();
}
},
+ { enabled: isOpen, enableOnFormTags: true },
[isSaving],
);
- useEffect(() => {
- if (isOpen) {
- document.addEventListener("keydown", handleKeyDown);
- return () => {
- document.removeEventListener("keydown", handleKeyDown);
- };
- }
- }, [isOpen, handleKeyDown]);
-
const handlePreviewLink = async (link: LinkWithViews) => {
if (link.domainId && isFree) {
toast.error("You need to upgrade to preview this link");
diff --git a/ee/features/permissions/components/dataroom-link-sheet.tsx b/ee/features/permissions/components/dataroom-link-sheet.tsx
index 0375db4a..dcfe42db 100644
--- a/ee/features/permissions/components/dataroom-link-sheet.tsx
+++ b/ee/features/permissions/components/dataroom-link-sheet.tsx
@@ -1,14 +1,9 @@
import Link from "next/link";
import { useRouter } from "next/router";
-import {
- Dispatch,
- SetStateAction,
- useCallback,
- useEffect,
- useRef,
- useState,
-} from "react";
+import { Dispatch, SetStateAction, useEffect, useRef, useState } from "react";
+
+import { useHotkeys } from "react-hotkeys-hook";
import { useTeam } from "@/context/team-context";
import {
@@ -149,27 +144,18 @@ export function DataroomLinkSheet({
}, [currentLink]);
// Handle Command+Enter (Mac) or Ctrl+Enter (Windows/Linux) to submit the form
- const handleKeyDown = useCallback(
- (event: KeyboardEvent) => {
- if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
- event.preventDefault();
- if (!isSaving && formRef.current) {
- formRef.current.requestSubmit();
- }
+ useHotkeys(
+ "mod+enter",
+ (e) => {
+ e.preventDefault();
+ if (!isSaving && formRef.current) {
+ formRef.current.requestSubmit();
}
},
+ { enabled: isOpen, enableOnFormTags: true },
[isSaving],
);
- useEffect(() => {
- if (isOpen) {
- document.addEventListener("keydown", handleKeyDown);
- return () => {
- document.removeEventListener("keydown", handleKeyDown);
- };
- }
- }, [isOpen, handleKeyDown]);
-
const handlePreviewLink = async (link: LinkWithViews) => {
if (link.domainId && isFree) {
toast.error("You need to upgrade to preview this link");