Skip to content

Commit 88d29e6

Browse files
committed
feat(site): add newsleter (#2803)
## Changes - Removed a console.log statement from the SalesForm component - Added a Newsletter component to the documentation sidebar - The Newsletter component allows users to subscribe to the Rivet Newsletter - Implemented PostHog tracking for newsletter subscriptions - Added form submission handling with success state feedback
1 parent 62b95a1 commit 88d29e6

File tree

3 files changed

+57
-14
lines changed

3 files changed

+57
-14
lines changed

site/src/app/(v2)/(marketing)/sales/form.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ export function SalesForm() {
1212

1313
const data = Object.fromEntries(formData.entries().toArray());
1414

15-
console.log(data);
16-
1715
posthog.capture("survey sent", {
1816
$survey_id: "0193928a-4799-0000-8fc4-455382e21359",
1917
...data,
@@ -27,8 +25,8 @@ export function SalesForm() {
2725
<span className="text-2xl text-white mb-2 block">
2826
Thank you for your interest!
2927
</span>
30-
We will get back to you within the next few days. In the
31-
meantime, feel free to explore our{" "}
28+
We will get back to you within the next few days. In the meantime, feel
29+
free to explore our{" "}
3230
<a href="/docs" className="text-[#FF5C00] hover:underline">
3331
documentation
3432
</a>{" "}

site/src/components/DocsTableOfContents.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { motion } from "framer-motion";
66
import Link from "next/link";
77
import { useCallback, useRef, useState } from "react";
88
import { useEffect } from "react";
9+
import { Newsletter } from "./Newsletter";
910

1011
const HEADER_HEIGHT = remToPx(6.5);
1112
// const SCROLL_MARGIN = remToPx(9 /* scroll-mt-header-offset */ - HEADER_HEIGHT);
@@ -30,10 +31,7 @@ function useScrollToActiveLink(currentSection) {
3031
if (linkRelativeTop + LINK_MARGIN >= containerRect.height) {
3132
// calculate the difference between the bottom of the link and the bottom of the container
3233
const bottomDifference =
33-
linkRelativeTop +
34-
LINK_MARGIN -
35-
containerRect.height +
36-
linkRect.height;
34+
linkRelativeTop + LINK_MARGIN - containerRect.height + linkRect.height;
3735
ref.current.scrollBy(0, bottomDifference);
3836
}
3937
// if the link is above the container, scroll up by the difference in height + the height of the link itself (so it's not at the top)
@@ -51,19 +49,15 @@ function useCurrentSection(tableOfContents = []) {
5149
);
5250
const getHeadings = useCallback((tableOfContents) => {
5351
return tableOfContents
54-
.flatMap((node) => [
55-
node.id,
56-
...node.children.map((child) => child.id),
57-
])
52+
.flatMap((node) => [node.id, ...node.children.map((child) => child.id)])
5853
.map((id) => {
5954
const el = document.getElementById(id);
6055
if (!el) return null;
6156

6257
const style = window.getComputedStyle(el);
6358
const scrollMt = Number.parseFloat(style.scrollMarginTop);
6459

65-
const top =
66-
window.scrollY + el.getBoundingClientRect().top - scrollMt;
60+
const top = window.scrollY + el.getBoundingClientRect().top - scrollMt;
6761
return { id, top };
6862
})
6963
.filter((x) => x !== null);
@@ -206,6 +200,7 @@ export function DocsTableOfContents({
206200
<div className="relative">
207201
<div className="relative">
208202
<Tree sections={tableOfContents} isActive={isActive} />
203+
<Newsletter />
209204
</div>
210205
</div>
211206
</div>

site/src/components/Newsletter.tsx

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use client";
2+
3+
import posthog from "posthog-js";
4+
import { Button, Input, Label } from "@rivet-gg/components";
5+
import { useState } from "react";
6+
7+
export function Newsletter() {
8+
const [isSubmitted, setIsSubmitted] = useState(false);
9+
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
10+
if (isSubmitted) return; // Prevent multiple submissions
11+
event.preventDefault();
12+
const formData = new FormData(event.currentTarget);
13+
14+
const data = Object.fromEntries(formData.entries().toArray());
15+
16+
posthog.capture("survey sent", {
17+
$survey_id: "01983e70-b743-0000-e4a7-07ce220da177",
18+
...data,
19+
});
20+
setIsSubmitted(true);
21+
22+
const form = event.currentTarget;
23+
24+
setTimeout(() => {
25+
form.reset();
26+
setIsSubmitted(false);
27+
}, 3000);
28+
};
29+
30+
return (
31+
<form className="mt-6 px-2" onSubmit={handleSubmit}>
32+
<div className="flex flex-col gap-2">
33+
<Label htmlFor="newsletter-email" className="text-sm">
34+
Rivet Newsletter
35+
</Label>
36+
<Input
37+
type="email"
38+
required
39+
placeholder="[email protected]"
40+
className="text-sm"
41+
autoComplete="email"
42+
name="$survey_response_2adad347-bc39-48f3-b5d1-755278685c94"
43+
/>
44+
<Button variant="secondary" type="submit" size="sm">
45+
{isSubmitted ? "Subscribed" : "Subscribe"}
46+
</Button>
47+
</div>
48+
</form>
49+
);
50+
}

0 commit comments

Comments
 (0)