Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

simplify plain setup

Steven Tey45d646cd007d
diff --git a/apps/web/app/api/support/route.ts b/apps/web/app/api/support/route.ts
index f17e734b35..465b6d25db 100644
--- a/apps/web/app/api/support/route.ts
+++ b/apps/web/app/api/support/route.ts
@@ -3,13 +3,6 @@ import { plain, upsertPlainCustomer } from "@/lib/plain";
import z from "@/lib/zod";
import { NextResponse } from "next/server";
-export const GET = withSession(async ({ session }) => {
- const res = await upsertPlainCustomer(session);
- return NextResponse.json({
- data: res.data?.customer,
- });
-});
-
const supportRequestQuerySchema = z.object({
message: z.string().min(1),
attachmentIds: z.array(z.string()),
@@ -21,9 +14,30 @@ export const POST = withSession(async ({ req, session }) => {
await req.json(),
);
+ let plainCustomerId: string | null = null;
+
+ const plainCustomer = await plain.getCustomerByEmail({
+ email: session.user.email,
+ });
+
+ if (plainCustomer.data) {
+ plainCustomerId = plainCustomer.data.id;
+ } else {
+ const { data } = await upsertPlainCustomer(session);
+ if (data) {
+ plainCustomerId = data.customer.id;
+ }
+ }
+
+ if (!plainCustomerId) {
+ return NextResponse.json({
+ error: "Plain customer not found",
+ });
+ }
+
const res = await plain.createThread({
customerIdentifier: {
- externalId: session.user.id,
+ customerId: plainCustomerId,
},
components: [
{
@@ -35,5 +49,7 @@ export const POST = withSession(async ({ req, session }) => {
attachmentIds,
});
+ console.log({ res });
+
return NextResponse.json(res);
});
diff --git a/apps/web/ui/layout/help/portal.tsx b/apps/web/ui/layout/help/portal.tsx
index 65c7d5983a..eab535c320 100644
--- a/apps/web/ui/layout/help/portal.tsx
+++ b/apps/web/ui/layout/help/portal.tsx
@@ -1,12 +1,10 @@
"use client";
import { Popover, useResizeObserver } from "@dub/ui";
-import { fetcher } from "@dub/utils";
import va from "@vercel/analytics";
import { AnimatePresence, motion } from "framer-motion";
import { XIcon } from "lucide-react";
-import { useSession } from "next-auth/react";
-import { createContext, useEffect, useRef, useState } from "react";
+import { createContext, useRef, useState } from "react";
import { HelpArticle } from ".";
import { ContactForm } from "./contact-form";
import { HelpArticles } from "./help-articles";
@@ -28,12 +26,6 @@ export function HelpButton({
}) {
const [isOpen, setIsOpen] = useState(false);
- const { data: session } = useSession();
-
- useEffect(() => {
- session && fetcher("/api/support");
- }, [session]);
-
return (
<HelpContext.Provider value={{ popularHelpArticles, allHelpArticles }}>
<Popover