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.

remove workspace publishable key

Steven Tey9c6b24bc98c4
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
index a52597348f..56599a0f22 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/tokens/page-client.tsx
@@ -8,7 +8,6 @@ import { useDeleteTokenModal } from "@/ui/modals/delete-token-modal";
import { useTokenCreatedModal } from "@/ui/modals/token-created-modal";
import EmptyState from "@/ui/shared/empty-state";
import { Delete } from "@/ui/shared/icons";
-import { WorkspacePublicKey } from "@/ui/workspaces/workspace-public-key";
import {
Avatar,
Badge,
@@ -49,7 +48,6 @@ export default function TokensPageClient() {
<>
<TokenCreatedModal />
<AddEditTokenModal />
- {conversionEnabled && <WorkspacePublicKey />}
<div className="rounded-lg border border-gray-200 bg-white">
<div className="flex flex-col items-center justify-between gap-4 space-y-3 border-b border-gray-200 p-5 sm:flex-row sm:space-y-0 sm:p-10">
<div className="flex max-w-screen-sm flex-col space-y-3">
diff --git a/apps/web/lib/actions/create-publishable-key.ts b/apps/web/lib/actions/create-publishable-key.ts
index 0bc061a850..2c7ac80234 100644
--- a/apps/web/lib/actions/create-publishable-key.ts
+++ b/apps/web/lib/actions/create-publishable-key.ts
@@ -2,32 +2,32 @@
import { prisma } from "@/lib/prisma";
import { nanoid } from "@dub/utils";
+import { getProgramOrThrow } from "../api/programs/get-program";
import z from "../zod";
import { authActionClient } from "./safe-action";
const schema = z.object({
workspaceId: z.string(),
+ programId: z.string(),
});
-// Create publishable key
+// Create publishable key for program
export const createPublishableKey = authActionClient
.schema(schema)
- .action(async ({ ctx }) => {
- const { workspace } = ctx;
+ .action(async ({ ctx, parsedInput }) => {
+ const { workspaceId, programId } = parsedInput;
- if (!workspace.conversionEnabled) {
- throw new Error("Conversion is not enabled for this workspace.");
- }
+ const program = await getProgramOrThrow({ workspaceId, programId });
- if (workspace.publishableKey) {
+ if (program.publishableKey) {
throw new Error("Publishable key already exists.");
}
const publishableKey = `dub_publishable_${nanoid(24)}`;
- await prisma.project.update({
+ await prisma.program.update({
where: {
- id: workspace.id,
+ id: program.id,
},
data: {
publishableKey,
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index da4f385469..d3292cb6ef 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -101,10 +101,6 @@ export const WorkspaceSchema = z
.describe(
"The feature flags of the workspace, indicating which features are enabled.",
),
- publishableKey: z
- .string()
- .nullable()
- .describe("The publishable key of the workspace."),
bankAccountName: z
.string()
.nullable()
diff --git a/apps/web/tests/utils/schema.ts b/apps/web/tests/utils/schema.ts
index 1974fe6f0c..20396adbcc 100644
--- a/apps/web/tests/utils/schema.ts
+++ b/apps/web/tests/utils/schema.ts
@@ -63,7 +63,6 @@ export const expectedWorkspace: Partial<Project> = {
stripeId: expect.any(String),
billingCycleStart: expect.any(Number),
inviteCode: expect.any(String),
- publishableKey: expect.any(String),
usage: expect.any(Number),
usageLimit: expect.any(Number),
diff --git a/apps/web/ui/workspaces/workspace-public-key.tsx b/apps/web/ui/workspaces/workspace-public-key.tsx
deleted file mode 100644
index 9db5813561..0000000000
--- a/apps/web/ui/workspaces/workspace-public-key.tsx
+++ /dev/null
@@ -1,62 +0,0 @@
-"use client";
-
-import { createPublishableKey } from "@/lib/actions/create-publishable-key";
-import useWorkspace from "@/lib/swr/use-workspace";
-import { Button, CopyButton } from "@dub/ui";
-import { useAction } from "next-safe-action/hooks";
-import { useState } from "react";
-import { toast } from "sonner";
-import { mutate } from "swr";
-
-export const WorkspacePublicKey = () => {
- const { id, slug, publishableKey } = useWorkspace();
-
- const [publicKey, setPublicKey] = useState<string | null>(
- publishableKey || null,
- );
-
- const { executeAsync, isExecuting } = useAction(createPublishableKey, {
- onSuccess({ data }) {
- toast.success("Publishable key created successfully.");
-
- if (data?.publishableKey) {
- setPublicKey(data.publishableKey);
- }
-
- mutate(`/api/workspaces/${slug}`);
- },
- onError({ error }) {
- toast.error(error.serverError);
- },
- });
-
- return (
- <>
- <div className="rounded-lg border border-gray-200 bg-white">
- <div className="relative flex flex-col space-y-6 p-5 sm:p-10">
- <div className="flex flex-col space-y-3">
- <h2 className="text-xl font-medium">Publishable Key</h2>
- <p className="text-sm text-gray-500">
- This key can be safely used in your client-side code (for
- client-side click-tracking).
- </p>
- </div>
-
- {publicKey ? (
- <div className="flex w-full max-w-md items-center justify-between rounded-md border border-gray-300 bg-white p-2">
- <p className="text-sm text-gray-500">{publicKey}</p>
- <CopyButton value={publicKey} className="rounded-md" />
- </div>
- ) : (
- <Button
- text={isExecuting ? "Creating..." : "Create publishable key"}
- loading={isExecuting}
- className="w-fit"
- onClick={() => executeAsync({ workspaceId: id! })}
- />
- )}
- </div>
- </div>
- </>
- );
-};