Files
hackerspace.sh/components/forms/copy-link-button.tsx
T
Moheeb Zara 2559166092 feat(forms): visible public link + one-click Copy on member and admin lists
- shared components/forms/copy-link-button.tsx (one control, no drift):
  copies the absolute /f/<space>/<slug> URL, check-mark + toast feedback
- admin /forms list: Copy link button on every published public form
- member /my-forms list: shows the /f/<space>/<slug> path and a Copy
  button for public forms; row restructured so the button is not nested
  in the row link
- members-only forms show no public link (correct: they have none)

337 tests; build verified. Local commit (deploy on your word).
2026-05-16 18:05:23 -07:00

34 lines
1.0 KiB
TypeScript

'use client'
import { useState } from 'react'
import { Check, Copy } from 'lucide-react'
import { toast } from 'sonner'
import { Button } from '@/components/ui/button'
// One reusable copy-to-clipboard control for a form's public link. Shared by
// the admin forms list and the member forms list so the behaviour and styling
// never drift.
export function CopyLinkButton({ path, label = 'Copy link' }: { path: string; label?: string }) {
const [copied, setCopied] = useState(false)
async function copy() {
const url =
typeof window !== 'undefined' ? `${window.location.origin}${path}` : path
try {
await navigator.clipboard?.writeText(url)
setCopied(true)
toast.success('Public link copied')
setTimeout(() => setCopied(false), 2000)
} catch {
toast.error('Could not copy — copy it manually')
}
}
return (
<Button size="sm" variant="secondary" onClick={copy} aria-label={label}>
{copied ? <Check className="size-4" /> : <Copy className="size-4" />}
{label}
</Button>
)
}