Skip to content

Commit

Permalink
add-user-to-loops-from-landing-page-example (#1105)
Browse files Browse the repository at this point in the history
* add-user-to-loops-from-landing-page-example

* Clean up logic

---------

Co-authored-by: Tom Gotsman <tomgotsman@Toms-MacBook-Pro.local>
Co-authored-by: Alek Petuskey <alekpetuskey@Aleks-MacBook-Pro.local>
  • Loading branch information
3 people authored Dec 3, 2024
1 parent 7f6624a commit 455f080
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 57 deletions.
49 changes: 6 additions & 43 deletions pcweb/pages/index/demos/forms/forms.py
Original file line number Diff line number Diff line change
@@ -1,48 +1,11 @@
from __future__ import annotations

import contextlib
from typing import Any

import httpx
import reflex as rx
from email_validator import EmailNotValidError, validate_email

from pcweb.components.button import button
from pcweb.components.icons import get_icon
from pcweb.constants import REFLEX_DEV_WEB_LANDING_FORM_DEMO_FORM_WEBHOOK_URL


class FormState(rx.State):
@rx.event
def submit(
self,
form_data: dict[str, Any],
):
def submit_form() -> None:
nonlocal form_data
email: str | None
if email := form_data.get("input_email"):
validated_email: str | None = None
with contextlib.suppress(EmailNotValidError):
validated_email = validate_email(
email,
check_deliverability=True,
)

if validated_email is None:
return

with contextlib.suppress(httpx.HTTPError) and httpx.Client() as client:
response = client.post(
REFLEX_DEV_WEB_LANDING_FORM_DEMO_FORM_WEBHOOK_URL,
json=form_data,
)
response.raise_for_status()

return

submit_form()
return rx.toast(form_data)
from pcweb.signup import IndexState


def form() -> rx.Component:
Expand All @@ -55,11 +18,11 @@ def form() -> rx.Component:
),
rx.box(
rx.text(
"Send us a message",
"Join Newsletter",
class_name="font-md-smbold text-slate-12 leading-6",
),
rx.text(
"Fill the form and we’ll back to you shortly.",
"Get the latest updates and news about Reflex.",
class_name="font-small text-slate-9",
),
class_name="flex flex-col gap-1",
Expand Down Expand Up @@ -116,7 +79,7 @@ def form() -> rx.Component:
type="submit",
class_name="!w-full !bg-slate-5 !border-t-[rgba(255,255,255,0.05)] !rounded-[0.625rem] hover:!bg-slate-6 !text-slate-9",
),
on_submit=FormState.submit,
on_submit=IndexState.signup,
class_name="flex flex-col gap-4 border-slate-4 bg-[#F9F9FB] dark:bg-[#222326] p-6 border rounded-[1rem] w-full lg:shadow-large",
),
class_name="flex items-center p-4 lg:px-10 lg:py-12 h-full overflow-hidden",
Expand All @@ -137,9 +100,9 @@ def form() -> rx.Component:
rx.hstack(
rx.image(src="/envelope.png"),
rx.vstack(
rx.heading("Send us a message"),
rx.heading("Join Newsletter"),
rx.text(
"Fill the form and we’ll back to you shortly.",
"Get the latest updates and news about Reflex.",
),
),
),
Expand Down
15 changes: 1 addition & 14 deletions pcweb/signup.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,7 @@ def signup(
"background": "linear-gradient(218deg, #1D1B23 -35.66%, #131217 100.84%)",
},
)

self.send_contact_to_webhook(email)
self.add_contact_to_loops(email)
# Check if the user is already on the newsletter
with rx.session() as session:
user = session.query(Waitlist).filter(Waitlist.email == email).first()
if user is None:
# Add the user to the newsletter
session.add(
Waitlist(
email=email,
),
)
session.commit()

self.signed_up = True
return None
return rx.toast.success("Thanks for signing up to the Newsletter!")

0 comments on commit 455f080

Please sign in to comment.