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 notification preference

Tim Wilsonb5790fbb00f3
diff --git a/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts b/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
index a094bca7c0..18135acbc7 100644
--- a/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
+++ b/apps/web/app/(ee)/api/cron/messages/notify-program/route.ts
@@ -50,7 +50,7 @@ export async function POST(req: Request) {
},
where: {
notificationPreference: {
- newPartnerApplication: true, // TODO
+ newMessageFromPartner: true,
},
},
},
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 cfac050216..3426916c93 100644
--- a/apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts
+++ b/apps/web/app/api/workspaces/[idOrSlug]/notification-preferences/route.ts
@@ -11,6 +11,7 @@ export const GET = withWorkspace(async ({ workspace, session }) => {
newPartnerSale: true,
newPartnerApplication: true,
newBountySubmitted: true,
+ newMessageFromPartner: true,
},
where: {
projectUser: {
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/notifications/page-client.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/notifications/page-client.tsx
index 8f9f077f0a..8cabfb6cd8 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/notifications/page-client.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/settings/(basic-layout)/notifications/page-client.tsx
@@ -4,7 +4,7 @@ import { updateNotificationPreference } from "@/lib/actions/update-notification-
import useWorkspace from "@/lib/swr/use-workspace";
import { notificationTypes } from "@/lib/zod/schemas/workspaces";
import { Switch, useOptimisticUpdate } from "@dub/ui";
-import { Globe, Hyperlink, UserPlus } from "@dub/ui/icons";
+import { Globe, Hyperlink, Msgs, UserPlus } from "@dub/ui/icons";
import { DollarSign, Trophy } from "lucide-react";
import { useAction } from "next-safe-action/hooks";
import { z } from "zod";
@@ -50,6 +50,13 @@ export default function NotificationsSettingsPageClient() {
description:
"Alert when a new bounty is submitted in your partner program.",
},
+ {
+ type: "newMessageFromPartner",
+ icon: Msgs,
+ title: "New message from partner",
+ description:
+ "Alert when a new message is received from a partner in your partner program.",
+ },
];
const {
diff --git a/apps/web/lib/zod/schemas/messages.ts b/apps/web/lib/zod/schemas/messages.ts
index 709c016df3..2a265aecd0 100644
--- a/apps/web/lib/zod/schemas/messages.ts
+++ b/apps/web/lib/zod/schemas/messages.ts
@@ -5,6 +5,8 @@ import { UserSchema } from "./users";
export const MAX_MESSAGE_LENGTH = 2000;
+const messageTextSchema = z.string().min(1).max(MAX_MESSAGE_LENGTH);
+
export const MessageSchema = z.object({
id: z.string(),
programId: z.string(),
@@ -12,7 +14,7 @@ export const MessageSchema = z.object({
senderPartnerId: z.string().nullable(),
senderUserId: z.string(),
- text: z.string().min(1).max(MAX_MESSAGE_LENGTH),
+ text: messageTextSchema,
readInApp: z.date().nullable(),
readInEmail: z.date().nullable(),
@@ -55,7 +57,7 @@ export const countMessagesQuerySchema = z.object({
export const messagePartnerSchema = z.object({
partnerId: z.string(),
- text: z.string(),
+ text: messageTextSchema,
createdAt: z.coerce
.date()
.refine(
@@ -95,7 +97,7 @@ export const getProgramMessagesQuerySchema = z.object({
export const messageProgramSchema = z.object({
programSlug: z.string(),
- text: z.string(),
+ text: messageTextSchema,
createdAt: z.coerce
.date()
.refine(
diff --git a/apps/web/lib/zod/schemas/workspaces.ts b/apps/web/lib/zod/schemas/workspaces.ts
index cf2b22f556..c7baaccf4c 100644
--- a/apps/web/lib/zod/schemas/workspaces.ts
+++ b/apps/web/lib/zod/schemas/workspaces.ts
@@ -151,6 +151,7 @@ export const notificationTypes = z.enum([
"newPartnerSale",
"newPartnerApplication",
"newBountySubmitted",
+ "newMessageFromPartner",
]);
export const WorkspaceSchemaExtended = WorkspaceSchema.extend({
diff --git a/packages/prisma/schema/workspace.prisma b/packages/prisma/schema/workspace.prisma
index 3fa563e80d..391ec793ea 100644
--- a/packages/prisma/schema/workspace.prisma
+++ b/packages/prisma/schema/workspace.prisma
@@ -127,6 +127,7 @@ model NotificationPreference {
newPartnerSale Boolean @default(true)
newPartnerApplication Boolean @default(true)
newBountySubmitted Boolean @default(true)
+ newMessageFromPartner Boolean @default(true)
projectUser ProjectUsers @relation(fields: [projectUserId], references: [id], onDelete: Cascade)
}