Skip to content

Commit 2a0f78c

Browse files
committed
hubspot integration
1 parent 4dc803d commit 2a0f78c

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

apps/app/app/api/capacity-notification/route.ts

+2-14
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
11
import { NextRequest, NextResponse } from "next/server";
2-
3-
async function saveEmailForNotification(email: string): Promise<boolean> {
4-
try {
5-
// TODO: Implement actual storage logic
6-
// DB? hubspot?
7-
console.log(`Saving email for capacity notification: ${email}`);
8-
9-
return true;
10-
} catch (error) {
11-
console.error("Failed to save email for notification:", error);
12-
return false;
13-
}
14-
}
2+
import { submitCapacityNotification } from "@/lib/analytics/hubspot";
153

164
export async function POST(req: NextRequest): Promise<NextResponse> {
175
try {
@@ -29,7 +17,7 @@ export async function POST(req: NextRequest): Promise<NextResponse> {
2917
);
3018
}
3119

32-
const success = await saveEmailForNotification(email);
20+
const success = await submitCapacityNotification(email);
3321

3422
if (success) {
3523
return NextResponse.json({ success: true }, { status: 200 });

apps/app/components/welcome/featured/PlayerOverlay.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export function PlayerOverlay({
9292

9393
const handleCommunityClick = () => {
9494
track("capacity_community_clicked");
95-
window.open("ttps://discord.com/invite/hxyNHeSzCK", "_blank");
95+
window.open("https://discord.com/invite/hxyNHeSzCK", "_blank");
9696
};
9797

9898
if (isLoading) {

apps/app/lib/analytics/hubspot.ts

+35
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,38 @@ export async function submitToHubspot(user: PrivyUser) {
6262
console.error("Error submitting to HubSpot:", error);
6363
}
6464
}
65+
66+
export async function submitCapacityNotification(
67+
email: string,
68+
): Promise<boolean> {
69+
try {
70+
const fields: HubspotField[] = [
71+
{ name: "email", value: email },
72+
{ name: "source", value: "capacity_notification" },
73+
];
74+
75+
const url = `https://api.hsforms.com/submissions/v3/integration/submit/${HubspotConfig.portalId}/${HubspotConfig.capacityFormId}`;
76+
77+
const response = await fetch(url, {
78+
method: "POST",
79+
headers: {
80+
"Content-Type": "application/json",
81+
},
82+
body: JSON.stringify({
83+
fields,
84+
}),
85+
});
86+
87+
if (!response.ok) {
88+
const errorData = await response.json();
89+
throw new Error(
90+
`Failed to submit to HubSpot: ${errorData.error || response.statusText}`,
91+
);
92+
}
93+
94+
return true;
95+
} catch (error) {
96+
console.error("Error submitting capacity notification to HubSpot:", error);
97+
return false;
98+
}
99+
}

apps/app/lib/env.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const IntercomConfig = z.object({
1616
const HubspotConfig = z.object({
1717
portalId: z.string().min(1),
1818
formId: z.string().min(1),
19+
capacityFormId: z.string().min(1),
1920
});
2021

2122
const MixpanelConfig = z.object({
@@ -74,6 +75,7 @@ const envConfig = {
7475
hubspot: {
7576
portalId: process.env.NEXT_PUBLIC_HUBSPOT_PORTAL_ID,
7677
formId: process.env.NEXT_PUBLIC_HUBSPOT_FORM_ID,
78+
capacityFormId: process.env.NEXT_PUBLIC_HUBSPOT_FORM_ID_CAPACITY,
7779
},
7880
} as const;
7981

0 commit comments

Comments
 (0)