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 betaTester flag in workspace endpoint

Steven Tey994b9e10fbe2
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 5fe0714a32..91996a8834 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -1,7 +1,7 @@
import { DubApiError } from "@/lib/api/errors";
import { deleteWorkspace } from "@/lib/api/workspaces";
import { withWorkspace } from "@/lib/auth";
-import { isReservedKey } from "@/lib/edge-config";
+import { isBetaTester, isReservedKey } from "@/lib/edge-config";
import { prisma } from "@/lib/prisma";
import z from "@/lib/zod";
import { WorkspaceSchema } from "@/lib/zod/schemas/workspaces";
@@ -34,10 +34,13 @@ const updateWorkspaceSchema = z.object({
// GET /api/workspaces/[idOrSlug] – get a specific workspace by id or slug
export const GET = withWorkspace(async ({ workspace, headers }) => {
+ const betaTester = await isBetaTester(workspace.id);
+
return NextResponse.json(
WorkspaceSchema.parse({
...workspace,
id: `ws_${workspace.id}`,
+ betaTester,
}),
{ headers },
);
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
index 07a4f6d916..67ee69ddf4 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/page-client.tsx
@@ -1,55 +1,23 @@
"use client";
import useWorkspace from "@/lib/swr/use-workspace";
+import ConnectStripeButton from "@/ui/workspaces/connect-stripe-button";
import DeleteWorkspace from "@/ui/workspaces/delete-workspace";
import UploadLogo from "@/ui/workspaces/upload-logo";
import WorkspaceId from "@/ui/workspaces/workspace-id";
import { Form } from "@dub/ui";
-import { Button } from "@dub/ui/src/button";
import { useRouter } from "next/navigation";
-import { useEffect, useState } from "react";
import { toast } from "sonner";
import { mutate } from "swr";
export default function WorkspaceSettingsClient() {
const router = useRouter();
- const { id, name, slug, isOwner } = useWorkspace();
-
- const [redirecting, setRedirecting] = useState(false);
-
- const redirectToStripe = async () => {
- setRedirecting(true);
- const response = await fetch(
- `/api/campaigns/connect-stripe?workspaceId=${id}`,
- {
- method: "POST",
- headers: {
- "Content-Type": "application/json",
- },
- },
- );
-
- const { url } = await response.json();
-
- window.location.href = url;
- };
-
- useEffect(() => {
- // when leave page, reset state
- return () => {
- setRedirecting(false);
- };
- }, []);
+ const { id, name, slug, isOwner, betaTester } = useWorkspace();
return (
<>
{/* TODO: Move the button to proper place */}
- <Button
- text="Connect to Stripe"
- loading={redirecting}
- onClick={redirectToStripe}
- className="max-w-xs"
- />
+ {betaTester && <ConnectStripeButton />}
<Form
title="Workspace Name"
description={`This is the name of your workspace on ${process.env.NEXT_PUBLIC_APP_NAME}.`}
diff --git a/apps/web/lib/types.ts b/apps/web/lib/types.ts
index 765fb5e7b0..23a189a5a9 100644
--- a/apps/web/lib/types.ts
+++ b/apps/web/lib/types.ts
@@ -96,6 +96,7 @@ export interface WorkspaceProps {
defaultDomains?: string[];
};
inviteCode: string;
+ betaTester?: boolean;
}
export interface UserProps {
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index ec960395b9..0e025bcdc0 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -62,6 +62,12 @@ export const WorkspaceSchema = z
.string()
.nullable()
.describe("The invite code of the workspace."),
+ betaTester: z
+ .boolean()
+ .optional()
+ .describe(
+ "Whether the workspace is enrolled in the beta testing program.",
+ ),
})
.openapi({
title: "Workspace",
diff --git a/apps/web/ui/workspaces/connect-stripe-button.tsx b/apps/web/ui/workspaces/connect-stripe-button.tsx
new file mode 100644
index 0000000000..543331928c
--- /dev/null
+++ b/apps/web/ui/workspaces/connect-stripe-button.tsx
@@ -0,0 +1,44 @@
+"use client";
+
+import useWorkspace from "@/lib/swr/use-workspace";
+import { Button } from "@dub/ui/src/button";
+import { useEffect, useState } from "react";
+
+export default function ConnectStripeButton() {
+ const { id: workspaceId } = useWorkspace();
+
+ const [redirecting, setRedirecting] = useState(false);
+
+ const redirectToStripe = async () => {
+ setRedirecting(true);
+ const response = await fetch(
+ `/api/campaigns/connect-stripe?workspaceId=${workspaceId}`,
+ {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ },
+ },
+ );
+
+ const { url } = await response.json();
+
+ window.location.href = url;
+ };
+
+ useEffect(() => {
+ // when leave page, reset state
+ return () => {
+ setRedirecting(false);
+ };
+ }, []);
+
+ return (
+ <Button
+ text="Connect to Stripe"
+ loading={redirecting}
+ onClick={redirectToStripe}
+ className="max-w-xs"
+ />
+ );
+}