forked from langfuse/langfuse-docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductUpdateSignup.tsx
More file actions
62 lines (56 loc) · 1.57 KB
/
productUpdateSignup.tsx
File metadata and controls
62 lines (56 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { cn } from "@/lib/utils";
import { useState } from "react";
export function ProductUpdateSignup(props: {
source?: string;
className?: string;
small?: boolean;
}) {
const [email, setEmail] = useState("");
const [isSubmitting, setIsSubmitting] = useState(false);
async function onSubmit(event: React.FormEvent<HTMLFormElement>) {
event.preventDefault();
setIsSubmitting(true);
const res = await fetch("/api/productUpdateSignup", {
method: "POST",
body: JSON.stringify({
email,
source: props.source ?? "Website signup",
}),
headers: {
"Content-Type": "application/json",
},
});
setIsSubmitting(false);
if (!res.ok) {
alert("Something went wrong. Please try again later.");
} else {
alert("Thanks for signing up!");
setEmail("");
}
}
return (
<form
onSubmit={onSubmit}
className={cn("flex gap-y-2 w-full flex-row max-w-sm", props.className)}
>
<Input
placeholder="Enter your email"
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
className={cn("rounded-r-none h-11 px-4 py-2", props.small && "h-9")}
/>
<Button
type="submit"
variant="secondary"
className="rounded-l-none"
disabled={isSubmitting}
size={props.small ? "sm" : "lg"}
>
{isSubmitting ? <>Submitting ...</> : <>Get updates</>}
</Button>
</form>
);
}