fix: ensure we dont bloat notification table with any other notification than app
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { useAppParams } from '@/hooks/useAppParams';
|
||||
import useWS from '@/hooks/useWS';
|
||||
import type { Notification } from '@openpanel/db';
|
||||
import type { Prisma } from '@openpanel/db';
|
||||
import { BellIcon } from 'lucide-react';
|
||||
import { toast } from 'sonner';
|
||||
|
||||
@@ -15,12 +15,15 @@ export function NotificationProvider() {
|
||||
export function InnerNotificationProvider({
|
||||
projectId,
|
||||
}: { projectId: string }) {
|
||||
useWS<Notification>(`/live/notifications/${projectId}`, (notification) => {
|
||||
toast(notification.title, {
|
||||
description: notification.message,
|
||||
icon: <BellIcon className="size-4" />,
|
||||
});
|
||||
});
|
||||
useWS<Prisma.NotificationUncheckedCreateInput>(
|
||||
`/live/notifications/${projectId}`,
|
||||
(notification) => {
|
||||
toast(notification.title, {
|
||||
description: notification.message,
|
||||
icon: <BellIcon className="size-4" />,
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -46,14 +46,6 @@ export function useColumns() {
|
||||
);
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'integration',
|
||||
header: 'Integration',
|
||||
cell({ row }) {
|
||||
const integration = row.original.integration;
|
||||
return <div>{integration?.name}</div>;
|
||||
},
|
||||
},
|
||||
{
|
||||
accessorKey: 'notificationRule',
|
||||
header: 'Rule',
|
||||
|
||||
@@ -117,21 +117,28 @@ function getIntegration(integrationId: string | null) {
|
||||
}
|
||||
|
||||
export async function createNotification(notification: ICreateNotification) {
|
||||
const res = await db.notification.create({
|
||||
data: {
|
||||
title: notification.title,
|
||||
message: notification.message,
|
||||
projectId: notification.projectId,
|
||||
payload: notification.payload || Prisma.DbNull,
|
||||
...getIntegration(notification.integrationId),
|
||||
notificationRuleId: notification.notificationRuleId,
|
||||
},
|
||||
});
|
||||
const data: Prisma.NotificationUncheckedCreateInput = {
|
||||
title: notification.title,
|
||||
message: notification.message,
|
||||
projectId: notification.projectId,
|
||||
payload: notification.payload || Prisma.DbNull,
|
||||
...getIntegration(notification.integrationId),
|
||||
notificationRuleId: notification.notificationRuleId,
|
||||
};
|
||||
|
||||
return triggerNotification(res);
|
||||
// Only create notifications for app
|
||||
if (data.sendToApp) {
|
||||
await db.notification.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
return triggerNotification(data);
|
||||
}
|
||||
|
||||
export function triggerNotification(notification: Notification) {
|
||||
export function triggerNotification(
|
||||
notification: Prisma.NotificationUncheckedCreateInput,
|
||||
) {
|
||||
return notificationQueue.add('sendNotification', {
|
||||
type: 'sendNotification',
|
||||
payload: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Queue, QueueEvents } from 'bullmq';
|
||||
|
||||
import type { IServiceEvent, Notification } from '@openpanel/db';
|
||||
import type { IServiceEvent, Notification, Prisma } from '@openpanel/db';
|
||||
import { getRedisQueue } from '@openpanel/redis';
|
||||
import type { TrackPayload } from '@openpanel/sdk';
|
||||
|
||||
@@ -130,7 +130,7 @@ export const miscQueue = new Queue<MiscQueuePayload>('misc', {
|
||||
export type NotificationQueuePayload = {
|
||||
type: 'sendNotification';
|
||||
payload: {
|
||||
notification: Notification;
|
||||
notification: Prisma.NotificationUncheckedCreateInput;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type Redis, getRedisPub, getRedisSub } from './redis';
|
||||
|
||||
import type { IServiceEvent, Notification } from '@openpanel/db';
|
||||
import type { IServiceEvent, Notification, Prisma } from '@openpanel/db';
|
||||
import { getSuperJson, setSuperJson } from '@openpanel/json';
|
||||
|
||||
export type IPublishChannels = {
|
||||
@@ -14,7 +14,7 @@ export type IPublishChannels = {
|
||||
saved: IServiceEvent;
|
||||
};
|
||||
notification: {
|
||||
created: Notification;
|
||||
created: Prisma.NotificationUncheckedCreateInput;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user