Skip to content

Commit 2114888

Browse files
committed
use custom clipboard hook
1 parent 791f3d6 commit 2114888

File tree

4 files changed

+31
-138
lines changed

4 files changed

+31
-138
lines changed

package-lock.json

Lines changed: 0 additions & 136 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
"@radix-ui/react-toggle": "^1.1.2",
4040
"@radix-ui/react-toggle-group": "^1.1.2",
4141
"@radix-ui/react-tooltip": "^1.1.8",
42-
"@reactuses/core": "^6.0.6",
4342
"@tailwindcss/vite": "^4.1.11",
4443
"@types/react": "^19.0.3",
4544
"@types/react-dom": "^19.0.2",

resources/js/components/two-factor-setup-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ import InputError from '@/components/input-error';
22
import { Button } from '@/components/ui/button';
33
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog';
44
import { InputOTP, InputOTPGroup, InputOTPSlot } from '@/components/ui/input-otp';
5+
import { useClipboard } from '@/hooks/use-clipboard';
56
import { OTP_MAX_LENGTH } from '@/hooks/use-two-factor-auth';
67
import { confirm } from '@/routes/two-factor';
78
import { Form } from '@inertiajs/react';
8-
import { useClipboard } from '@reactuses/core';
99
import { REGEXP_ONLY_DIGITS } from 'input-otp';
1010
import { Check, Copy, Loader2, ScanLine } from 'lucide-react';
1111
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/** Credits to https://github.com/juliencrn/usehooks-ts */
2+
3+
import { useCallback, useState } from 'react';
4+
5+
type CopiedValue = string | null;
6+
7+
type CopyFn = (text: string) => Promise<boolean>;
8+
9+
export function useClipboard(): [CopiedValue, CopyFn] {
10+
const [copiedText, setCopiedText] = useState<CopiedValue>(null);
11+
12+
const copy: CopyFn = useCallback(async (text) => {
13+
if (!navigator?.clipboard) {
14+
console.warn('Clipboard not supported');
15+
return false;
16+
}
17+
18+
try {
19+
await navigator.clipboard.writeText(text);
20+
setCopiedText(text);
21+
return true;
22+
} catch (error) {
23+
console.warn('Copy failed', error);
24+
setCopiedText(null);
25+
return false;
26+
}
27+
}, []);
28+
29+
return [copiedText, copy];
30+
}

0 commit comments

Comments
 (0)