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 manage integration / create new integration form

Steven Teybae4f274360e
diff --git a/apps/web/app/api/oauth/apps/[appId]/route.ts b/apps/web/app/api/oauth/apps/[appId]/route.ts
index fb596fa9ab..5ad1d2cbd6 100644
--- a/apps/web/app/api/oauth/apps/[appId]/route.ts
+++ b/apps/web/app/api/oauth/apps/[appId]/route.ts
@@ -1,11 +1,11 @@
import { DubApiError } from "@/lib/api/errors";
import { parseRequestBody } from "@/lib/api/utils";
import { withWorkspace } from "@/lib/auth";
+import { deleteScreenshots } from "@/lib/integrations/utils";
import { prisma } from "@/lib/prisma";
import { storage } from "@/lib/storage";
import { oAuthAppSchema, updateOAuthAppSchema } from "@/lib/zod/schemas/oauth";
import { nanoid, R2_URL } from "@dub/utils";
-import { Prisma } from "@prisma/client";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
@@ -222,21 +222,3 @@ export const DELETE = withWorkspace(
featureFlag: "integrations",
},
);
-
-const deleteScreenshots = async (screenshots: Prisma.JsonValue | null) => {
- const images = screenshots as string[];
-
- if (!images || images.length === 0) {
- return;
- }
-
- const res = await Promise.all(
- images.map(async (image: string) => {
- if (image.startsWith(`${R2_URL}/integration-screenshots`)) {
- return storage.delete(image.replace(`${R2_URL}/`, ""));
- }
- }),
- );
-
- console.log({ res });
-};
diff --git a/apps/web/app/api/slack/callback/route.ts b/apps/web/app/api/slack/callback/route.ts
index 22724d4c51..1ee45ae1ab 100644
--- a/apps/web/app/api/slack/callback/route.ts
+++ b/apps/web/app/api/slack/callback/route.ts
@@ -6,7 +6,7 @@ import { SlackCredential } from "@/lib/integrations/slack/type";
import { prisma } from "@/lib/prisma";
import { redis } from "@/lib/upstash";
import z from "@/lib/zod";
-import { getSearchParams } from "@dub/utils";
+import { APP_DOMAIN_WITH_NGROK, getSearchParams } from "@dub/utils";
import { Project } from "@prisma/client";
import { redirect } from "next/navigation";
@@ -57,6 +57,10 @@ export const GET = async (req: Request) => {
formData.append("code", code);
formData.append("client_id", env.SLACK_CLIENT_ID);
formData.append("client_secret", env.SLACK_CLIENT_SECRET);
+ formData.append(
+ "redirect_uri",
+ `${APP_DOMAIN_WITH_NGROK}/api/slack/callback`,
+ );
const response = await fetch("https://slack.com/api/oauth.v2.access", {
method: "POST",
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/manage/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/manage/page.tsx
new file mode 100644
index 0000000000..4fe0d0e0fe
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/[integrationSlug]/manage/page.tsx
@@ -0,0 +1,46 @@
+import { prisma } from "@/lib/prisma";
+import AddEditIntegrationForm from "@/ui/oauth-apps/add-edit-integration-form";
+import { MaxWidthWrapper } from "@dub/ui";
+import { ChevronLeft } from "lucide-react";
+import Link from "next/link";
+import { notFound } from "next/navigation";
+
+export default async function IntegrationManagePage({
+ params,
+}: {
+ params: { slug: string; integrationSlug: string };
+}) {
+ // this is only available for Dub workspace for now
+ // we might open this up to other workspaces in the future
+ if (params.slug !== "dub") {
+ notFound();
+ }
+ const integration = await prisma.integration.findUnique({
+ where: {
+ slug: params.integrationSlug,
+ },
+ });
+ if (!integration) {
+ notFound();
+ }
+ return (
+ <MaxWidthWrapper className="grid max-w-screen-lg gap-8">
+ <Link
+ href={`/${params.slug}/settings/integrations`}
+ className="flex items-center gap-x-1"
+ >
+ <ChevronLeft className="size-4" />
+ <p className="text-sm font-medium text-gray-500">
+ Back to integrations
+ </p>
+ </Link>
+
+ <AddEditIntegrationForm
+ integration={{
+ ...integration,
+ screenshots: integration.screenshots as string[],
+ }}
+ />
+ </MaxWidthWrapper>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/new/page.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/new/page.tsx
new file mode 100644
index 0000000000..d2d6b1a0e1
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/integrations/new/page.tsx
@@ -0,0 +1,45 @@
+import AddEditIntegrationForm from "@/ui/oauth-apps/add-edit-integration-form";
+import { MaxWidthWrapper } from "@dub/ui";
+import { ChevronLeft } from "lucide-react";
+import Link from "next/link";
+import { notFound } from "next/navigation";
+
+export default function NewIntegrationsPage({
+ params,
+}: {
+ params: { slug: string };
+}) {
+ // this is only available for Dub workspace for now
+ // we might open this up to other workspaces in the future
+ if (params.slug !== "dub") {
+ notFound();
+ }
+ return (
+ <MaxWidthWrapper className="grid max-w-screen-lg gap-8">
+ <Link
+ href={`/${params.slug}/settings/integrations`}
+ className="flex items-center gap-x-1"
+ >
+ <ChevronLeft className="size-4" />
+ <p className="text-sm font-medium text-gray-500">
+ Back to integrations
+ </p>
+ </Link>
+
+ <AddEditIntegrationForm
+ integration={{
+ name: "",
+ slug: "",
+ description: "",
+ readme: "",
+ developer: "",
+ website: "",
+ logo: null,
+ screenshots: [],
+ createdAt: new Date(),
+ updatedAt: new Date(),
+ }}
+ />
+ </MaxWidthWrapper>
+ );
+}
diff --git a/apps/web/lib/actions/add-edit-integration.ts b/apps/web/lib/actions/add-edit-integration.ts
new file mode 100644
index 0000000000..9e87db659e
--- /dev/null
+++ b/apps/web/lib/actions/add-edit-integration.ts
@@ -0,0 +1,83 @@
+"use server";
+
+import { prisma } from "@/lib/prisma";
+import { DUB_WORKSPACE_ID, nanoid, R2_URL } from "@dub/utils";
+import { waitUntil } from "@vercel/functions";
+import { deleteScreenshots } from "../integrations/utils";
+import { isStored, storage } from "../storage";
+import z from "../zod";
+import { createIntegrationSchema } from "../zod/schemas/integration";
+import { authActionClient } from "./safe-action";
+
+export const addEditIntegration = authActionClient
+ .schema(
+ createIntegrationSchema.merge(
+ z.object({
+ id: z.string().optional(), // if id is provided, we are editing the integration
+ workspaceId: z.string(),
+ }),
+ ),
+ )
+ .action(async ({ parsedInput }) => {
+ const { id, workspaceId, ...integration } = parsedInput;
+
+ // this is only available for Dub workspace for now
+ // we might open this up to other workspaces in the future
+ if (workspaceId !== DUB_WORKSPACE_ID) {
+ throw new Error("Not authorized");
+ }
+
+ if (integration.logo && !isStored(integration.logo)) {
+ const result = await storage.upload(
+ `integrations/${id}_${nanoid(7)}`,
+ integration.logo,
+ );
+ integration.logo = result.url;
+ }
+
+ if (id) {
+ const oldIntegration = await prisma.integration.findUniqueOrThrow({
+ where: { id },
+ });
+
+ await prisma.integration.update({
+ where: { id },
+ data: integration,
+ });
+
+ waitUntil(
+ (async () => {
+ const logoUpdated = integration.logo !== oldIntegration.logo;
+ if (
+ logoUpdated &&
+ integration.logo &&
+ integration.logo.startsWith(`${R2_URL}/integrations/${id}`)
+ ) {
+ await storage.delete(integration.logo.replace(`${R2_URL}/`, ""));
+ }
+
+ const removedScreenshots =
+ oldIntegration.screenshots &&
+ Array.isArray(oldIntegration.screenshots)
+ ? oldIntegration.screenshots.filter(
+ (s) =>
+ typeof s === "string" &&
+ !integration.screenshots.includes(s),
+ )
+ : [];
+
+ if (removedScreenshots.length > 0) {
+ await deleteScreenshots(removedScreenshots);
+ }
+ })(),
+ );
+ } else {
+ await prisma.integration.create({
+ data: {
+ ...integration,
+ projectId: workspaceId,
+ },
+ });
+ }
+ return { ok: true };
+ });
diff --git a/apps/web/lib/integrations/slack/slash-commands.ts b/apps/web/lib/integrations/slack/slash-commands.ts
index 2f65ea866f..9664528e8a 100644
--- a/apps/web/lib/integrations/slack/slash-commands.ts
+++ b/apps/web/lib/integrations/slack/slash-commands.ts
@@ -35,17 +35,11 @@ export const handleSlashCommand = async (
const installation = await prisma.installedIntegration.findFirst({
where: {
- integration: {
- slug: "slack",
+ integrationId: "clzu59rx9000110bm5fnlzwuj",
+ credentials: {
+ path: "$.team.id",
+ equals: data.team_id,
},
- AND: [
- {
- credentials: {
- path: "$.team.id",
- equals: data.team_id,
- },
- },
- ],
},
});
@@ -90,8 +84,8 @@ const createShortLink = async ({
workspace: Pick<WorkspaceProps, "id" | "plan">;
installation: InstalledIntegration;
}) => {
- const [url, key] = data.text;
- const body = createLinkBodySchema.parse({ url, key });
+ const [url, key, domain] = data.text;
+ const body = createLinkBodySchema.parse({ url, key, domain });
const { link, error } = await processLink({
payload: body,
diff --git a/apps/web/lib/integrations/utils.ts b/apps/web/lib/integrations/utils.ts
new file mode 100644
index 0000000000..41d0991d86
--- /dev/null
+++ b/apps/web/lib/integrations/utils.ts
@@ -0,0 +1,21 @@
+import { storage } from "@/lib/storage";
+import { R2_URL } from "@dub/utils";
+import { Prisma } from "@prisma/client";
+
+export const deleteScreenshots = async (
+ screenshots: Prisma.JsonValue | null,
+) => {
+ const images = screenshots as string[];
+
+ if (!images || images.length === 0) {
+ return;
+ }
+
+ return await Promise.all(
+ images.map(async (image: string) => {
+ if (image.startsWith(`${R2_URL}/integration-screenshots`)) {
+ return storage.delete(image.replace(`${R2_URL}/`, ""));
+ }
+ }),
+ );
+};
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 8f844976f3..be9e04a84f 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -203,6 +203,13 @@ export type ExistingOAuthApp = OAuthAppProps;
export type IntegrationProps = z.infer<typeof integrationSchema>;
+export type NewOrExistingIntegration = Omit<
+ IntegrationProps,
+ "id" | "verified" | "installations"
+> & {
+ id?: string;
+};
+
export type InstalledIntegrationProps = Pick<
IntegrationProps,
"id" | "slug" | "logo" | "name" | "developer" | "description"
diff --git a/apps/web/lib/zod/schemas/integration.ts b/apps/web/lib/zod/schemas/integration.ts
index 10b1b79bf8..bd44fcd418 100644
--- a/apps/web/lib/zod/schemas/integration.ts
+++ b/apps/web/lib/zod/schemas/integration.ts
@@ -1,3 +1,4 @@
+import { R2_URL } from "@dub/utils";
import { z } from "zod";
export const integrationSchema = z.object({
@@ -16,3 +17,44 @@ export const integrationSchema = z.object({
updatedAt: z.date(),
installations: z.number().default(0),
});
+
+export const createIntegrationSchema = 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()
+ .url({
+ message: "website must be a valid URL",
+ })
+ .max(100),
+ logo: z
+ .string()
+ .url({
+ message: "Please provide a valid URL for the logo",
+ })
+ .nullish(),
+ description: z
+ .string()
+ .max(120, {
+ message: "must be less than 120 characters",
+ })
+ .nullish(),
+ readme: z
+ .string()
+ .max(1000, {
+ message: "must be less than 1000 characters",
+ })
+ .nullish(),
+ screenshots: z
+ .array(z.string())
+ .max(4, {
+ message: "only 4 screenshots are allowed",
+ })
+ .transform((screenshots) =>
+ screenshots.map((screenshot) =>
+ screenshot.startsWith(R2_URL) ? screenshot : `${R2_URL}/${screenshot}`,
+ ),
+ )
+ .default([]),
+});
diff --git a/apps/web/lib/zod/schemas/oauth.ts b/apps/web/lib/zod/schemas/oauth.ts
index a15ef6f246..e59013f252 100644
--- a/apps/web/lib/zod/schemas/oauth.ts
+++ b/apps/web/lib/zod/schemas/oauth.ts
@@ -1,72 +1,6 @@
import { OAUTH_SCOPES } from "@/lib/api/oauth/constants";
-import { R2_URL } from "@dub/utils";
import { z } from "zod";
-import { integrationSchema } from "./integration";
-
-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()
- .url({
- message: "website must be a valid URL",
- })
- .max(100),
- logo: z
- .string()
- .url({
- message: "Please provide a valid URL for the logo",
- })
- .nullable(),
- redirectUris: z
- .string()
- .array()
- .min(1, {
- message: "At least one redirect URI is required",
- })
- .max(5, {
- message: "only 5 redirect URIs are allowed",
- })
- .refine(
- (urls) => {
- return urls.every(
- (url) =>
- url.startsWith("https://") || url.startsWith("http://localhost"),
- );
- },
- {
- message:
- "redirect_uri must be a valid URL starting with 'https://' except for 'http://localhost'",
- },
- ),
- description: z
- .string()
- .max(120, {
- message: "must be less than 120 characters",
- })
- .nullable(),
- readme: z
- .string()
- .max(1000, {
- message: "must be less than 1000 characters",
- })
- .nullable(),
- pkce: z.boolean().default(false),
- screenshots: z
- .array(z.string())
- .max(4, {
- message: "only 4 screenshots are allowed",
- })
- .transform((screenshots) =>
- screenshots.map((screenshot) =>
- screenshot.startsWith(R2_URL) ? screenshot : `${R2_URL}/${screenshot}`,
- ),
- )
- .default([]),
-});
-
-export const updateOAuthAppSchema = createOAuthAppSchema.partial();
+import { createIntegrationSchema, integrationSchema } from "./integration";
export const oAuthAppSchema = integrationSchema.merge(
z.object({
@@ -77,6 +11,35 @@ export const oAuthAppSchema = integrationSchema.merge(
}),
);
+export const createOAuthAppSchema = createIntegrationSchema.merge(
+ z.object({
+ redirectUris: z
+ .string()
+ .array()
+ .min(1, {
+ message: "At least one redirect URI is required",
+ })
+ .max(5, {
+ message: "only 5 redirect URIs are allowed",
+ })
+ .refine(
+ (urls) => {
+ return urls.every(
+ (url) =>
+ url.startsWith("https://") || url.startsWith("http://localhost"),
+ );
+ },
+ {
+ message:
+ "redirect_uri must be a valid URL starting with 'https://' except for 'http://localhost'",
+ },
+ ),
+ pkce: z.boolean().default(false),
+ }),
+);
+
+export const updateOAuthAppSchema = createOAuthAppSchema.partial();
+
// Schema for OAuth2.0 Authorization request
export const authorizeRequestSchema = z.object({
client_id: z.string().min(1, "Missing client_id"),
diff --git a/apps/web/ui/oauth-apps/add-edit-integration-form.tsx b/apps/web/ui/oauth-apps/add-edit-integration-form.tsx
new file mode 100644
index 0000000000..5d18bc3051
--- /dev/null
+++ b/apps/web/ui/oauth-apps/add-edit-integration-form.tsx
@@ -0,0 +1,360 @@
+"use client";
+
+import { addEditIntegration } from "@/lib/actions/add-edit-integration";
+import { clientAccessCheck } from "@/lib/api/tokens/permissions";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { NewOrExistingIntegration } from "@/lib/types";
+import { Button, FileUpload, InfoTooltip, LoadingSpinner } from "@dub/ui";
+import { cn } from "@dub/utils";
+import slugify from "@sindresorhus/slugify";
+import { Reorder } from "framer-motion";
+import { Paperclip, Trash2 } from "lucide-react";
+import { useAction } from "next-safe-action/hooks";
+import { useEffect, useState } from "react";
+import TextareaAutosize from "react-textarea-autosize";
+import { toast } from "sonner";
+
+export default function AddEditIntegrationForm({
+ integration,
+}: {
+ integration: NewOrExistingIntegration;
+}) {
+ const { id: workspaceId, role } = useWorkspace();
+ const [screenshots, setScreenshots] = useState<
+ {
+ file?: File;
+ key?: string;
+ uploading: boolean;
+ }[]
+ >(
+ (integration.screenshots || []).map((s) => ({
+ uploading: false,
+ key: s,
+ })),
+ );
+
+ const [data, setData] = useState<NewOrExistingIntegration>(integration);
+
+ const { error: permissionsError } = clientAccessCheck({
+ action: "oauth_apps.write",
+ role,
+ });
+
+ useEffect(() => {
+ if (!integration.slug) {
+ setData((prev) => ({
+ ...prev,
+ slug: slugify(name),
+ }));
+ }
+ }, [integration.slug]);
+
+ // Handle screenshots upload
+ const handleUpload = async (file: File) => {
+ setScreenshots((prev) => [...prev, { file, uploading: true }]);
+
+ const response = await fetch(
+ `/api/oauth/apps/upload-url?workspaceId=${workspaceId}`,
+ {
+ method: "POST",
+ },
+ );
+
+ if (!response.ok) {
+ toast.error("Failed to get signed URL for screenshot upload.");
+ return;
+ }
+
+ const { signedUrl, key } = await response.json();
+
+ const uploadResponse = await fetch(signedUrl, {
+ method: "PUT",
+ body: file,
+ headers: {
+ "Content-Type": file.type,
+ "Content-Length": file.size.toString(),
+ },
+ });
+
+ if (!uploadResponse.ok) {
+ const result = await uploadResponse.json();
+ toast.error(result.error.message || "Failed to upload screenshot.");
+ return;
+ }
+
+ toast.success(`${file.name} uploaded!`);
+ setScreenshots((prev) =>
+ prev.map((screenshot) =>
+ screenshot.file === file
+ ? { ...screenshot, uploading: false, key }
+ : screenshot,
+ ),
+ );
+ };
+
+ const { name, slug, description, readme, developer, website, logo } = data;
+
+ const buttonDisabled = !name || !slug || !developer || !website;
+ const uploading = screenshots.some((s) => s.uploading);
+ const canManageApp = !permissionsError;
+
+ const { executeAsync, isExecuting } = useAction(addEditIntegration, {
+ onSuccess: () => {
+ toast.success(`Integration ${integration.id ? "updated" : "created"}`);
+ },
+ onError: ({ error }) => {
+ toast.error(
+ error.validationErrors?.[0]?.message || "Failed to update integration",
+ );
+ },
+ });
+
+ return (
+ <>
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ await executeAsync({
+ ...data,
+ screenshots: screenshots
+ .map((s) => s.key)
+ .filter(Boolean) as string[],
+ workspaceId: workspaceId!.replace("ws_", ""),
+ });
+ }}
+ className="flex flex-col space-y-5 pb-20 text-left"
+ >
+ <div>
+ <FileUpload
+ accept="images"
+ className="h-24 w-24 rounded-full border border-gray-300"
+ iconClassName="w-5 h-5"
+ variant="plain"
+ readFile
+ imageSrc={
+ logo ||
+ `https://api.dicebear.com/7.x/shapes/svg?seed=${integration.slug}`
+ }
+ onChange={({ src }) => setData({ ...data, logo: src })}
+ content={null}
+ maxFileSizeMB={2}
+ disabled={!canManageApp}
+ />
+ </div>
+
+ <div>
+ <label htmlFor="name" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Application name
+ </h2>
+ <InfoTooltip content="Application name will be displayed in the OAuth consent screen" />
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <input
+ className={cn(
+ "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",
+ {
+ "cursor-not-allowed bg-gray-50": !canManageApp,
+ },
+ )}
+ required
+ value={name}
+ onChange={(e) => setData({ ...data, name: e.target.value })}
+ autoFocus
+ autoComplete="off"
+ placeholder="My App"
+ disabled={!canManageApp}
+ />
+ </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={cn(
+ "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",
+ {
+ "cursor-not-allowed bg-gray-50": !canManageApp,
+ },
+ )}
+ required
+ value={slug}
+ onChange={(e) => setData({ ...data, slug: e.target.value })}
+ autoComplete="off"
+ placeholder="my-app"
+ disabled={!canManageApp}
+ />
+ </div>
+ </div>
+
+ <div>
+ <label htmlFor="slug" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Description</h2>
+ <InfoTooltip content="Description of your application" />
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <TextareaAutosize
+ name="description"
+ minRows={2}
+ className={cn(
+ "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",
+ {
+ "cursor-not-allowed bg-gray-50": !canManageApp,
+ },
+ )}
+ placeholder="Add a description"
+ value={description || ""}
+ maxLength={120}
+ onChange={(e) => {
+ setData({ ...data, description: e.target.value });
+ }}
+ disabled={!canManageApp}
+ />
+ </div>
+ </div>
+
+ <div>
+ <label htmlFor="slug" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Overview</h2>
+ <InfoTooltip content="Provide some details about your integration. This will be displayed on the integration page. Markdown is supported." />
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <TextareaAutosize
+ name="readme"
+ minRows={10}
+ className={cn(
+ "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",
+ {
+ "cursor-not-allowed bg-gray-50": !canManageApp,
+ },
+ )}
+ placeholder="## My Awesome Integration"
+ value={readme || ""}
+ maxLength={1000}
+ onChange={(e) => {
+ setData({ ...data, readme: e.target.value });
+ }}
+ disabled={!canManageApp}
+ />
+ </div>
+ </div>
+
+ <div>
+ <label htmlFor="slug" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Screenshots</h2>
+ <InfoTooltip content="You can upload up to 4 screenshots that will be displayed on the integration page." />
+ </label>
+ <Reorder.Group
+ axis="y"
+ values={screenshots}
+ onReorder={setScreenshots}
+ className="mt-2 grid w-full gap-2"
+ >
+ {screenshots.map((screenshot) => (
+ <Reorder.Item
+ key={screenshot.key}
+ value={screenshot}
+ className="group flex w-full items-center justify-between rounded-md border border-gray-200 bg-white transition-shadow hover:cursor-grab active:cursor-grabbing active:shadow-lg"
+ >
+ <div className="flex flex-1 items-center space-x-2 p-2">
+ {screenshot.uploading ? (
+ <LoadingSpinner className="h-4 w-4" />
+ ) : (
+ <Paperclip className="h-4 w-4 text-gray-500" />
+ )}
+ <p className="text-center text-sm text-gray-500">
+ {screenshot.file?.name || screenshot.key}
+ </p>
+ </div>
+ <button
+ disabled={!canManageApp}
+ className="h-full rounded-r-md border-l border-gray-200 p-2"
+ onClick={() => {
+ setScreenshots((prev) =>
+ prev.filter((s) => s.key !== screenshot.key),
+ );
+ }}
+ >
+ <Trash2 className="h-4 w-4 text-gray-500" />
+ </button>
+ </Reorder.Item>
+ ))}
+ </Reorder.Group>
+
+ <FileUpload
+ accept="any"
+ className="mt-2 aspect-[5/1] w-full rounded-md border border-dashed border-gray-300"
+ iconClassName="w-5 h-5"
+ variant="plain"
+ onChange={async ({ file }) => await handleUpload(file)}
+ content="Drag and drop or click to upload screenshots"
+ disabled={!canManageApp || screenshots.length >= 4}
+ />
+ </div>
+
+ <div>
+ <label htmlFor="developer" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">
+ Developer name
+ </h2>
+ <InfoTooltip content="The person or company developing this application" />
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <input
+ className={cn(
+ "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",
+ {
+ "cursor-not-allowed bg-gray-50": !canManageApp,
+ },
+ )}
+ required
+ value={developer}
+ onChange={(e) => setData({ ...data, developer: e.target.value })}
+ placeholder="Acme Inc."
+ disabled={!canManageApp}
+ />
+ </div>
+ </div>
+
+ <div>
+ <label htmlFor="website" className="flex items-center space-x-2">
+ <h2 className="text-sm font-medium text-gray-900">Website URL</h2>
+ <InfoTooltip content="URL to the developer's website or documentation" />
+ </label>
+ <div className="relative mt-2 rounded-md shadow-sm">
+ <input
+ className={cn(
+ "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",
+ {
+ "cursor-not-allowed bg-gray-50": !canManageApp,
+ },
+ )}
+ type="url"
+ required
+ value={website}
+ onChange={(e) => setData({ ...data, website: e.target.value })}
+ placeholder="https://acme.com"
+ disabled={!canManageApp}
+ />
+ </div>
+ </div>
+
+ <Button
+ text={integration.id ? "Save changes" : "Create"}
+ disabled={buttonDisabled || uploading || isExecuting}
+ loading={isExecuting}
+ type="submit"
+ {...(permissionsError && {
+ disabledTooltip: permissionsError,
+ })}
+ />
+ </form>
+ </>
+ );
+}
diff --git a/apps/web/ui/oauth-apps/integration-card.tsx b/apps/web/ui/oauth-apps/integration-card.tsx
index 23ed6f08d6..286036a151 100644
--- a/apps/web/ui/oauth-apps/integration-card.tsx
+++ b/apps/web/ui/oauth-apps/integration-card.tsx
@@ -51,7 +51,10 @@ export default function IntegrationCard(
</p>
<div className="flex items-center justify-end gap-1 text-gray-500">
<Download className="size-4" />
- <span className="text-sm">{integration.installations} installs</span>
+ <span className="text-sm">
+ {integration.installations} install
+ {integration.installations === 1 ? "" : "s"}
+ </span>
</div>
</div>
</Link>