Skip to content

Commit 096c86f

Browse files
committed
no component state
1 parent 30eb831 commit 096c86f

File tree

1 file changed

+82
-84
lines changed

1 file changed

+82
-84
lines changed

reflex_ui/blocks/demo_form.py

Lines changed: 82 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
based on company size.
66
"""
77

8-
import asyncio
98
import os
109
import urllib.parse
1110
import uuid
@@ -214,8 +213,8 @@ def check_if_default_value_is_selected(value: str) -> bool:
214213
return value.strip() != "Select"
215214

216215

217-
class DemoForm(rx.ComponentState):
218-
"""Component state for handling demo form submissions and integrations."""
216+
class DemoFormStateUI(rx.State):
217+
"""State for handling demo form submissions and integrations."""
219218

220219
@rx.event(background=True)
221220
async def on_submit(self, form_data: dict[str, Any]):
@@ -268,7 +267,7 @@ async def on_submit(self, form_data: dict[str, Any]):
268267
return
269268
yield is_sending_demo_form.push(True)
270269
# Send to PostHog and Slack for all submissions
271-
await self.send_demo_event(form_data)
270+
yield DemoFormStateUI.send_demo_event(form_data)
272271

273272
notes_content = f"""
274273
Name: {form_data.get("first_name", "")} {form_data.get("last_name", "")}
@@ -294,6 +293,7 @@ async def on_submit(self, form_data: dict[str, Any]):
294293

295294
yield [is_sending_demo_form.push(False), rx.redirect(cal_url_with_params)]
296295

296+
@rx.event(background=True)
297297
async def send_demo_event(self, form_data: dict[str, Any]):
298298
"""Create and send demo event to PostHog and Slack.
299299
@@ -319,12 +319,13 @@ async def send_demo_event(self, form_data: dict[str, Any]):
319319
)
320320

321321
# Send data to PostHog, Common Room, and Slack
322-
await asyncio.gather(
323-
self.send_data_to_posthog(demo_event),
324-
self.send_data_to_common_room(demo_event),
325-
self.send_data_to_slack(demo_event),
326-
)
322+
yield [
323+
DemoFormStateUI.send_data_to_posthog(demo_event),
324+
DemoFormStateUI.send_data_to_common_room(demo_event),
325+
DemoFormStateUI.send_data_to_slack(demo_event),
326+
]
327327

328+
@rx.event(background=True)
328329
async def send_data_to_posthog(self, event_instance: PosthogEvent):
329330
"""Send data to PostHog using class introspection.
330331
@@ -348,6 +349,7 @@ async def send_data_to_posthog(self, event_instance: PosthogEvent):
348349
except Exception:
349350
log("Error sending data to PostHog")
350351

352+
@rx.event(background=True)
351353
async def send_data_to_common_room(self, event_instance: DemoEvent):
352354
"""Update CommonRoom with user login information."""
353355
tags: Sequence[str] = [
@@ -383,6 +385,7 @@ async def send_data_to_common_room(self, event_instance: DemoEvent):
383385
f"CommonRoom: Failed to identify user with email {event_instance.company_email}, err: {ex}"
384386
)
385387

388+
@rx.event(background=True)
386389
async def send_data_to_slack(self, event_instance: DemoEvent):
387390
"""Send demo form data to Slack webhook.
388391
@@ -410,89 +413,84 @@ async def send_data_to_slack(self, event_instance: DemoEvent):
410413
except Exception as e:
411414
log(f"Error sending data to Slack webhook: {e}")
412415

413-
@classmethod
414-
def get_component(cls, **props):
415-
"""Create and return the demo form component.
416416

417-
Builds a complete form with all required fields, validation,
418-
and styling. The form includes personal info, company details,
419-
and preferences.
417+
def demo_form(**props) -> rx.Component:
418+
"""Create and return the demo form component.
420419
421-
Args:
422-
**props: Additional properties to pass to the form component
420+
Builds a complete form with all required fields, validation,
421+
and styling. The form includes personal info, company details,
422+
and preferences.
423423
424-
Returns:
425-
A Reflex form component with all demo form fields
426-
"""
427-
return rx.el.form(
428-
rx.el.div(
429-
input_field("First name", "John", "first_name", "text", True),
430-
input_field("Last name", "Smith", "last_name", "text", True),
431-
class_name="grid grid-cols-2 gap-4",
432-
),
433-
input_field("Business Email", "[email protected]", "email", "email", True),
434-
rx.el.div(
435-
input_field("Job title", "CTO", "job_title", "text", True),
436-
input_field(
437-
"Company name", "Pynecone, Inc.", "company_name", "text", True
438-
),
439-
class_name="grid grid-cols-2 gap-4",
440-
),
441-
text_area_field(
442-
"What are you looking to build? *",
443-
"Please list any apps, requirements, or data sources you plan on using",
444-
"internal_tools",
445-
True,
446-
),
447-
rx.el.div(
448-
select_field(
449-
"Number of employees?",
450-
"number_of_employees",
451-
["1", "2-5", "6-10", "11-50", "51-100", "101-500", "500+"],
452-
),
453-
select_field(
454-
"How did you hear about us?",
455-
"how_did_you_hear_about_us",
456-
[
457-
"Google Search",
458-
"Social Media",
459-
"Word of Mouth",
460-
"Blog",
461-
"Conference",
462-
"Other",
463-
],
464-
),
465-
class_name="grid grid-cols-2 gap-4",
424+
Args:
425+
**props: Additional properties to pass to the form component
426+
427+
Returns:
428+
A Reflex form component with all demo form fields
429+
"""
430+
return rx.el.form(
431+
rx.el.div(
432+
input_field("First name", "John", "first_name", "text", True),
433+
input_field("Last name", "Smith", "last_name", "text", True),
434+
class_name="grid grid-cols-2 gap-4",
435+
),
436+
input_field("Business Email", "[email protected]", "email", "email", True),
437+
rx.el.div(
438+
input_field("Job title", "CTO", "job_title", "text", True),
439+
input_field("Company name", "Pynecone, Inc.", "company_name", "text", True),
440+
class_name="grid grid-cols-2 gap-4",
441+
),
442+
text_area_field(
443+
"What are you looking to build? *",
444+
"Please list any apps, requirements, or data sources you plan on using",
445+
"internal_tools",
446+
True,
447+
),
448+
rx.el.div(
449+
select_field(
450+
"Number of employees?",
451+
"number_of_employees",
452+
["1", "2-5", "6-10", "11-50", "51-100", "101-500", "500+"],
466453
),
467454
select_field(
468-
"How technical are you?",
469-
"technical_level",
470-
["Non-technical", "Neutral", "Technical"],
471-
True,
455+
"How did you hear about us?",
456+
"how_did_you_hear_about_us",
457+
[
458+
"Google Search",
459+
"Social Media",
460+
"Word of Mouth",
461+
"Blog",
462+
"Conference",
463+
"Other",
464+
],
472465
),
473-
rx.cond(
466+
class_name="grid grid-cols-2 gap-4",
467+
),
468+
select_field(
469+
"How technical are you?",
470+
"technical_level",
471+
["Non-technical", "Neutral", "Technical"],
472+
True,
473+
),
474+
rx.cond(
475+
demo_form_error_message.value,
476+
rx.el.span(
474477
demo_form_error_message.value,
475-
rx.el.span(
476-
demo_form_error_message.value,
477-
class_name="text-destructive-10 text-sm font-medium",
478-
),
479-
),
480-
ui.button(
481-
"Submit",
482-
type="submit",
483-
class_name="w-full",
484-
loading=is_sending_demo_form.value,
485-
),
486-
on_submit=cls.on_submit,
487-
class_name=ui.cn(
488-
"@container flex flex-col gap-6 p-6",
489-
props.pop("class_name", ""),
478+
class_name="text-destructive-10 text-sm font-medium",
490479
),
491-
**props,
492-
)
493-
494-
495-
demo_form = DemoForm.create
480+
),
481+
ui.button(
482+
"Submit",
483+
type="submit",
484+
class_name="w-full",
485+
loading=is_sending_demo_form.value,
486+
),
487+
on_submit=DemoFormStateUI.on_submit,
488+
class_name=ui.cn(
489+
"@container flex flex-col gap-6 p-6",
490+
props.pop("class_name", ""),
491+
),
492+
**props,
493+
)
496494

497495

498496
def demo_form_dialog(trigger: rx.Component, **props) -> rx.Component:

0 commit comments

Comments
 (0)