-
Notifications
You must be signed in to change notification settings - Fork 112
Expand file tree
/
Copy pathLinkIdCard.tsx
More file actions
72 lines (66 loc) · 2.21 KB
/
Copy pathLinkIdCard.tsx
File metadata and controls
72 lines (66 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Button } from "@/components/ui/button";
import { Copy, Check, ExternalLink, Link2 } from "lucide-react";
import { useState } from "react";
import toast from "react-hot-toast";
export function LinkIdCard({
username,
qrCode,
}: {
username: string;
qrCode?: React.ReactNode;
}) {
const [copied, setCopied] = useState(false);
async function copyProfile() {
try {
await navigator.clipboard.writeText(`https://linkid.qzz.io/${username}`);
setCopied(true);
toast.success("Profile link copied successfully!");
setTimeout(() => setCopied(false), 1200);
} catch (error) {
toast.error("Unable to copy profile link. Please try again.");
}
}
return (
<Card>
<CardHeader className="flex flex-row items-center justify-between">
<CardTitle className="flex flex-row items-center gap-2 text-base sm:text-lg">
<Link2 className="h-4 w-4 sm:h-5 sm:w-5" />
Your LinkID
</CardTitle>
<div className="flex-shrink-0">{qrCode}</div>
</CardHeader>
<CardContent className="flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between">
{/* Link box */}
<div className="flex items-center justify-between gap-2 rounded-md bg-muted px-3 py-2 text-sm font-mono w-full sm:w-auto">
<code className="truncate">linkid.qzz.io/{username}</code>
<Button
size="icon"
variant="ghost"
onClick={copyProfile}
className="shrink-0"
aria-label="Copy profile link"
title="Copy profile link"
>
{copied ? (
<Check className="h-4 w-4 text-green-600" />
) : (
<Copy className="h-4 w-4" />
)}
</Button>
</div>
{/* Open button */}
<Button
variant="outline"
asChild
className="w-full sm:w-auto justify-center gap-2"
>
<a href={`/${username}`} target="_blank" rel="noopener noreferrer">
<ExternalLink className="h-4 w-4" />
Open
</a>
</Button>
</CardContent>
</Card>
);
}