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.

add API routes

Steven Tey1102eab26c5b
diff --git a/apps/web/app/api/support/route.ts b/apps/web/app/api/support/route.ts
new file mode 100644
index 0000000000..e08d6fac1f
--- /dev/null
+++ b/apps/web/app/api/support/route.ts
@@ -0,0 +1,11 @@
+import { withSession } from "@/lib/auth";
+import { NextResponse } from "next/server";
+
+// POST /api/support – file a support request
+export const POST = withSession(async ({ req, session }) => {
+ const { message } = await req.json();
+
+ return NextResponse.json({
+ success: true,
+ });
+});
diff --git a/apps/web/app/api/support/upload/route.ts b/apps/web/app/api/support/upload/route.ts
new file mode 100644
index 0000000000..dfd7e3c5c0
--- /dev/null
+++ b/apps/web/app/api/support/upload/route.ts
@@ -0,0 +1,25 @@
+import { withSession } from "@/lib/auth";
+import { plain } from "@/lib/plain";
+import { AttachmentType } from "@team-plain/typescript-sdk";
+import { NextResponse } from "next/server";
+
+// POST /api/support/upload – upload a file
+export const POST = withSession(async ({ req, session }) => {
+ const res = await plain.createAttachmentUploadUrl({
+ customerId: "c_XXXXXXXXXXXXXXXXXXXXXXXXXX",
+ fileName: "the-filename.jpeg",
+ fileSizeBytes: 32318,
+ attachmentType: AttachmentType.CustomTimelineEntry,
+ });
+
+ if (res.error) {
+ console.error(res.error);
+ } else {
+ console.log("Attachment upload url created");
+ console.log(res.data);
+ }
+
+ return NextResponse.json({
+ success: true,
+ });
+});
diff --git a/apps/web/lib/plain.ts b/apps/web/lib/plain.ts
new file mode 100644
index 0000000000..ab30d9df17
--- /dev/null
+++ b/apps/web/lib/plain.ts
@@ -0,0 +1,5 @@
+import { PlainClient } from "@team-plain/typescript-sdk";
+
+export const plain = new PlainClient({
+ apiKey: process.env.PLAIN_API_KEY as string,
+});
diff --git a/apps/web/package.json b/apps/web/package.json
index bd43e710fb..5d94516358 100644
--- a/apps/web/package.json
+++ b/apps/web/package.json
@@ -24,6 +24,7 @@
"@splinetool/react-spline": "^2.2.6",
"@splinetool/runtime": "^1.0.87",
"@stripe/stripe-js": "^1.44.1",
+ "@team-plain/typescript-sdk": "^3.9.0",
"@upstash/qstash": "^2.3.0",
"@upstash/ratelimit": "^0.3.6",
"@upstash/redis": "^1.25.1",
diff --git a/apps/web/ui/layout/help-button.tsx b/apps/web/ui/layout/help-button.tsx
index d12e82fc28..d24ebdee5e 100644
--- a/apps/web/ui/layout/help-button.tsx
+++ b/apps/web/ui/layout/help-button.tsx
@@ -1,6 +1,6 @@
"use client";
-import { Button, Popover, useMediaQuery } from "@dub/ui";
+import { Button, Popover } from "@dub/ui";
import { cn } from "@dub/utils";
import { AnimatePresence, motion } from "framer-motion";
import {
@@ -13,6 +13,7 @@ import {
} from "lucide-react";
import Link from "next/link";
import { ElementType, useEffect, useRef, useState } from "react";
+import TextareaAutosize from "react-textarea-autosize";
export default function HelpButton() {
const [isOpen, setIsOpen] = useState(false);
@@ -31,12 +32,12 @@ export default function HelpButton() {
<button
type="button"
onClick={() => setIsOpen((o) => !o)}
- className="font-lg relative h-12 w-12 overflow-hidden rounded-full border border-gray-100 bg-white shadow-md active:bg-gray-50"
+ className="font-lg relative h-12 w-12 overflow-hidden rounded-full border border-gray-200 bg-white shadow-md active:bg-gray-50"
>
<AnimatePresence>
<motion.div
key={isOpen ? "open" : "closed"}
- className="absolute inset-0 flex items-center justify-center text-base font-medium text-gray-700 hover:text-blue-700"
+ className="absolute inset-0 flex items-center justify-center text-base font-medium text-gray-700 hover:text-gray-700"
initial={{ opacity: 0, scale: 0 }}
animate={{ opacity: 1, scale: 1 }}
exit={{ opacity: 0, scale: 0 }}
@@ -50,8 +51,6 @@ export default function HelpButton() {
}
function HelpSection({ onClose }: { onClose: () => void }) {
- const { isMobile } = useMediaQuery();
-
const [screen, setScreen] = useState<"main" | "contact">("main");
const [message, setMessage] = useState("");
@@ -66,14 +65,14 @@ function HelpSection({ onClose }: { onClose: () => void }) {
return (
<motion.div
- className="max-w-full sm:w-[275px]"
+ className="max-w-full sm:w-[20rem]"
animate={{ height: contentHeight }}
- transition={{ duration: 0.1 }}
+ transition={{ ease: "easeInOut" }}
>
<div ref={ref}>
{screen === "main" && (
<div className="w-full">
- <h3 className="font-semibold">Need help?</h3>
+ <h3 className="text-base font-semibold">Need help?</h3>
<p className="mt-2 text-gray-600">
Check out our help center or get in touch for more assistance.
</p>
@@ -82,7 +81,6 @@ function HelpSection({ onClose }: { onClose: () => void }) {
icon={BookOpenText}
label="Help center"
href="https://dub.co/help"
- onClick={onClose}
/>
<HelpLink
as="button"
@@ -96,27 +94,26 @@ function HelpSection({ onClose }: { onClose: () => void }) {
)}
{screen === "contact" && (
<div className="w-full">
- <h3 className="flex items-center gap-0.5 font-semibold">
- <button
- type="button"
- className="-ml-0.5 rounded-full p-0.5 hover:bg-gray-100"
- onClick={() => setScreen("main")}
- >
- <ChevronLeft className="h-4 w-4" />
- </button>
- Get in touch
- </h3>
+ <button
+ type="button"
+ className="-ml-2 flex items-center space-x-2 rounded-md px-2 py-1 hover:bg-gray-100"
+ onClick={() => setScreen("main")}
+ >
+ <ChevronLeft className="h-4 w-4" />
+ <h3 className="flex items-center gap-0.5 text-base font-semibold">
+ Contact support
+ </h3>
+ </button>
<label className="mt-5 block w-full">
<span className="block text-sm font-medium text-gray-700">
Your message
</span>
- <textarea
+ <TextareaAutosize
name="message"
required
- placeholder="How can we help?"
+ placeholder="E.g. My custom domain is not working."
value={message}
autoComplete="off"
- autoFocus={!isMobile}
onChange={(e) => setMessage(e.target.value)}
rows={3}
className={`${
@@ -127,10 +124,17 @@ function HelpSection({ onClose }: { onClose: () => void }) {
/>
</label>
{/* TODO */}
- <label className="mt-3 block flex cursor-pointer items-center gap-1 text-gray-500 hover:text-gray-700 hover:underline">
- Upload attachment <Upload className="h-3 w-3" />
+ <label className="mt-3 flex cursor-pointer items-center space-x-1 py-1">
+ <p className="text-gray-500 hover:text-gray-700 hover:underline">
+ Upload attachment
+ </p>
+ <Upload className="h-3 w-3" />
</label>
- <Button className="mt-5" text="Send message" />
+ <Button
+ className="mt-3 h-9"
+ disabled={!message}
+ text="Send message"
+ />
</div>
)}
</div>
@@ -157,7 +161,7 @@ function HelpLink<T extends ElementType = typeof Link>({
target="_blank"
className={cn(
"-mx-2 flex items-center gap-1.5 rounded-md px-2 py-1.5 font-medium text-gray-800",
- "transition-colors duration-75 hover:bg-blue-500/10 hover:text-blue-800 active:bg-blue-500/[.15]",
+ "transition-colors duration-75 hover:bg-gray-100 hover:text-gray-800 active:bg-gray-200",
)}
onClick={onClick}
>
diff --git a/apps/web/ui/layout/user-dropdown.tsx b/apps/web/ui/layout/user-dropdown.tsx
index 1910b0633f..831dcae140 100644
--- a/apps/web/ui/layout/user-dropdown.tsx
+++ b/apps/web/ui/layout/user-dropdown.tsx
@@ -1,16 +1,9 @@
"use client";
-import { Avatar, Badge, IconMenu, LoadingCircle, Popover } from "@dub/ui";
+import { Avatar, Badge, IconMenu, Popover } from "@dub/ui";
import va from "@vercel/analytics";
-import { Crisp } from "crisp-sdk-web";
import Cookies from "js-cookie";
-import {
- Edit3,
- HelpCircle,
- LogOut,
- MessageCircle,
- Settings,
-} from "lucide-react";
+import { Edit3, HelpCircle, LogOut, Settings } from "lucide-react";
import { signOut, useSession } from "next-auth/react";
import Link from "next/link";
import { useEffect, useState } from "react";
@@ -18,31 +11,6 @@ import { useEffect, useState } from "react";
export default function UserDropdown() {
const { data: session } = useSession();
const [openPopover, setOpenPopover] = useState(false);
- const [openingSupport, setOpeningSupport] = useState(false);
-
- useEffect(() => {
- Crisp.configure("2c09b1ee-14c2-46d1-bf72-1dbb998a19e0", {
- autoload: false,
- });
- }, []);
-
- useEffect(() => {
- if (session?.user?.email) {
- Crisp.user.setEmail(session.user.email);
- Crisp.user.setNickname(session.user.name || session.user.email);
- }
- }, [session]);
-
- useEffect(() => {
- Crisp.chat.onChatOpened(() => {
- va.track("Open support chat");
- setOpeningSupport(false);
- setOpenPopover(false);
- });
- Crisp.chat.onChatClosed(() => {
- Crisp.chat.hide();
- });
- }, []);
const [unreadChangelogs, setUnreadChangelogs] = useState(0);
useEffect(() => {
@@ -82,25 +50,6 @@ export default function UserDropdown() {
icon={<HelpCircle className="h-4 w-4" />}
/>
</Link>
- <button
- className="w-full rounded-md p-2 text-sm transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"
- onClick={() => {
- setOpeningSupport(true);
- Crisp.chat.open();
- Crisp.chat.show();
- }}
- >
- <IconMenu
- text="Support"
- icon={
- openingSupport ? (
- <LoadingCircle />
- ) : (
- <MessageCircle className="h-4 w-4" />
- )
- }
- />
- </button>
<Link
href="/settings"
onClick={() => setOpenPopover(false)}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3beb32fb94..9044445160 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -73,6 +73,9 @@ importers:
'@stripe/stripe-js':
specifier: ^1.44.1
version: 1.44.1
+ '@team-plain/typescript-sdk':
+ specifier: ^3.9.0
+ version: 3.9.0
'@upstash/qstash':
specifier: ^2.3.0
version: 2.3.0
@@ -3282,6 +3285,14 @@ packages:
- supports-color
dev: false
+ /@graphql-typed-document-node/[email protected]([email protected]):
+ resolution: {integrity: sha512-mB9oAsNCm9aM3/SOv4YtBMqZbYj10R7dkq8byBqxGY/ncFwhf2oQzMV+LCRlWoDSEBJ3COiR1yeDvMtsoOsuFQ==}
+ peerDependencies:
+ graphql: ^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0 || ^17.0.0
+ dependencies:
+ graphql: 16.8.1
+ dev: false
+
resolution: {integrity: sha512-iouYNlPxRAwZ2XboDT+OfRKHuaKHiqjB5VFYZ0NFrHkbEF+AV3muIUY9olQsp8uxU4VvRCMiRk9ftzFDGb61aw==}
engines: {node: ^8.13.0 || >=10.10.0}
@@ -6805,6 +6816,16 @@ packages:
tailwindcss: 3.3.3
dev: false
+ /@team-plain/[email protected]:
+ resolution: {integrity: sha512-fS22kpwPuKzXpIHs+tK+974Wx/+CPs3+vmxW1kldmuXGWZ1p8V4PdYC0R8AC0uiG9f48VX4gq6x1Uw2isPpM+w==}
+ dependencies:
+ '@graphql-typed-document-node/core': 3.2.0([email protected])
+ ajv: 8.12.0
+ ajv-formats: 2.1.1([email protected])
+ graphql: 16.8.1
+ zod: 3.22.4
+ dev: false
+
/@tediousjs/[email protected]:
resolution: {integrity: sha512-7qSgZbincDDDFyRweCIEvZULFAw5iz/DeunhvuxpL31nfntX3P4Yd4HkHBRg9H8CdqY1e5WFN1PZIz/REL9MVQ==}
dev: false
@@ -7594,6 +7615,17 @@ packages:
- supports-color
dev: false
+ resolution: {integrity: sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==}
+ peerDependencies:
+ ajv: ^8.0.0
+ peerDependenciesMeta:
+ ajv:
+ optional: true
+ dependencies:
+ ajv: 8.12.0
+ dev: false
+
resolution: {integrity: sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==}
peerDependencies:
@@ -7610,6 +7642,15 @@ packages:
json-schema-traverse: 0.4.1
uri-js: 4.4.1
+ resolution: {integrity: sha512-sRu1kpcO9yLtYxBKvqfTeh9KzZEwO3STyX1HT+4CaDzC6HpTGYhIhPIzj9XuKU7KYDwnaeh5hcOwjy1QuJzBPA==}
+ dependencies:
+ fast-deep-equal: 3.1.3
+ json-schema-traverse: 1.0.0
+ require-from-string: 2.0.2
+ uri-js: 4.4.1
+ dev: false
+
resolution: {integrity: sha512-hCv9AqTQ8ycjpSd3upOJd7vFwW1JaoYQ7tpham03GJ1ca8/65rqn0RpaWpItOAd6ylW9wAw6luXYPJIyPFVOww==}
dev: false
@@ -10066,6 +10107,11 @@ packages:
resolution: {integrity: sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag==}
+ resolution: {integrity: sha512-59LZHPdGZVh695Ud9lRzPBVTtlX9ZCV150Er2W43ro37wVof0ctenSaskPPjN7lVTIN8mSZt8PHUNKZuNQUuxw==}
+ engines: {node: ^12.22.0 || ^14.16.0 || ^16.0.0 || >=17.0.0}
+ dev: false
+
resolution: {integrity: sha512-KcFVtoP1CVFtQu0aSk3AyAt2og66PFhZAlkUOuWKwzMLoulHXG5W5wE5xAnHb+yl3/wEFoqGW7/cDGMU8igDZQ==}
engines: {node: '>=14.0.0'}
@@ -10851,6 +10897,10 @@ packages:
resolution: {integrity: sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==}
+ resolution: {integrity: sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==}
+ dev: false
+
resolution: {integrity: sha512-Bdboy+l7tA3OGW6FjyFHWkP5LuByj1Tk33Ljyq0axyzdk9//JSi2u3fP1QSmd1KNwq6VOKYGlAu87CisVir6Pw==}
@@ -13850,6 +13900,11 @@ packages:
engines: {node: '>=0.10.0'}
dev: false
+ resolution: {integrity: sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==}
+ engines: {node: '>=0.10.0'}
+ dev: false
+
resolution: {integrity: sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==}
dev: false