The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
fix api endpoint
Steven Tey1b7c856e9054
diff --git a/apps/web/app/api/integrations/[slug]/uninstall/route.ts b/apps/web/app/api/integrations/uninstall/route.tssimilarity index 62%rename from apps/web/app/api/integrations/[slug]/uninstall/route.tsrename to apps/web/app/api/integrations/uninstall/route.tsindex fd724ae6f0..538196077a 100644--- a/apps/web/app/api/integrations/[slug]/uninstall/route.ts+++ b/apps/web/app/api/integrations/uninstall/route.ts@@ -7,24 +7,16 @@ import { NextResponse } from "next/server";// DELETE /api/integrations/[slug]/installation - delete an installation by slugexport const DELETE = withWorkspace(- async ({ params, workspace }) => {- const integration = await prisma.oAuthAuthorizedApp.findFirst({+ async ({ searchParams, workspace }) => {+ const { installationId } = searchParams;++ const installation = await prisma.oAuthAuthorizedApp.findUnique({where: {- projectId: workspace.id,- oAuthApp: {- slug: params.slug,- },- },- select: {- id: true,- clientId: true,- userId: true,+ id: installationId,},});- console.log({ integration });-- if (!integration) {+ if (!installation) {throw new DubApiError({code: "not_found",message: "Integration not found",@@ -34,21 +26,21 @@ export const DELETE = withWorkspace(await prisma.$transaction([prisma.oAuthAuthorizedApp.delete({where: {- id: integration.id,+ id: installationId,},}),prisma.restrictedToken.delete({where: {userId_projectId_clientId: {- userId: integration.userId,+ userId: installation.userId,projectId: workspace.id,- clientId: integration.clientId,+ clientId: installation.clientId,},},}),]);- return NextResponse.json({ id: params.clientId });+ return NextResponse.json({ id: installationId });},{requiredPermissions: ["integrations.write"],diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsxindex 1340b820bf..9131fb02a8 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page-client.tsx@@ -1,7 +1,7 @@"use client";import useWorkspace from "@/lib/swr/use-workspace";-import { OAuthAppProps } from "@/lib/types";+import { IntegrationPageProps } from "@/lib/types";import { useUninstallIntegrationModal } from "@/ui/modals/uninstall-integration-modal";import { ThreeDots } from "@/ui/shared/icons";import {@@ -21,17 +21,7 @@ import { useState } from "react";export default function IntegrationPageClient({integration,}: {- integration: OAuthAppProps & {- installations: number;- installed: {- by: {- id: string;- name: string | null;- image: string | null;- };- createdAt: Date;- } | null;- };+ integration: IntegrationPageProps;}) {const { slug } = useWorkspace();@@ -44,7 +34,7 @@ export default function IntegrationPageClient({return (<MaxWidthWrapper className="my-10 grid max-w-screen-lg gap-8">- <UninstallIntegrationModal />+ {integration.installed && <UninstallIntegrationModal />}<Linkhref={`/${slug}/integrations`}className="flex items-center gap-x-1"@@ -72,35 +62,37 @@ export default function IntegrationPageClient({<p className="text-sm text-gray-500">{integration.description}</p></div></div>- <Popover- align="end"- content={- <div className="grid w-screen gap-px p-2 sm:w-48">- <Button- text="Uninstall Integration"- variant="danger-outline"- icon={<Trash className="h-4 w-4" />}- className="h-9 justify-start px-2"- onClick={() => {- setShowUninstallIntegrationModal(true);- }}- />- </div>- }- openPopover={openPopover}- setOpenPopover={setOpenPopover}- >- <button- onClick={() => setOpenPopover(!openPopover)}- className={cn(- "flex h-10 items-center rounded-md border px-1.5 outline-none transition-all",- "border-gray-200 bg-white text-gray-900 placeholder-gray-400",- "focus-visible:border-gray-500 data-[state=open]:border-gray-500 data-[state=open]:ring-4 data-[state=open]:ring-gray-200",- )}+ {integration.installed && (+ <Popover+ align="end"+ content={+ <div className="grid w-screen gap-px p-2 sm:w-48">+ <Button+ text="Uninstall Integration"+ variant="danger-outline"+ icon={<Trash className="h-4 w-4" />}+ className="h-9 justify-start px-2"+ onClick={() => {+ setShowUninstallIntegrationModal(true);+ }}+ />+ </div>+ }+ openPopover={openPopover}+ setOpenPopover={setOpenPopover}>- <ThreeDots className="h-5 w-5 text-gray-500" />- </button>- </Popover>+ <button+ onClick={() => setOpenPopover(!openPopover)}+ className={cn(+ "flex h-10 items-center rounded-md border px-1.5 outline-none transition-all",+ "border-gray-200 bg-white text-gray-900 placeholder-gray-400",+ "focus-visible:border-gray-500 data-[state=open]:border-gray-500 data-[state=open]:ring-4 data-[state=open]:ring-gray-200",+ )}+ >+ <ThreeDots className="h-5 w-5 text-gray-500" />+ </button>+ </Popover>+ )}</div><div className="flex gap-12 rounded-lg border border-gray-200 bg-white p-4">{integration.installed && (diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page.tsxindex c3884c7ce3..cc0367d9dd 100644--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page.tsx+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/[integrationSlug]/page.tsx@@ -48,6 +48,7 @@ export default async function IntegrationPage({installed:integration.authorizedApps.length > 0? {+ id: integration.authorizedApps[0].id,by: {id: integration.authorizedApps[0].userId,name: integration.authorizedApps[0].user.name,diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.tsindex e4d49a505b..4b190d2109 100644--- a/apps/web/lib/types.ts+++ b/apps/web/lib/types.ts@@ -203,7 +203,18 @@ export type TokenProps = z.infer<typeof tokenSchema>;export type OAuthAppProps = z.infer<typeof oAuthAppSchema>;-export type CreatedIntegrationProps = z.infer<typeof oAuthAppSchema>;+export type IntegrationPageProps = OAuthAppProps & {+ installations: number;+ installed: {+ id: string;+ by: {+ id: string;+ name: string | null;+ image: string | null;+ };+ createdAt: Date;+ } | null;+};export type InstalledIntegrationProps = z.infer<typeof oAuthAuthorizedAppSchemadiff --git a/apps/web/ui/modals/uninstall-integration-modal.tsx b/apps/web/ui/modals/uninstall-integration-modal.tsxindex b241e4293e..fc047f87a5 100644--- a/apps/web/ui/modals/uninstall-integration-modal.tsx+++ b/apps/web/ui/modals/uninstall-integration-modal.tsx@@ -1,5 +1,5 @@import useWorkspace from "@/lib/swr/use-workspace";-import { OAuthAppProps } from "@/lib/types";+import { IntegrationPageProps } from "@/lib/types";import {BlurImage,Button,@@ -25,12 +25,12 @@ function UninstallIntegrationModal({}: {showUninstallIntegrationModal: boolean;setShowUninstallIntegrationModal: Dispatch<SetStateAction<boolean>>;- integration: OAuthAppProps;+ integration: IntegrationPageProps;}) {const router = useRouter();const [removing, setRemoving] = useState(false);const { id: workspaceId, logo } = useWorkspace();- const { name, description, slug } = integration;+ const { name, description, installed } = integration;const { isMobile } = useMediaQuery();return (@@ -83,7 +83,7 @@ function UninstallIntegrationModal({onClick={() => {setRemoving(true);fetch(- `/api/integration/${slug}/uninstall?workspaceId=${workspaceId}`,+ `/api/integrations/uninstall?workspaceId=${workspaceId}&installationId=${installed?.id}`,{method: "DELETE",headers: { "Content-Type": "application/json" },@@ -108,7 +108,7 @@ function UninstallIntegrationModal({export function useUninstallIntegrationModal({integration,}: {- integration: OAuthAppProps;+ integration: IntegrationPageProps;}) {const [showUninstallIntegrationModal, setShowUninstallIntegrationModal] =useState(false);