Skip to content

Commit 7c55aa3

Browse files
committed
calcom embed
1 parent 664e4aa commit 7c55aa3

File tree

2 files changed

+437
-302
lines changed

2 files changed

+437
-302
lines changed

reflex_ui/blocks/calcom.py

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
"""Cal.com integration components for Reflex UI."""
2+
3+
import os
4+
5+
import reflex as rx
6+
7+
DEFAULT_CAL_FORM = os.getenv(
8+
"DEFAULT_CAL_FORM", "forms/f87bd9b2-b339-4915-b4d4-0098e2db4394"
9+
)
10+
11+
12+
def get_cal_attrs(cal_form: str = DEFAULT_CAL_FORM, **kwargs):
13+
"""Get Cal.com attributes for embedding.
14+
15+
Args:
16+
cal_form: The Cal.com form link
17+
**kwargs: Additional attributes to include
18+
19+
Returns:
20+
Dictionary of Cal.com attributes
21+
"""
22+
attrs = {
23+
"data-cal-link": cal_form,
24+
"data-cal-namespace": "talk",
25+
"data-cal-config": rx.color_mode_cond(
26+
'{"theme":"light","layout":"month_view"}',
27+
'{"theme":"dark","layout":"month_view"}',
28+
),
29+
}
30+
attrs.update(kwargs)
31+
return attrs
32+
33+
34+
class CalcomPopupEmbed(rx.Fragment):
35+
"""Cal.com popup embed component using React hooks."""
36+
37+
def add_imports(self) -> rx.ImportDict:
38+
"""Add required imports for Cal.com embed.
39+
40+
Returns:
41+
Dictionary of imports needed for the component
42+
"""
43+
return {
44+
"react": rx.ImportVar("useEffect"),
45+
"@calcom/[email protected]": rx.ImportVar("getCalApi"),
46+
}
47+
48+
def add_hooks(self) -> list[str | rx.Var[object]]:
49+
"""Add React hooks for Cal.com API initialization.
50+
51+
Returns:
52+
List of hook code strings to initialize Cal.com
53+
"""
54+
return [
55+
"""
56+
useEffect(() => {
57+
(async function () {
58+
const cal = await getCalApi({ namespace: "talk" });
59+
cal("ui", {
60+
hideEventTypeDetails: false,
61+
layout: "month_view",
62+
styles: {
63+
branding: { brandColor: "#6F56CF" },
64+
},
65+
});
66+
})();
67+
}, []);
68+
""",
69+
]
70+
71+
72+
calcom_popup_embed = CalcomPopupEmbed.create
73+
74+
75+
class CalEmbed(rx.Component):
76+
"""Cal.com embed component using the Cal React component."""
77+
78+
library = "@calcom/[email protected]"
79+
tag = "Cal"
80+
is_default = True
81+
82+
cal_link: rx.Var[str]
83+
84+
config: rx.Var[dict]
85+
86+
@classmethod
87+
def create(
88+
cls,
89+
cal_link: str = DEFAULT_CAL_FORM,
90+
config: dict | None = None,
91+
**props,
92+
):
93+
"""Create a Cal.com embed component.
94+
95+
Args:
96+
cal_link: The Cal.com link (e.g., "forms/...")
97+
config: Configuration object for Cal.com (e.g., {"theme": "light"})
98+
**props: Additional props to pass to the component
99+
"""
100+
return super().create(
101+
cal_link=cal_link,
102+
config=config,
103+
**props,
104+
)
105+
106+
107+
cal_embed = CalEmbed.create

0 commit comments

Comments
 (0)