The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add support for integration slug
Steven Tey150aed23b086
diff --git a/apps/web/app/api/oauth-apps/[clientId]/route.ts b/apps/web/app/api/oauth-apps/[clientId]/route.tsindex 4eeb6c9094..3ae2dea2d1 100644--- a/apps/web/app/api/oauth-apps/[clientId]/route.ts+++ b/apps/web/app/api/oauth-apps/[clientId]/route.ts@@ -33,7 +33,7 @@ export const GET = withWorkspace(// PATCH /api/oauth-apps/[clientId] – update an OAuth appexport const PATCH = withWorkspace(async ({ req, params, workspace }) => {- const { name, developer, website, redirectUri, logo, pkce } =+ const { name, slug, developer, website, redirectUri, logo, pkce } =updateOAuthAppSchema.parse(await parseRequestBody(req));const app = await prisma.oAuthApp.update({@@ -43,6 +43,7 @@ export const PATCH = withWorkspace(},data: {name,+ slug,developer,website,redirectUri,diff --git a/apps/web/app/api/oauth-apps/route.ts b/apps/web/app/api/oauth-apps/route.tsindex 9d36815e73..f21918b95e 100644--- a/apps/web/app/api/oauth-apps/route.ts+++ b/apps/web/app/api/oauth-apps/route.ts@@ -27,7 +27,7 @@ export const GET = withWorkspace(// POST /api/oauth-apps - create a new OAuth appexport const POST = withWorkspace(async ({ req, workspace, session }) => {- const { name, developer, website, redirectUri, logo, pkce } =+ const { name, slug, developer, website, redirectUri, logo, pkce } =createOAuthAppSchema.parse(await parseRequestBody(req));const clientId = createToken({@@ -44,6 +44,7 @@ export const POST = withWorkspace(data: {projectId: workspace.id,name,+ slug,developer,website,redirectUri,diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/integration-card.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/integration-card.tsxnew file mode 100644index 0000000000..3a4b661381--- /dev/null+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/integration-card.tsx@@ -0,0 +1,72 @@+import { OAuthAuthorizedAppProps } from "@/lib/types";+import { useDeleteAppModal } from "@/ui/modals/delete-oauth-app-modal";+import { Delete, ThreeDots } from "@/ui/shared/icons";+import { BlurImage, Button, Popover, TokenAvatar } from "@dub/ui";+import { useState } from "react";++export default function IntegrationCard(app: OAuthAuthorizedAppProps) {+ const [openPopover, setOpenPopover] = useState(false);++ const { DeleteAppModal, setShowDeleteAppModal } = useDeleteAppModal({+ app: {+ clientId: app.clientId,+ name: app.name,+ },+ appType: "authorized",+ });++ return (+ <>+ <DeleteAppModal />+ <div className="relative rounded-xl border border-gray-200 bg-white px-5 py-4">+ <div className="flex items-center space-x-3">+ {app.logo ? (+ <BlurImage+ src={app.logo}+ alt={`Logo for ${app.name}`}+ className="h-10 w-10 rounded-full border border-gray-200"+ width={20}+ height={20}+ />+ ) : (+ <TokenAvatar id={app.clientId} />+ )}+ <div className="flex flex-col space-y-px">+ <p className="font-semibold text-gray-700">{app.name}</p>+ <p className="text-sm text-gray-500">Installed</p>+ </div>+ </div>+ <Popover+ content={+ <div className="w-full sm:w-48">+ <div className="grid gap-px p-2">+ <Button+ text="Disconnect"+ variant="danger-outline"+ icon={<Delete className="h-4 w-4" />}+ className="h-9 justify-start px-2 font-medium"+ onClick={() => {+ setOpenPopover(false);+ setShowDeleteAppModal(true);+ }}+ />+ </div>+ </div>+ }+ align="end"+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}+ >+ <button+ onClick={() => {+ setOpenPopover(!openPopover);+ }}+ className="absolute right-4 rounded-md px-1 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"+ >+ <ThreeDots className="h-5 w-5 text-gray-500" />+ </button>+ </Popover>+ </div>+ </>+ );+}diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/page-client.tsxindex 11ed34a137..02da28be0d 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/page-client.tsx@@ -3,26 +3,21 @@import useWorkspace from "@/lib/swr/use-workspace";import { OAuthAppProps, OAuthAuthorizedAppProps } from "@/lib/types";import { useAddEditAppModal } from "@/ui/modals/add-edit-oauth-app-modal";-import { useDeleteAppModal } from "@/ui/modals/delete-oauth-app-modal";import { useAppCreatedModal } from "@/ui/modals/oauth-app-created-modal";import EmptyState from "@/ui/shared/empty-state";-import { Delete } from "@/ui/shared/icons";import {- BlurImage,Button,LoadingSpinner,MaxWidthWrapper,- Popover,- TokenAvatar,buttonVariants,} from "@dub/ui";import { Key } from "@dub/ui/src/icons";-import { cn, fetcher, formatDate } from "@dub/utils";-import { MoreVertical } from "lucide-react";+import { cn, fetcher } from "@dub/utils";import Link from "next/link";import { redirect } from "next/navigation";import { useState } from "react";import useSWR from "swr";+import IntegrationCard from "./integration-card";export default function AuthorizedAppsPageClient() {const { id: workspaceId, slug, flags } = useWorkspace();@@ -89,9 +84,9 @@ export default function AuthorizedAppsPageClient() {</p></div>) : apps.length > 0 ? (- <div className="divide-y divide-gray-200">+ <div className="grid gap-4 sm:grid-cols-3">{apps.map((app) => (- <AppRow key={app.id} {...app} />+ <IntegrationCard key={app.id} {...app} />))}</div>) : (@@ -106,74 +101,3 @@ export default function AuthorizedAppsPageClient() {</>);}--const AppRow = (app: OAuthAuthorizedAppProps) => {- const [openPopover, setOpenPopover] = useState(false);-- const { DeleteAppModal, setShowDeleteAppModal } = useDeleteAppModal({- app: {- clientId: app.clientId,- name: app.name,- },- appType: "authorized",- });-- return (- <>- <DeleteAppModal />- <div className="relative grid grid-cols-5 items-center rounded-xl border border-gray-200 bg-white px-5 py-4">- <div className="col-span-3 flex items-center space-x-3">- {app.logo ? (- <BlurImage- src={app.logo}- alt={`Logo for ${app.name}`}- className="h-10 w-10 rounded-full border border-gray-200"- width={20}- height={20}- />- ) : (- <TokenAvatar id={app.clientId} />- )}- <div className="flex flex-col space-y-px">- <p className="font-semibold text-gray-700">{app.name}</p>- <div className="flex items-center gap-x-2">- <p className="text-sm text-gray-500" suppressHydrationWarning>- Authorized by {app.user.name} on {formatDate(app.createdAt)}- </p>- </div>- </div>- </div>- <Popover- content={- <div className="w-full sm:w-48">- <div className="grid gap-px p-2">- <Button- text="Disconnect"- variant="danger-outline"- icon={<Delete className="h-4 w-4" />}- className="h-9 justify-start px-2 font-medium"- onClick={() => {- setOpenPopover(false);- setShowDeleteAppModal(true);- }}- />- </div>- </div>- }- align="end"- openPopover={openPopover}- setOpenPopover={setOpenPopover}- >- <button- onClick={() => {- setOpenPopover(!openPopover);- }}- className="absolute right-4 rounded-md px-1 py-2 transition-all duration-75 hover:bg-gray-100 active:bg-gray-200"- >- <MoreVertical className="h-5 w-5 text-gray-500" />- </button>- </Popover>- </div>- </>- );-};diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.tsindex 3cedc3018c..c13580b1aa 100644--- a/apps/web/lib/zod/schemas/oauth.ts+++ b/apps/web/lib/zod/schemas/oauth.ts@@ -3,6 +3,7 @@ import { z } from "zod";export const createOAuthAppSchema = z.object({name: z.string().min(1).max(100),+ slug: z.string().min(1).max(100),developer: z.string().min(1).max(100),website: z.string()@@ -43,6 +44,7 @@ export const oAuthAppSchema = z.object({clientId: z.string(),clientSecret: z.string().optional(),name: z.string(),+ slug: z.string(),developer: z.string(),website: z.string(),redirectUri: z.string(),diff --git a/apps/web/prisma/schema/oauth.prisma b/apps/web/prisma/schema/oauth.prismaindex 2c65a78c76..d268fd82d1 100644--- a/apps/web/prisma/schema/oauth.prisma+++ b/apps/web/prisma/schema/oauth.prisma@@ -2,6 +2,7 @@ model OAuthApp {id String @id @default(cuid())clientId String @uniquename String+ slug String @uniquedeveloper Stringwebsite StringhashedClientSecret String@@ -22,6 +23,7 @@ model OAuthApp {@@index(projectId)@@index([userId])+ @@index([slug])}model OAuthCode {diff --git a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx b/apps/web/ui/modals/add-edit-oauth-app-modal.tsxindex 196760dbd1..cf7933927f 100644--- a/apps/web/ui/modals/add-edit-oauth-app-modal.tsx+++ b/apps/web/ui/modals/add-edit-oauth-app-modal.tsx@@ -1,11 +1,13 @@import useWorkspace from "@/lib/swr/use-workspace";import { OAuthAppProps } from "@/lib/types";import { Button, ButtonProps, InfoTooltip, Logo, Modal, Switch } from "@dub/ui";+import slugify from "@sindresorhus/slugify";import {Dispatch,FormEvent,SetStateAction,useCallback,+ useEffect,useMemo,useState,} from "react";@@ -14,6 +16,7 @@ import { mutate } from "swr";const newApp: OAuthAppProps = {name: "",+ slug: "",developer: "",website: "",clientId: "",@@ -34,7 +37,7 @@ function AddEditAppModal({onAppCreated?: (App: OAuthAppProps) => void;}) {const [saving, setSaving] = useState(false);- const { id: workspaceId, logo: workspaceLogo, slug } = useWorkspace();+ const { id: workspaceId } = useWorkspace();const [data, setData] = useState<OAuthAppProps>(app || newApp);// Determine the endpoint@@ -80,8 +83,17 @@ function AddEditAppModal({}};- const { name, developer, website, redirectUri, logo, pkce } = data;- const buttonDisabled = !name || !developer || !website || !redirectUri;+ const { name, slug, developer, website, redirectUri, logo, pkce } = data;++ useEffect(() => {+ setData((prev) => ({+ ...prev,+ slug: slugify(name),+ }));+ }, [name]);++ const buttonDisabled =+ !name || !slug || !developer || !website || !redirectUri;return (<>@@ -124,6 +136,25 @@ function AddEditAppModal({</div></div>+ <div>+ <label htmlFor="slug" className="flex items-center space-x-2">+ <h2 className="text-sm font-medium text-gray-900">+ Application slug+ </h2>+ <InfoTooltip content="Unique slug for this application on Dub" />+ </label>+ <div className="relative mt-2 rounded-md shadow-sm">+ <input+ className="block w-full rounded-md border-gray-300 text-gray-900 placeholder-gray-400 focus:border-gray-500 focus:outline-none focus:ring-gray-500 sm:text-sm"+ required+ value={slug}+ onChange={(e) => setData({ ...data, slug: e.target.value })}+ autoComplete="off"+ placeholder="my-app"+ />+ </div>+ </div>+<div><label htmlFor="developer" className="flex items-center space-x-2"><h2 className="text-sm font-medium text-gray-900">