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 a way for users to submit their integration for review

Kiran K1e58d3b4aac1
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
index d2f01c66ce..05987a759a 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/oauth-apps/[appId]/page-client.tsx
@@ -5,6 +5,7 @@ import { clientAccessCheck } from "@/lib/api/tokens/permissions";
import useWorkspace from "@/lib/swr/use-workspace";
import { OAuthAppProps } from "@/lib/types";
import { useRemoveOAuthAppModal } from "@/ui/modals/remove-oauth-app-modal";
+import { useSubmitOAuthAppModal } from "@/ui/modals/submit-oauth-app-modal";
import AddOAuthAppForm from "@/ui/oauth-apps/add-edit-app-form";
import OAuthAppCredentials from "@/ui/oauth-apps/oauth-app-credentials";
import { ThreeDots } from "@/ui/shared/icons";
@@ -16,7 +17,7 @@ import {
TokenAvatar,
} from "@dub/ui";
import { fetcher } from "@dub/utils";
-import { ChevronLeft, RefreshCcw, Trash } from "lucide-react";
+import { ChevronLeft, RefreshCcw, Trash, Upload } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import Link from "next/link";
import { notFound, useSearchParams } from "next/navigation";
@@ -50,6 +51,11 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
oAuthApp,
});
+ const { SubmitOAuthAppModal, setShowSubmitOAuthAppModal } =
+ useSubmitOAuthAppModal({
+ oAuthApp,
+ });
+
const { error: permissionsError } = clientAccessCheck({
action: "oauth_apps.write",
role,
@@ -63,6 +69,7 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
<>
<MaxWidthWrapper className="grid max-w-screen-lg gap-8">
<RemoveOAuthAppModal />
+ <SubmitOAuthAppModal />
<Link
href={`/${slug}/settings/oauth-apps`}
className="flex items-center gap-x-1"
@@ -132,6 +139,18 @@ export default function OAuthAppManagePageClient({ appId }: { appId: string }) {
setShowRemoveOAuthAppModal(true);
}}
/>
+
+ {!oAuthApp?.verified && (
+ <Button
+ text="Submit for review"
+ variant="outline"
+ icon={<Upload className="h-4 w-4" />}
+ className="h-9 justify-start px-2"
+ onClick={() => {
+ setShowSubmitOAuthAppModal(true);
+ }}
+ />
+ )}
</div>
}
align="end"
diff --git a/apps/web/lib/actions/submit-oauth-app-for-review.ts b/apps/web/lib/actions/submit-oauth-app-for-review.ts
new file mode 100644
index 0000000000..17baaf0b09
--- /dev/null
+++ b/apps/web/lib/actions/submit-oauth-app-for-review.ts
@@ -0,0 +1,46 @@
+"use server";
+
+import { prisma } from "@/lib/prisma";
+import { sendEmail } from "emails";
+import { ratelimit } from "../upstash";
+import z from "../zod";
+import { authActionClient } from "./safe-action";
+
+const schema = z.object({
+ message: z.string().max(1000),
+ workspaceId: z.string(),
+ integrationId: z.string(),
+});
+
+// Submit an OAuth app for review
+export const submitOAuthAppForReview = authActionClient
+ .schema(schema)
+ .action(async ({ ctx, parsedInput }) => {
+ const { workspace } = ctx;
+ const { message, integrationId } = parsedInput;
+
+ const integration = await prisma.integration.findFirstOrThrow({
+ where: {
+ id: integrationId,
+ projectId: workspace.id,
+ },
+ });
+
+ const { success } = await ratelimit(1, "1 m").limit(
+ `submit-oauth-app-for-review:${integrationId}`,
+ );
+
+ if (!success) {
+ throw new Error(
+ "Rate limit exceeded. Please try again later or contact support.",
+ );
+ }
+
+ await sendEmail({
+ subject: `New OAuth App Submission: ${integration.name} by ${workspace.name}`,
+ email: "[email protected]",
+ react: message,
+ });
+
+ return { ok: true };
+ });
diff --git a/apps/web/ui/modals/submit-oauth-app-modal.tsx b/apps/web/ui/modals/submit-oauth-app-modal.tsx
new file mode 100644
index 0000000000..2c5c679d08
--- /dev/null
+++ b/apps/web/ui/modals/submit-oauth-app-modal.tsx
@@ -0,0 +1,142 @@
+import { submitOAuthAppForReview } from "@/lib/actions/submit-oauth-app-for-review";
+import useWorkspace from "@/lib/swr/use-workspace";
+import { OAuthAppProps } from "@/lib/types";
+import { BlurImage, Button, Logo, Modal } from "@dub/ui";
+import { useAction } from "next-safe-action/hooks";
+import {
+ Dispatch,
+ SetStateAction,
+ useCallback,
+ useMemo,
+ useState,
+} from "react";
+import TextareaAutosize from "react-textarea-autosize";
+import { toast } from "sonner";
+
+const DEFAULT_MESSAGE =
+ "Hey! I'm submitting my OAuth app for review. Please let me know if you have any questions or need more information.";
+
+function SubmitOAuthAppModal({
+ showSubmitOAuthAppModal,
+ setShowSubmitOAuthAppModal,
+ oAuthApp,
+}: {
+ showSubmitOAuthAppModal: boolean;
+ setShowSubmitOAuthAppModal: Dispatch<SetStateAction<boolean>>;
+ oAuthApp: Pick<OAuthAppProps, "id" | "name" | "logo" | "slug"> | undefined;
+}) {
+ const workspace = useWorkspace();
+ const [message, setMessage] = useState(DEFAULT_MESSAGE);
+
+ const { execute, isExecuting } = useAction(submitOAuthAppForReview, {
+ onSuccess: () => {
+ toast.success(
+ "OAuth app submitted for review. We'll be in touch shortly.",
+ );
+ setShowSubmitOAuthAppModal(false);
+ },
+ onError: ({ error }) => {
+ toast.error(error.serverError?.serverError);
+ },
+ });
+
+ if (!oAuthApp) {
+ return null;
+ }
+
+ return (
+ <Modal
+ showModal={showSubmitOAuthAppModal}
+ setShowModal={setShowSubmitOAuthAppModal}
+ >
+ <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">
+ {oAuthApp.logo ? (
+ <BlurImage
+ src={oAuthApp.logo}
+ alt={oAuthApp.name}
+ className="h-10 w-10 rounded-full"
+ width={20}
+ height={20}
+ />
+ ) : (
+ <Logo />
+ )}
+
+ <h3 className="text-lg font-medium">
+ Submit {oAuthApp.name} for review
+ </h3>
+
+ <p className="text-center text-sm text-gray-500">
+ Please provide any additional information or comments for us to review
+ your app.
+ </p>
+ </div>
+
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+
+ execute({
+ message,
+ integrationId: oAuthApp.id,
+ workspaceId: workspace.id!,
+ });
+ }}
+ className="flex flex-col space-y-6 bg-gray-50 px-4 py-8 text-left sm:px-16"
+ >
+ <div>
+ <TextareaAutosize
+ id="message"
+ name="message"
+ minRows={5}
+ value={message}
+ onChange={(e) => setMessage(e.target.value)}
+ className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-gray-500 focus:ring-gray-500 sm:text-sm"
+ maxLength={1000}
+ />
+ </div>
+
+ <div className="flex flex-col space-y-2 sm:flex-row sm:justify-end sm:space-x-2 sm:space-y-0">
+ <Button
+ text="Cancel"
+ variant="secondary"
+ onClick={() => setShowSubmitOAuthAppModal(false)}
+ disabled={isExecuting}
+ />
+ <Button
+ text={isExecuting ? "Submitting..." : "Submit"}
+ loading={isExecuting}
+ disabled={message.trim().length === 0}
+ type="submit"
+ />
+ </div>
+ </form>
+ </Modal>
+ );
+}
+
+export function useSubmitOAuthAppModal({
+ oAuthApp,
+}: {
+ oAuthApp: Pick<OAuthAppProps, "id" | "name" | "logo" | "slug"> | undefined;
+}) {
+ const [showSubmitOAuthAppModal, setShowSubmitOAuthAppModal] = useState(false);
+
+ const SubmitOAuthAppModalCallback = useCallback(() => {
+ return (
+ <SubmitOAuthAppModal
+ showSubmitOAuthAppModal={showSubmitOAuthAppModal}
+ setShowSubmitOAuthAppModal={setShowSubmitOAuthAppModal}
+ oAuthApp={oAuthApp}
+ />
+ );
+ }, [showSubmitOAuthAppModal, setShowSubmitOAuthAppModal, oAuthApp]);
+
+ return useMemo(
+ () => ({
+ setShowSubmitOAuthAppModal,
+ SubmitOAuthAppModal: SubmitOAuthAppModalCallback,
+ }),
+ [setShowSubmitOAuthAppModal, SubmitOAuthAppModalCallback],
+ );
+}