100 lines
3.5 KiB
TypeScript
100 lines
3.5 KiB
TypeScript
"use client";
|
|
|
|
import { useState, useCallback } from "react";
|
|
import { QRCodeSVG } from "qrcode.react";
|
|
|
|
export function ShareProfileButton({ userId, shareUrl }: { userId: string; shareUrl: string }) {
|
|
const [open, setOpen] = useState(false);
|
|
const [copied, setCopied] = useState(false);
|
|
|
|
const handleCopy = useCallback(() => {
|
|
navigator.clipboard.writeText(shareUrl).then(() => {
|
|
setCopied(true);
|
|
setTimeout(() => setCopied(false), 2000);
|
|
});
|
|
}, [shareUrl]);
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
type="button"
|
|
onClick={() => setOpen(true)}
|
|
className="rounded-lg bg-neutral-900 px-4 py-2 text-sm font-medium text-white shadow-sm transition hover:bg-neutral-800"
|
|
>
|
|
Share Profile
|
|
</button>
|
|
|
|
{open && (
|
|
<>
|
|
{/* Backdrop */}
|
|
<div
|
|
className="fixed inset-0 z-40 bg-black/40"
|
|
onClick={() => setOpen(false)}
|
|
/>
|
|
|
|
{/* Modal */}
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center p-4">
|
|
<div className="w-full max-w-sm rounded-2xl border border-neutral-200 bg-white p-6 shadow-xl">
|
|
<div className="flex items-center justify-between">
|
|
<h2 className="text-lg font-semibold text-neutral-900">
|
|
Share Profile
|
|
</h2>
|
|
<button
|
|
type="button"
|
|
onClick={() => setOpen(false)}
|
|
className="flex size-8 items-center justify-center rounded-lg text-neutral-400 transition hover:bg-neutral-100 hover:text-neutral-600"
|
|
>
|
|
<svg
|
|
xmlns="http://www.w3.org/2000/svg"
|
|
viewBox="0 0 20 20"
|
|
fill="currentColor"
|
|
className="size-5"
|
|
>
|
|
<path d="M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z" />
|
|
</svg>
|
|
</button>
|
|
</div>
|
|
|
|
<p className="mt-2 text-sm text-neutral-500">
|
|
Scan this QR code or share the link to add you as a friend.
|
|
</p>
|
|
|
|
{/* QR Code */}
|
|
<div className="mt-5 flex justify-center rounded-xl border border-neutral-100 bg-white p-4">
|
|
<QRCodeSVG
|
|
value={shareUrl}
|
|
size={200}
|
|
level="M"
|
|
includeMargin={false}
|
|
/>
|
|
</div>
|
|
|
|
{/* Link + Copy */}
|
|
<div className="mt-4 flex items-center gap-2">
|
|
<input
|
|
type="text"
|
|
readOnly
|
|
value={shareUrl}
|
|
className="flex-1 rounded-lg border border-neutral-200 bg-neutral-50 px-3 py-2 text-xs font-mono text-neutral-600 focus:outline-none"
|
|
/>
|
|
<button
|
|
type="button"
|
|
onClick={handleCopy}
|
|
className="shrink-0 rounded-lg border border-neutral-200 px-3 py-2 text-xs font-medium text-neutral-700 transition hover:bg-neutral-100"
|
|
>
|
|
{copied ? "Copied!" : "Copy"}
|
|
</button>
|
|
</div>
|
|
|
|
{/* User ID reference */}
|
|
<p className="mt-3 text-center text-xs text-neutral-400">
|
|
User ID: {userId}
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</>
|
|
)}
|
|
</>
|
|
);
|
|
}
|