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 `showConversions` switch+logic

Tim Wilson457bd81f2bb9
diff --git a/apps/web/app/api/dashboards/route.ts b/apps/web/app/api/dashboards/route.ts
index 80f17ba9a6..d7bc8d2212 100644
--- a/apps/web/app/api/dashboards/route.ts
+++ b/apps/web/app/api/dashboards/route.ts
@@ -2,6 +2,7 @@ import { createId } from "@/lib/api/create-id";
import { getLinkOrThrow } from "@/lib/api/links/get-link-or-throw";
import { withWorkspace } from "@/lib/auth";
import { verifyFolderAccess } from "@/lib/folder/permissions";
+import { getPlanCapabilities } from "@/lib/plan-capabilities";
import {
createDashboardQuerySchema,
dashboardSchema,
@@ -30,6 +31,8 @@ export const POST = withWorkspace(
async ({ searchParams, workspace, session }) => {
const params = createDashboardQuerySchema.parse(searchParams);
+ const { canTrackConversions } = getPlanCapabilities(workspace.plan);
+
if ("key" in params) {
const { domain, key } = params;
const link = await getLinkOrThrow({
@@ -53,6 +56,7 @@ export const POST = withWorkspace(
linkId: link.id,
projectId: workspace.id,
userId: link.userId,
+ showConversions: canTrackConversions,
},
});
@@ -81,6 +85,7 @@ export const POST = withWorkspace(
folderId,
projectId: workspace.id,
userId: session.user.id,
+ showConversions: canTrackConversions,
},
});
diff --git a/apps/web/lib/zod/schemas/dashboard.ts b/apps/web/lib/zod/schemas/dashboard.ts
index 635748265c..5c8e6aad0b 100644
--- a/apps/web/lib/zod/schemas/dashboard.ts
+++ b/apps/web/lib/zod/schemas/dashboard.ts
@@ -8,6 +8,7 @@ export const dashboardSchema = z.object({
projectId: z.string().nullable(),
userId: z.string().nullable(),
password: z.string().nullable(),
+ showConversions: z.boolean(),
doIndex: z.boolean(),
createdAt: z.date(),
updatedAt: z.date(),
@@ -20,6 +21,7 @@ export const createDashboardQuerySchema = domainKeySchema.or(
);
export const updateDashboardBodySchema = dashboardSchema.pick({
+ showConversions: true,
doIndex: true,
password: true,
});
diff --git a/apps/web/ui/modals/share-dashboard-modal.tsx b/apps/web/ui/modals/share-dashboard-modal.tsx
index b7b4c3a161..0c9e771b0a 100644
--- a/apps/web/ui/modals/share-dashboard-modal.tsx
+++ b/apps/web/ui/modals/share-dashboard-modal.tsx
@@ -25,7 +25,7 @@ import {
pluralize,
} from "@dub/utils";
import { useCallback, useEffect, useMemo, useState } from "react";
-import { useForm } from "react-hook-form";
+import { Controller, useForm } from "react-hook-form";
import { toast } from "sonner";
import useSWR from "swr";
import { z } from "zod";
@@ -90,6 +90,7 @@ function ShareDashboardModalInner({
const {
register,
+ control,
handleSubmit,
watch,
setValue,
@@ -98,6 +99,7 @@ function ShareDashboardModalInner({
useEffect(() => {
setChecked(Boolean(dashboard));
+ setValue("showConversions", dashboard?.showConversions ?? false);
setValue("doIndex", dashboard?.doIndex ?? false);
setValue("password", dashboard?.password ?? null);
}, [dashboard]);
@@ -258,17 +260,34 @@ function ShareDashboardModalInner({
onSubmit={handleSubmit(handleUpdate)}
>
<p className="text-base font-medium">Settings</p>
+ <div className="flex items-center justify-between gap-2">
+ <p className="text-sm text-neutral-600">
+ Conversion analytics
+ </p>
+ <Controller
+ name="showConversions"
+ control={control}
+ render={({ field }) => (
+ <Switch
+ checked={field.value}
+ fn={(checked) => field.onChange(checked)}
+ />
+ )}
+ />
+ </div>
<div className="flex items-center justify-between gap-2">
<p className="text-sm text-neutral-600">
Search engine indexing
</p>
- <Switch
- checked={watch("doIndex")}
- fn={(checked) => {
- setValue("doIndex", checked, {
- shouldDirty: true,
- });
- }}
+ <Controller
+ name="doIndex"
+ control={control}
+ render={({ field }) => (
+ <Switch
+ checked={field.value}
+ fn={(checked) => field.onChange(checked)}
+ />
+ )}
/>
</div>
<div className="flex items-center justify-between gap-2">