({
eventId,
clerkUserId,
...buttonProps
}: Omit<ButtonProps, "children" | "onClick"> & {
eventId: string
clerkUserId: string
})
| 7 | type CopyState = "idle" | "copied" | "error" |
| 8 | |
| 9 | export function CopyEventButton({ |
| 10 | eventId, |
| 11 | clerkUserId, |
| 12 | ...buttonProps |
| 13 | }: Omit<ButtonProps, "children" | "onClick"> & { |
| 14 | eventId: string |
| 15 | clerkUserId: string |
| 16 | }) { |
| 17 | const [copyState, setCopyState] = useState<CopyState>("idle") |
| 18 | |
| 19 | const CopyIcon = getCopyIcon(copyState) |
| 20 | |
| 21 | return ( |
| 22 | <Button |
| 23 | {...buttonProps} |
| 24 | onClick={() => { |
| 25 | navigator.clipboard |
| 26 | .writeText(`${location.origin}/book/${clerkUserId}/${eventId}`) |
| 27 | .then(() => { |
| 28 | setCopyState("copied") |
| 29 | setTimeout(() => setCopyState("idle"), 2000) |
| 30 | }) |
| 31 | .catch(() => { |
| 32 | setCopyState("error") |
| 33 | setTimeout(() => setCopyState("idle"), 2000) |
| 34 | }) |
| 35 | }} |
| 36 | > |
| 37 | <CopyIcon className="size-4 mr-2" /> |
| 38 | {getChildren(copyState)} |
| 39 | </Button> |
| 40 | ) |
| 41 | } |
| 42 | |
| 43 | function getCopyIcon(copyState: CopyState) { |
| 44 | switch (copyState) { |
nothing calls this directly
no test coverage detected