This repository was archived by the owner on Apr 23, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcalcom.py
More file actions
119 lines (93 loc) · 3.22 KB
/
calcom.py
File metadata and controls
119 lines (93 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""Cal.com integration components for Reflex UI."""
import os
import reflex as rx
DEFAULT_CAL_NAMESPACE = os.getenv("DEFAULT_CAL_NAMESPACE", "reflex-intro-call")
DEFAULT_CAL_LINK = os.getenv("DEFAULT_CAL_LINK", "team/reflex/reflex-intro-call")
def get_cal_attrs(
cal_namespace: str = DEFAULT_CAL_NAMESPACE,
cal_link: str = DEFAULT_CAL_LINK,
config: str | rx.Var[str] | None = '{"theme": "dark", "layout": "month_view"}',
**kwargs,
):
"""Get Cal.com attributes for embedding.
Args:
cal_namespace: The Cal.com namespace
cal_link: The Cal.com form link
config: Cal.com configuration dict including theme, layout, name, email, etc.
**kwargs: Additional attributes to include
Returns:
Dictionary of Cal.com attributes
"""
attrs = {
"data-cal-link": cal_link,
"data-cal-namespace": cal_namespace,
"data-cal-config": config,
}
attrs.update(kwargs)
return attrs
class CalcomPopupEmbed(rx.Fragment):
"""Cal.com popup embed component using React hooks."""
def add_imports(self) -> rx.ImportDict:
"""Add required imports for Cal.com embed.
Returns:
Dictionary of imports needed for the component
"""
return {
"react": rx.ImportVar("useEffect"),
"@calcom/embed-react@1.5.3": rx.ImportVar("getCalApi"),
}
def add_hooks(self) -> list[str | rx.Var[object]]:
"""Add React hooks for Cal.com API initialization.
Returns:
List of hook code strings to initialize Cal.com
"""
return [
"""
useEffect(() => {
(async function () {
const cal = await getCalApi({ namespace: "reflex-intro-call" });
cal("ui", {
hideEventTypeDetails: false,
layout: "month_view",
styles: {
branding: { brandColor: "#6F56CF" },
},
});
})();
}, []);
""",
]
calcom_popup_embed = CalcomPopupEmbed.create
class CalEmbed(rx.Component):
"""Cal.com embed component using the Cal React component."""
library = "@calcom/embed-react@1.5.3"
tag = "Cal"
is_default = True
cal_link: rx.Var[str]
namespace: rx.Var[str]
config: rx.Var[dict]
@classmethod
def create(
cls,
cal_link: str = DEFAULT_CAL_LINK,
cal_namespace: str = DEFAULT_CAL_NAMESPACE,
config: rx.Var[dict] | dict | None = None,
**props,
):
"""Create a Cal.com embed component.
Args:
cal_link: The Cal.com link (e.g., "team/reflex/reflex-intro-call")
cal_namespace: The namespace for the Cal.com embed
config: Configuration object for Cal.com including prefill data.
According to https://cal.com/help/embedding/prefill-booking-form-embed
you can prefill: name, email, notes, and location.
Example: {"layout": "month_view", "name": "John Doe", "email": "[email protected]", "notes": "Company details..."}
**props: Additional props to pass to the component
"""
return super().create(
cal_link=cal_link,
namespace=cal_namespace,
config=config,
**props,
)
cal_embed = CalEmbed.create