From 7b756c8fc0a0fedee4c54442793ea03587fdd3ac Mon Sep 17 00:00:00 2001 From: Nils Jacobsen Date: Fri, 12 Apr 2024 15:30:53 +0200 Subject: [PATCH] feat: add substack form for newsletter --- .../interface/components/NewsletterForm.tsx | 142 +----------------- 1 file changed, 8 insertions(+), 134 deletions(-) diff --git a/inlang/source-code/website/src/interface/components/NewsletterForm.tsx b/inlang/source-code/website/src/interface/components/NewsletterForm.tsx index 72fd9fa6f1..834aa3b3b6 100644 --- a/inlang/source-code/website/src/interface/components/NewsletterForm.tsx +++ b/inlang/source-code/website/src/interface/components/NewsletterForm.tsx @@ -1,143 +1,17 @@ -import { Show, createSignal } from "solid-js" -import { showToast } from "./Toast.jsx" -import { rpc } from "@inlang/rpc" import * as m from "../../paraglide/messages.js" -import Captcha from "./Captcha.jsx" -import validator from "validator" -import { Icon } from "./Icon.jsx" export function NewsletterForm() { - const [email, setEmail] = createSignal("") - const [loading, setLoading] = createSignal(false) - // eslint-disable-next-line unicorn/no-null - const [captchaResponse, setCaptchaResponse] = createSignal(null) - - const fetchSubscriber = async (email: any) => { - setLoading(true) - const response = await rpc.subscribeNewsletter({ email }) - if (!response.error) { - if (response.data === "already subscribed") { - showToast({ - title: "Could not subscribe", - variant: "success", - message: m.newsletter_error_alreadySubscribed(), - }) - } else if (response.data === "success") { - showToast({ - title: "Success", - variant: "success", - message: m.newsletter_success(), - }) - } else { - showToast({ - title: "Error", - variant: "danger", - message: m.newsletter_error_generic(), - }) - } - } else { - showToast({ - title: "Error", - variant: "danger", - message: m.newsletter_error_generic(), - }) - } - - setLoading(false) - setEmail("") - } - - function handleSubscribe() { - if (loading()) return - - function checkEmail(email: any) { - if (email.trim() === "") { - return "empty" - } else if (!validator.default.isEmail(email)) { - return "invalid" - } else { - return "valid" - } - } - - const emailValue = email() - if (checkEmail(emailValue) === "empty") { - showToast({ - title: "Error", - variant: "danger", - message: m.newsletter_error_emptyEmail(), - }) - return - } else if (checkEmail(emailValue) === "invalid") { - showToast({ - title: "Error", - variant: "danger", - message: m.newsletter_error_invalidEmail(), - }) - return - } else if (captchaResponse() === null) { - showToast({ - title: "Error", - variant: "danger", - message: m.newsletter_error_captcha(), - }) - return - } - - fetchSubscriber(emailValue) - } - return (

{m.newsletter_title()}

-
-
- { - // @ts-ignore - setEmail(event.target.value) - }} - onPaste={(event) => { - // @ts-ignore - setEmail(event.target.value) - }} - onKeyDown={(event) => { - if (event.key === "Enter") { - handleSubscribe() - } - }} - /> - - - -
- - {m.newsletter_button()} - - } - > - - +
+