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.

New referral sales

Kiran Kf526164cb847
diff --git a/apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts b/apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts
index 6861c07454..51598a2fdf 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts
@@ -8,6 +8,7 @@ export const GET = withWorkspace(async ({ workspace, session }) => {
select: {
domainConfigurationUpdates: true,
linkUsageSummary: true,
+ newReferralSale: true,
},
where: {
projectUser: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/notifications/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/notifications/page-client.tsx
index 7b0b1c8a29..14d7e0d5e7 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/notifications/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/notifications/page-client.tsx
@@ -2,39 +2,49 @@
import { updateNotificationPreference } from "@/lib/actions/update-notification-preference";
import useWorkspace from "@/lib/swr/use-workspace";
+import { notificationTypes } from "@/lib/zod/schemas/workspaces";
import { Switch, useOptimisticUpdate } from "@dub/ui";
import { Globe, Hyperlink } from "@dub/ui/icons";
+import { DollarSign } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
+import { useMemo } from "react";
+import { z } from "zod";
-type PreferenceType = "linkUsageSummary" | "domainConfigurationUpdates";
-
+type PreferenceType = z.infer<typeof notificationTypes>;
type Preferences = Record<PreferenceType, boolean>;
-const notifications: {
- type: PreferenceType;
- icon: React.ElementType;
- title: string;
- description: string;
-}[] = [
- {
- type: "domainConfigurationUpdates",
- icon: Globe,
- title: "Domain configuration updates",
- description: "Updates to your custom domain configuration.",
- },
- {
- type: "linkUsageSummary",
- icon: Hyperlink,
- title: "Monthly links usage summary",
- description:
- "Monthly summary email of your top 5 links by usage & total links created.",
- },
-];
-
export default function NotificationsSettingsPageClient() {
- const { id: workspaceId } = useWorkspace();
+ const { id: workspaceId, partnersEnabled } = useWorkspace();
const { executeAsync } = useAction(updateNotificationPreference);
+ const notifications = useMemo(
+ () => [
+ {
+ type: "domainConfigurationUpdates",
+ icon: Globe,
+ title: "Domain configuration updates",
+ description: "Updates to your custom domain configuration.",
+ show: true,
+ },
+ {
+ type: "linkUsageSummary",
+ icon: Hyperlink,
+ title: "Monthly links usage summary",
+ description:
+ "Monthly summary email of your top 5 links by usage & total links created.",
+ show: true,
+ },
+ {
+ type: "newReferralSale",
+ icon: DollarSign,
+ title: "New referral sales",
+ description: "Alert when a new sale is made on your referral program.",
+ show: partnersEnabled,
+ },
+ ],
+ [partnersEnabled],
+ );
+
const {
data: preferences,
isLoading,
@@ -82,50 +92,52 @@ export default function NotificationsSettingsPageClient() {
</p>
</div>
<div className="mt-2 grid grid-cols-1 gap-3">
- {notifications.map(({ type, icon: Icon, title, description }) => (
- <div
- key={type}
- className="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 bg-white p-5"
- >
- <div className="flex min-w-0 items-center gap-4">
- <div className="hidden rounded-full border border-neutral-200 sm:block">
- <div className="rounded-full border border-white bg-gradient-to-t from-neutral-100 p-1 md:p-3">
- <Icon className="size-5" />
+ {notifications
+ .filter(({ show }) => show)
+ .map(({ type, icon: Icon, title, description }) => (
+ <div
+ key={type}
+ className="flex items-center justify-between gap-4 rounded-xl border border-neutral-200 bg-white p-5"
+ >
+ <div className="flex min-w-0 items-center gap-4">
+ <div className="hidden rounded-full border border-neutral-200 sm:block">
+ <div className="rounded-full border border-white bg-gradient-to-t from-neutral-100 p-1 md:p-3">
+ <Icon className="size-5" />
+ </div>
</div>
- </div>
- <div className="overflow-hidden">
- <div className="flex items-center gap-1.5 sm:gap-2.5">
- <div className="truncate text-sm font-medium">{title}</div>
- </div>
- <div className="mt-1 flex items-center gap-1 text-xs">
- <span className="whitespace-pre-wrap text-neutral-500">
- {description}
- </span>
+ <div className="overflow-hidden">
+ <div className="flex items-center gap-1.5 sm:gap-2.5">
+ <div className="truncate text-sm font-medium">{title}</div>
+ </div>
+ <div className="mt-1 flex items-center gap-1 text-xs">
+ <span className="whitespace-pre-wrap text-neutral-500">
+ {description}
+ </span>
+ </div>
</div>
</div>
- </div>
- <Switch
- checked={preferences?.[type] ?? false}
- disabled={isLoading}
- fn={(checked: boolean) => {
- if (!preferences) return;
+ <Switch
+ checked={preferences?.[type] ?? false}
+ disabled={isLoading}
+ fn={(checked: boolean) => {
+ if (!preferences) return;
- update(
- () =>
- handleUpdate({
- type,
- value: checked,
- currentPreferences: preferences,
- }),
- {
- ...preferences,
- [type]: checked,
- },
- );
- }}
- />
- </div>
- ))}
+ update(
+ () =>
+ handleUpdate({
+ type,
+ value: checked,
+ currentPreferences: preferences,
+ }),
+ {
+ ...preferences,
+ [type]: checked,
+ },
+ );
+ }}
+ />
+ </div>
+ ))}
</div>
</div>
);
diff --git a/apps/web/lib/actions/update-notification-preference.ts b/apps/web/lib/actions/update-notification-preference.ts
index 27bf912b63..95c1705f7c 100644
--- a/apps/web/lib/actions/update-notification-preference.ts
+++ b/apps/web/lib/actions/update-notification-preference.ts
@@ -2,11 +2,12 @@
import { prisma } from "@dub/prisma";
import z from "../zod";
+import { notificationTypes } from "../zod/schemas/workspaces";
import { authActionClient } from "./safe-action";
const schema = z.object({
workspaceId: z.string(),
- type: z.enum(["linkUsageSummary", "domainConfigurationUpdates"]),
+ type: notificationTypes,
value: z.boolean(),
});
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index a5cd2c393e..51de123ca8 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -138,3 +138,9 @@ export const createWorkspaceSchema = z.object({
export const updateWorkspaceSchema = createWorkspaceSchema.partial().extend({
allowedHostnames: z.array(z.string()).optional(),
});
+
+export const notificationTypes = z.enum([
+ "linkUsageSummary",
+ "domainConfigurationUpdates",
+ "newReferralSale",
+]);
diff --git a/packages/prisma/schema/workspace.prisma b/packages/prisma/schema/workspace.prisma
index 8f8c7d4185..735dbf5b5c 100644
--- a/packages/prisma/schema/workspace.prisma
+++ b/packages/prisma/schema/workspace.prisma
@@ -118,6 +118,7 @@ model NotificationPreference {
projectUserId String @unique
linkUsageSummary Boolean @default(true)
domainConfigurationUpdates Boolean @default(true)
+ newReferralSale Boolean @default(true)
projectUser ProjectUsers @relation(fields: [projectUserId], references: [id], onDelete: Cascade)
}