Skip to content

Commit ed7cf7b

Browse files
committed
optional user details
1 parent 86a54b6 commit ed7cf7b

File tree

1 file changed

+25
-12
lines changed

1 file changed

+25
-12
lines changed

reflex_ui/blocks/plain.py

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ class PlainChat(rx.Component):
1818

1919
tag = "PlainChat"
2020

21-
full_name: rx.Var[str]
22-
short_name: rx.Var[str]
23-
chat_avatar_url: rx.Var[str]
24-
external_id: rx.Var[str]
21+
full_name: rx.Var[str] = rx.Var.create("User")
22+
short_name: rx.Var[str] = rx.Var.create("User")
23+
chat_avatar_url: rx.Var[str] = rx.Var.create("")
24+
external_id: rx.Var[str] = rx.Var.create("")
2525
hide_launcher: rx.Var[bool] = rx.Var.create(True)
2626

2727
# Optional email authentication
@@ -42,11 +42,20 @@ def add_hooks(self) -> list[str | rx.Var]:
4242
f"""useEffect(() => {{
4343
if (typeof window === 'undefined') return;
4444
45-
const customerDetails = {{
46-
fullName: {self.full_name!s},
47-
shortName: {self.short_name!s},
48-
chatAvatarUrl: {self.chat_avatar_url!s},
49-
}};
45+
const customerDetails = {{}};
46+
47+
// Add fullName and shortName if provided
48+
if ({self.full_name!s}) {{
49+
customerDetails.fullName = {self.full_name!s};
50+
}}
51+
if ({self.short_name!s}) {{
52+
customerDetails.shortName = {self.short_name!s};
53+
}}
54+
55+
// Add chatAvatarUrl if provided
56+
if ({self.chat_avatar_url!s}) {{
57+
customerDetails.chatAvatarUrl = {self.chat_avatar_url!s};
58+
}}
5059
5160
// Add email if provided
5261
if ({self.email!s}) {{
@@ -62,11 +71,15 @@ def add_hooks(self) -> list[str | rx.Var]:
6271
hideBranding: true,
6372
theme: 'auto',
6473
customerDetails: customerDetails,
65-
threadDetails: {{
66-
externalId: {self.external_id!s},
67-
}},
6874
}};
6975
76+
// Add threadDetails if externalId is provided
77+
if ({self.external_id!s}) {{
78+
initOptions.threadDetails = {{
79+
externalId: {self.external_id!s},
80+
}};
81+
}}
82+
7083
// Add requireAuthentication if true
7184
if ({self.require_authentication!s}) {{
7285
initOptions.requireAuthentication = true;

0 commit comments

Comments
 (0)