Skip to content

Commit 61b86d9

Browse files
committed
revert
1 parent 116a403 commit 61b86d9

File tree

1 file changed

+39
-20
lines changed

1 file changed

+39
-20
lines changed

reflex_ui/blocks/plain.py

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,49 @@ def add_hooks(self) -> list[str | rx.Var]:
4040
return [
4141
rx.Var(
4242
f"""useEffect(() => {{
43+
if (typeof window === 'undefined') return;
44+
45+
const customerDetails = {{
46+
fullName: {self.full_name!s},
47+
shortName: {self.short_name!s},
48+
chatAvatarUrl: {self.chat_avatar_url!s},
49+
}};
50+
51+
// Add email if provided
52+
if ({self.email!s}) {{
53+
customerDetails.email = {self.email!s};
54+
}}
55+
if ({self.email_hash!s}) {{
56+
customerDetails.emailHash = {self.email_hash!s};
57+
}}
58+
59+
const initOptions = {{
60+
appId: '{PLAIN_APP_ID}',
61+
hideLauncher: {self.hide_launcher!s},
62+
hideBranding: true,
63+
theme: 'auto',
64+
customerDetails: customerDetails,
65+
threadDetails: {{
66+
externalId: {self.external_id!s},
67+
}},
68+
}};
69+
70+
// Add requireAuthentication if true
71+
if ({self.require_authentication!s}) {{
72+
initOptions.requireAuthentication = true;
73+
}}
74+
75+
if (window.Plain) {{
76+
Plain.init(initOptions);
77+
return;
78+
}}
79+
4380
const script = document.createElement('script');
4481
script.async = false;
4582
script.src = 'https://chat.cdn-plain.com/index.js';
46-
script.onload = () => {{
47-
Plain.init({{
48-
appId: '{PLAIN_APP_ID}',
49-
hideLauncher: {self.hide_launcher!s},
50-
hideBranding: true,
51-
theme: 'auto',
52-
customerDetails: {{
53-
fullName: {self.full_name!s},
54-
shortName: {self.short_name!s},
55-
chatAvatarUrl: {self.chat_avatar_url!s},
56-
email: {self.email!s},
57-
emailHash: {self.email_hash!s},
58-
}},
59-
threadDetails: {{
60-
externalId: {self.external_id!s},
61-
}},
62-
requireAuthentication: {self.require_authentication!s},
63-
}});
64-
}};
83+
script.onload = () => Plain.init(initOptions);
6584
document.head.appendChild(script);
66-
}}, [])"""
85+
}}, [{self.full_name!s}, {self.short_name!s}, {self.chat_avatar_url!s}, {self.external_id!s}, {self.email!s}, {self.email_hash!s}])"""
6786
)
6887
]
6988

0 commit comments

Comments
 (0)