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 delete integration modal

Kiran Kc89a2c85da01
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/credentials.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/credentials.tsx
new file mode 100644
index 0000000000..43276beac0
--- /dev/null
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/credentials.tsx
@@ -0,0 +1,49 @@
+"use client";
+
+import { CopyButton } from "@dub/ui";
+
+export default function AppCredentials({
+ clientId,
+ clientSecret,
+}: {
+ clientId: string | null;
+ clientSecret: string | null;
+}) {
+ if (!clientId) {
+ return null;
+ }
+
+ return (
+ <div className="flex flex-col space-y-4 bg-gray-50 text-left">
+ <div className="space-y-2">
+ <label className="text-sm font-medium text-gray-500">Client ID</label>
+ <div className="flex items-center justify-between rounded-md border border-gray-300 bg-white p-3">
+ <p className="font-mono text-sm text-gray-500">{clientId}</p>
+ <div className="flex flex-col gap-2">
+ <CopyButton value={clientId} className="rounded-md" />
+ </div>
+ </div>
+ </div>
+
+ {clientSecret && (
+ <div className="space-y-2">
+ <label className="text-sm font-medium text-gray-500">
+ Client Secret
+ </label>
+ <div className="flex items-center justify-between rounded-md border border-gray-300 bg-white p-3">
+ <p className="text-nowrap font-mono text-sm text-gray-500">
+ {clientSecret}
+ </p>
+ <div className="flex flex-col gap-2">
+ <CopyButton value={clientSecret} className="rounded-md" />
+ </div>
+ </div>
+ <span className="text-xs text-red-400">
+ Be sure to copy your client secret. You won’t be able to see it
+ again.
+ </span>
+ </div>
+ )}
+ </div>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/page-client.tsx
index cb9a93488f..05ded7ae21 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/[integrationId]/page-client.tsx
@@ -2,11 +2,11 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAppProps } from "@/lib/types";
+import { useRemoveIntegrationModal } from "@/ui/modals/remove-integration-modal";
import { ThreeDots } from "@/ui/shared/icons";
import {
BlurImage,
Button,
- CopyButton,
LoadingSpinner,
MaxWidthWrapper,
Popover,
@@ -19,6 +19,7 @@ import { notFound, useSearchParams } from "next/navigation";
import { useState } from "react";
import useSWR from "swr";
import AddEditIntegrationForm from "../../add-edit-integration-form";
+import AppCredentials from "./credentials";
export default function IntegrationManagePageClient({
integrationId,
@@ -33,10 +34,10 @@ export default function IntegrationManagePageClient({
fetcher,
);
- // const { UninstallIntegrationModal, setShowUninstallIntegrationModal } =
- // useUninstallIntegrationModal({
- // integration: integration,
- // });
+ const { RemoveIntegrationModal, setShowRemoveIntegrationModal } =
+ useRemoveIntegrationModal({
+ integration,
+ });
if (isLoading) {
return <LoadingSpinner />;
@@ -49,7 +50,7 @@ export default function IntegrationManagePageClient({
return (
<>
<MaxWidthWrapper className="my-10 grid max-w-screen-lg gap-8">
- {/* <UninstallIntegrationModal /> */}
+ <RemoveIntegrationModal />
<Link
href={`/${slug}/integrations/manage`}
className="flex items-center gap-x-1"
@@ -88,7 +89,7 @@ export default function IntegrationManagePageClient({
icon={<Trash className="h-4 w-4" />}
className="h-9 justify-start px-2"
onClick={() => {
- // setShowUninstallIntegrationModal(true);
+ setShowRemoveIntegrationModal(true);
}}
/>
</div>
@@ -108,12 +109,6 @@ export default function IntegrationManagePageClient({
</button>
</Popover>
</div>
-
- {/* <div className="flex gap-12 rounded-lg border border-gray-200 bg-white p-4">
- <div className="flex items-center gap-2">
- <AddEditIntegrationForm />
- </div>
- </div> */}
</MaxWidthWrapper>
<MaxWidthWrapper className="max-w-screen-lg space-y-10">
@@ -126,49 +121,3 @@ export default function IntegrationManagePageClient({
</>
);
}
-
-const AppCredentials = ({
- clientId,
- clientSecret,
-}: {
- clientId: string | null;
- clientSecret: string | null;
-}) => {
- if (!clientId) {
- return null;
- }
-
- return (
- <div className="flex flex-col space-y-4 bg-gray-50 text-left">
- <div className="space-y-2">
- <label className="text-sm font-medium text-gray-500">Client ID</label>
- <div className="flex items-center justify-between rounded-md border border-gray-300 bg-white p-3">
- <p className="font-mono text-sm text-gray-500">{clientId}</p>
- <div className="flex flex-col gap-2">
- <CopyButton value={clientId} className="rounded-md" />
- </div>
- </div>
- </div>
-
- {clientSecret && (
- <div className="space-y-2">
- <label className="text-sm font-medium text-gray-500">
- Client Secret
- </label>
- <div className="flex items-center justify-between rounded-md border border-gray-300 bg-white p-3">
- <p className="text-nowrap font-mono text-sm text-gray-500">
- {clientSecret}
- </p>
- <div className="flex flex-col gap-2">
- <CopyButton value={clientSecret} className="rounded-md" />
- </div>
- </div>
- <span className="text-xs text-red-400">
- Be sure to copy your client secret. You won’t be able to see it
- again.
- </span>
- </div>
- )}
- </div>
- );
-};
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/page-client.tsx
index 4f5129290b..a547e936eb 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/integrations/manage/page-client.tsx
@@ -2,7 +2,7 @@
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAppProps } from "@/lib/types";
-import { MaxWidthWrapper, buttonVariants } from "@dub/ui";
+import { LoadingSpinner, MaxWidthWrapper, buttonVariants } from "@dub/ui";
import { cn, fetcher } from "@dub/utils";
import Link from "next/link";
import { redirect } from "next/navigation";
@@ -46,9 +46,13 @@ export default function IntegrationConsolePageClient() {
<MaxWidthWrapper className="flex flex-col gap-3 py-4">
<div className="grid gap-4 sm:grid-cols-3">
- {integrations?.map((integration) => (
- <IntegrationCard key={integration.id} {...integration} />
- ))}
+ {isLoading ? (
+ <LoadingSpinner />
+ ) : (
+ integrations?.map((integration) => (
+ <IntegrationCard key={integration.id} {...integration} />
+ ))
+ )}
</div>
</MaxWidthWrapper>
</>
diff --git a/apps/web/ui/modals/remove-integration-modal.tsx b/apps/web/ui/modals/remove-integration-modal.tsx
new file mode 100644
index 0000000000..63ecbd01a2
--- /dev/null
+++ b/apps/web/ui/modals/remove-integration-modal.tsx
@@ -0,0 +1,157 @@
+import useWorkspace from "@/lib/swr/use-workspace";
+import { OAuthAppProps } from "@/lib/types";
+import { BlurImage, Button, Logo, Modal, useMediaQuery } from "@dub/ui";
+import { useRouter } from "next/navigation";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import { toast } from "sonner";
+
+function RemoveIntegrationModal({
+ showRemoveIntegrationModal,
+ setShowRemoveIntegrationModal,
+ integration,
+}: {
+ showRemoveIntegrationModal: boolean;
+ setShowRemoveIntegrationModal: Dispatch<SetStateAction<boolean>>;
+ integration:
+ | Pick<
+ OAuthAppProps,
+ "id" | "name" | "description" | "logo" | "installations"
+ >
+ | undefined;
+}) {
+ const router = useRouter();
+ const { isMobile } = useMediaQuery();
+ const [deleting, setDeleting] = useState(false);
+ const { id: workspaceId, slug: workspaceSlug, logo } = useWorkspace();
+
+ const deleteIntegration = async () => {
+ setDeleting(true);
+
+ const response = await fetch(
+ `/api/oauth/apps/${integration?.id}?workspaceId=${workspaceId}`,
+ {
+ method: "DELETE",
+ headers: { "Content-Type": "application/json" },
+ },
+ );
+
+ setDeleting(false);
+
+ if (!response.ok) {
+ const { error } = await response.json();
+ throw new Error(error.message);
+ }
+
+ setShowRemoveIntegrationModal(false);
+ router.push(`/${workspaceSlug}/integrations/manage`);
+ };
+
+ if (!integration) {
+ return null;
+ }
+
+ return (
+ <Modal
+ showModal={showRemoveIntegrationModal}
+ setShowModal={setShowRemoveIntegrationModal}
+ >
+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 px-4 py-4 pt-8 sm:px-16">
+ {logo ? (
+ <BlurImage
+ src={logo}
+ alt="Workspace logo"
+ className="h-10 w-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ ) : (
+ <Logo />
+ )}
+ <h3 className="text-lg font-medium">Delete {integration.name}</h3>
+ <p className="text-center text-sm text-gray-500">
+ Deleting this integration will invalidate any access tokens authorized
+ by users. Are you sure you want to continue?
+ </p>
+ </div>
+
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+
+ toast.promise(deleteIntegration(), {
+ loading: "Deleting integration...",
+ success: "Integration deleted successfully!",
+ error: (err) => err,
+ });
+ }}
+ className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16"
+ >
+ <div>
+ <label htmlFor="verification" className="block text-sm text-gray-700">
+ To verify, type{" "}
+ <span className="font-semibold text-black">{integration.name}</span>{" "}
+ below
+ </label>
+ <div className="relative mt-1 rounded-md shadow-sm">
+ <input
+ type="text"
+ name="verification"
+ id="verification"
+ pattern={integration.name}
+ required
+ autoFocus={false}
+ autoComplete="off"
+ 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"
+ />
+ </div>
+ </div>
+
+ <Button
+ text="Confirm delete"
+ variant="danger"
+ loading={deleting}
+ autoFocus={!isMobile}
+ type="submit"
+ />
+ </form>
+ </Modal>
+ );
+}
+
+export function useRemoveIntegrationModal({
+ integration,
+}: {
+ integration:
+ | Pick<
+ OAuthAppProps,
+ "id" | "name" | "description" | "logo" | "installations"
+ >
+ | undefined;
+}) {
+ const [showRemoveIntegrationModal, setShowRemoveIntegrationModal] =
+ useState(false);
+
+ const RemoveIntegrationModalCallback = useCallback(() => {
+ return (
+ <RemoveIntegrationModal
+ showRemoveIntegrationModal={showRemoveIntegrationModal}
+ setShowRemoveIntegrationModal={setShowRemoveIntegrationModal}
+ integration={integration}
+ />
+ );
+ }, [showRemoveIntegrationModal, setShowRemoveIntegrationModal]);
+
+ return useMemo(
+ () => ({
+ setShowRemoveIntegrationModal,
+ RemoveIntegrationModal: RemoveIntegrationModalCallback,
+ }),
+ [setShowRemoveIntegrationModal, RemoveIntegrationModalCallback],
+ );
+}