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.

usePrograms

Steven Tey5d854ffc7878
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
index 80ec5af0a3..ed8f5f9d70 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/route.ts
@@ -4,43 +4,31 @@ import { withWorkspace } from "@/lib/auth";
import { dub } from "@/lib/dub";
import { getFeatureFlags } from "@/lib/edge-config";
import { prisma } from "@/lib/prisma";
-import { ProgramSchema } from "@/lib/zod/schemas/partners";
import {
WorkspaceSchema,
updateWorkspaceSchema,
} from "@/lib/zod/schemas/workspaces";
import { waitUntil } from "@vercel/functions";
import { NextResponse } from "next/server";
-import { z } from "zod";
// GET /api/workspaces/[idOrSlug] – get a specific workspace by id or slug
export const GET = withWorkspace(
async ({ workspace, headers }) => {
- const [domains, programs] = await Promise.all([
- prisma.domain.findMany({
- where: {
- projectId: workspace.id,
- },
- select: {
- slug: true,
- primary: true,
- },
- }),
- prisma.program.findMany({
- where: {
- workspaceId: workspace.id,
- },
- }),
- ]);
+ const domains = await prisma.domain.findMany({
+ where: {
+ projectId: workspace.id,
+ },
+ select: {
+ slug: true,
+ primary: true,
+ },
+ });
return NextResponse.json(
- WorkspaceSchema.extend({
- programs: z.array(ProgramSchema.pick({ id: true, name: true })),
- }).parse({
+ WorkspaceSchema.parse({
...workspace,
id: `ws_${workspace.id}`,
domains,
- programs,
flags: await getFeatureFlags({
workspaceId: workspace.id,
}),
diff --git a/apps/web/lib/swr/use-programs.ts b/apps/web/lib/swr/use-programs.ts
new file mode 100644
index 0000000000..f24ab32062
--- /dev/null
+++ b/apps/web/lib/swr/use-programs.ts
@@ -0,0 +1,22 @@
+import { fetcher } from "@dub/utils";
+import useSWR from "swr";
+import { ProgramProps } from "../types";
+import useWorkspace from "./use-workspace";
+
+export default function usePrograms() {
+ const { id: workspaceId, conversionEnabled } = useWorkspace();
+
+ const { data: programs, error } = useSWR<ProgramProps[]>(
+ conversionEnabled && `/api/programs?workspaceId=${workspaceId}`,
+ fetcher,
+ {
+ dedupingInterval: 60000,
+ },
+ );
+
+ return {
+ programs,
+ error,
+ loading: !programs && !error ? true : false,
+ };
+}
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index 4e8d4aec96..9797a352a6 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -45,7 +45,9 @@ export const WorkspaceSchema = z
stripeConnectId: z
.string()
.nullable()
- .describe("[BETA]: The Stripe Connect ID of the workspace."),
+ .describe(
+ "[BETA – Dub Conversions]: The Stripe Connect ID of the workspace.",
+ ),
usage: z.number().describe("The usage of the workspace."),
usageLimit: z.number().describe("The usage limit of the workspace."),
@@ -112,9 +114,21 @@ export const WorkspaceSchema = z
.string()
.nullable()
.describe("The publishable key of the workspace."),
- bankAccountName: z.string().nullable(),
- partialAccountNumber: z.string().nullable(),
- bankAccountVerified: z.boolean(),
+ bankAccountName: z
+ .string()
+ .nullable()
+ .describe(
+ "[BETA – Dub Partners]: The name of the connected bank account.",
+ ),
+ partialAccountNumber: z
+ .string()
+ .nullable()
+ .describe(
+ "[BETA – Dub Partners]: The partial account number of the bank account.",
+ ),
+ bankAccountVerified: z
+ .boolean()
+ .describe("[BETA – Dub Partners]: Whether the bank account is verified."),
})
.openapi({
title: "Workspace",
diff --git a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
index 3fbaff2262..12ff8a76ec 100644
--- a/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
+++ b/apps/web/ui/layout/sidebar/app-sidebar-nav.tsx
@@ -1,5 +1,6 @@
"use client";
+import usePrograms from "@/lib/swr/use-programs";
import useWorkspace from "@/lib/swr/use-workspace";
import { BetaFeatures } from "@/lib/types";
import {
@@ -238,7 +239,8 @@ export function AppSidebarNav({
}) {
const { slug } = useParams() as { slug?: string };
const pathname = usePathname();
- const { flags, programs } = useWorkspace();
+ const { flags } = useWorkspace();
+ const { programs } = usePrograms();
const currentArea = useMemo(() => {
return pathname.startsWith("/account/settings")