MCPcopy Create free account
hub / github.com/WebDevSimplified/calendly-clone / CopyEventButton

Function CopyEventButton

src/components/CopyEventButton.tsx:9–41  ·  view source on GitHub ↗
({
  eventId,
  clerkUserId,
  ...buttonProps
}: Omit<ButtonProps, "children" | "onClick"> & {
  eventId: string
  clerkUserId: string
})

Source from the content-addressed store, hash-verified

7type CopyState = "idle" | "copied" | "error"
8
9export 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
43function getCopyIcon(copyState: CopyState) {
44 switch (copyState) {

Callers

nothing calls this directly

Calls 2

getCopyIconFunction · 0.85
getChildrenFunction · 0.85

Tested by

no test coverage detected