|
1
|
"use client" |
|
2
|
|
|
3
|
import { Brackets, CheckCircle, SquareTwoStack, Tag } from "@medusajs/icons" |
|
4
|
import { |
|
5
|
DropdownMenu, |
|
6
|
H2, |
|
7
|
H2Props, |
|
8
|
H3, |
|
9
|
H3Props, |
|
10
|
useCopy, |
|
11
|
useGenerateSnippet, |
|
12
|
} from "docs-ui" |
|
13
|
|
|
14
|
type EventHeaderProps = ( |
|
15
|
| { |
|
16
|
headerLvl: "2" |
|
17
|
headerProps: H2Props |
|
18
|
} |
|
19
|
| { |
|
20
|
headerLvl: "3" |
|
21
|
headerProps: H3Props |
|
22
|
} |
|
23
|
) & { |
|
24
|
eventName: string |
|
25
|
payload: string |
|
26
|
} |
|
27
|
|
|
28
|
export const EventHeader = ({ |
|
29
|
headerLvl, |
|
30
|
headerProps, |
|
31
|
eventName, |
|
32
|
payload: payloadStr, |
|
33
|
}: EventHeaderProps) => { |
|
34
|
const Header = headerLvl === "2" ? H2 : H3 |
|
35
|
const { snippet } = useGenerateSnippet({ |
|
36
|
type: "subscriber", |
|
37
|
options: { |
|
38
|
event: eventName, |
|
39
|
payload: payloadStr, |
|
40
|
}, |
|
41
|
}) |
|
42
|
const { handleCopy: handleEventNameCopy, isCopied: eventNameCopied } = |
|
43
|
useCopy(eventName) |
|
44
|
const { handleCopy: handleSnippetCopy, isCopied: snippetCopied } = |
|
45
|
useCopy(snippet) |
|
46
|
|
|
47
|
return ( |
|
48
|
<div className="flex items-center justify-between flex-wrap"> |
|
49
|
<Header {...headerProps}>{headerProps.children ?? eventName}</Header> |
|
50
|
<DropdownMenu |
|
51
|
dropdownButtonContent={ |
|
52
|
<> |
|
53
|
{eventNameCopied || snippetCopied ? ( |
|
54
|
<CheckCircle /> |
|
55
|
) : ( |
|
56
|
<SquareTwoStack /> |
|
57
|
)} |
|
58
|
</> |
|
59
|
} |
|
60
|
menuItems={[ |
|
61
|
{ |
|
62
|
type: "action", |
|
63
|
title: "Copy event name", |
|
64
|
action: () => handleEventNameCopy(), |
|
65
|
icon: <Tag />, |
|
66
|
}, |
|
67
|
{ |
|
68
|
type: "action", |
|
69
|
title: "Copy subscriber for event", |
|
70
|
action: () => handleSnippetCopy(), |
|
71
|
icon: <Brackets />, |
|
72
|
}, |
|
73
|
]} |
|
74
|
menuClassName="z-10" |
|
75
|
/> |
|
76
|
</div> |
|
77
|
) |
|
78
|
} |