|
1
|
"use client" |
|
2
|
|
|
3
|
import React from "react" |
|
4
|
import { ProductView, useSiteConfig } from "../../providers/SiteConfig" |
|
5
|
import { ArrowUpRightOnBox } from "@medusajs/icons" |
|
6
|
import clsx from "clsx" |
|
7
|
import { DocsTrackingEvents } from "../../constants" |
|
8
|
import { useAnalytics } from "../../providers/Analytics" |
|
9
|
|
|
10
|
export type InProductActionProps = { |
|
11
|
product: ProductView |
|
12
|
renderType: "default" |
|
13
|
type: string |
|
14
|
data?: Record<string, unknown> |
|
15
|
children?: React.ReactNode |
|
16
|
} |
|
17
|
|
|
18
|
export const InProductAction = ({ |
|
19
|
product, |
|
20
|
renderType, |
|
21
|
type, |
|
22
|
data, |
|
23
|
children, |
|
24
|
}: InProductActionProps) => { |
|
25
|
const { productView } = useSiteConfig() |
|
26
|
const { track } = useAnalytics() |
|
27
|
|
|
28
|
if (productView !== product) { |
|
29
|
return <>{children}</> |
|
30
|
} |
|
31
|
|
|
32
|
const handleClick = () => { |
|
33
|
window.parent.postMessage( |
|
34
|
{ |
|
35
|
type, |
|
36
|
data, |
|
37
|
}, |
|
38
|
"*" |
|
39
|
) |
|
40
|
track({ |
|
41
|
event: { |
|
42
|
event: DocsTrackingEvents.BLOOM_ACTION, |
|
43
|
options: { |
|
44
|
type, |
|
45
|
...data, |
|
46
|
}, |
|
47
|
}, |
|
48
|
}) |
|
49
|
} |
|
50
|
|
|
51
|
// TODO add handling for other render types |
|
52
|
|
|
53
|
return ( |
|
54
|
<span |
|
55
|
className={clsx( |
|
56
|
"border-b border-dashed border-medusa-fg-muted hover:border-medusa-fg-interactive", |
|
57
|
"font-medium transition-colors cursor-pointer", |
|
58
|
"inline-flex items-center gap-0.25" |
|
59
|
)} |
|
60
|
onClick={handleClick} |
|
61
|
tabIndex={-1} |
|
62
|
> |
|
63
|
<span>{children}</span> |
|
64
|
<ArrowUpRightOnBox /> |
|
65
|
</span> |
|
66
|
) |
|
67
|
} |