mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Ready for release 1.1.4
This commit is contained in:
+6
-1
@@ -5,6 +5,7 @@ import {NotifierCard} from "@/components/wrappers/dashboard/common/notifier/noti
|
||||
import {useState} from "react";
|
||||
import {EmptyStatePlaceholder} from "@/components/wrappers/common/empty-state-placeholder";
|
||||
import {OrganizationWithMembers} from "@/db/schema/03_organization";
|
||||
import {NotifierAddEditModal} from "@/components/wrappers/dashboard/common/notifier/notifier-add-edit-modal";
|
||||
|
||||
type NotificationChannelsSectionProps = {
|
||||
notificationChannels: NotificationChannelWith[]
|
||||
@@ -22,8 +23,10 @@ export const NotificationChannelsSection = ({
|
||||
|
||||
return (
|
||||
<div className="h-full">
|
||||
<NotifierAddEditModal open={isAddModalOpen} onOpenChangeAction={setIsAddModalOpen} adminView={false} trigger={false}/>
|
||||
{hasNotifiers ? (
|
||||
<div className="h-full">
|
||||
|
||||
<CardsWithPagination
|
||||
data={notificationChannels}
|
||||
cardItem={NotifierCard}
|
||||
@@ -36,7 +39,9 @@ export const NotificationChannelsSection = ({
|
||||
) : (
|
||||
<EmptyStatePlaceholder
|
||||
text="No notification channels configured yet"
|
||||
onClick={() => setIsAddModalOpen(true)}
|
||||
onClick={() => {
|
||||
setIsAddModalOpen(true)
|
||||
}}
|
||||
className="h-full"
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -54,16 +54,21 @@ export function notificationLogsColumns(): ColumnDef<NotificationLogWithRelation
|
||||
},
|
||||
{
|
||||
accessorKey: "policy",
|
||||
header: "Event Kinds",
|
||||
cell: ({row}) => {
|
||||
const eventKinds = row.original.policy?.eventKinds ?? [];
|
||||
header: "Event Kind",
|
||||
cell: ({ row }) => {
|
||||
const eventKind = row.original.policy?.event;
|
||||
|
||||
if (!eventKind) {
|
||||
return (
|
||||
<div className="text-muted-foreground italic">
|
||||
No event
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{eventKinds.map((eventKind, idx) => (
|
||||
<div key={idx} className="flex items-center gap-2">
|
||||
<Badge>{eventKind}</Badge>
|
||||
</div>
|
||||
))}
|
||||
<div className="flex items-center gap-2">
|
||||
<Badge>{eventKind}</Badge>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ import {Input} from "@/components/ui/input";
|
||||
import {Form} from "@/components/ui/form";
|
||||
import {Button} from "@/components/ui/button";
|
||||
import {useMutation} from "@tanstack/react-query";
|
||||
import {TooltipProvider} from "@/components/ui/tooltip";
|
||||
import {Tooltip, TooltipContent, TooltipProvider, TooltipTrigger} from "@/components/ui/tooltip";
|
||||
|
||||
import {
|
||||
EmailFormSchema,
|
||||
@@ -26,6 +26,11 @@ import {
|
||||
} from "@/components/wrappers/dashboard/admin/settings/email/email-form/email-form.action";
|
||||
import {toast} from "sonner";
|
||||
import {useRouter} from "next/navigation";
|
||||
import {sendEmail} from "@/lib/email/email-helper";
|
||||
import {render} from "@react-email/components";
|
||||
import EmailSettingsTest from "@/components/emails/email-settings-test";
|
||||
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
|
||||
import {Send} from "lucide-react";
|
||||
|
||||
export type EmailFormProps = {
|
||||
defaultValues?: EmailFormType;
|
||||
@@ -36,6 +41,8 @@ export const EmailForm = (props: EmailFormProps) => {
|
||||
schema: EmailFormSchema,
|
||||
defaultValues: props.defaultValues,
|
||||
});
|
||||
const isDirty = form.formState.isDirty;
|
||||
|
||||
const router = useRouter();
|
||||
|
||||
const mutation = useMutation({
|
||||
@@ -47,10 +54,45 @@ export const EmailForm = (props: EmailFormProps) => {
|
||||
return;
|
||||
}
|
||||
toast.success(`Success updating email informations`);
|
||||
form.reset(data);
|
||||
router.refresh();
|
||||
},
|
||||
});
|
||||
|
||||
const mutationSendEmailTest = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!props.defaultValues?.smtpUser || !props.defaultValues?.smtpFrom) {
|
||||
toast.error("SMTP is not configured");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const email = await sendEmail({
|
||||
to: props.defaultValues.smtpUser,
|
||||
subject: "Portabase",
|
||||
html: await render(EmailSettingsTest(), {}),
|
||||
from: props.defaultValues.smtpFrom,
|
||||
});
|
||||
|
||||
if (email?.response) {
|
||||
toast.success("Test Email successfully sent!");
|
||||
}
|
||||
|
||||
return email;
|
||||
} catch (error: unknown) {
|
||||
if (error instanceof Error) {
|
||||
toast.error(`Email sending failed: ${error.message}`);
|
||||
} else {
|
||||
toast.error("Unknown error while sending test email");
|
||||
}
|
||||
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return (
|
||||
<TooltipProvider>
|
||||
<Card>
|
||||
@@ -139,8 +181,56 @@ export const EmailForm = (props: EmailFormProps) => {
|
||||
</FormItem>
|
||||
)}
|
||||
/>
|
||||
<div className="flex justify-end gap-4">
|
||||
<Button>Save</Button>
|
||||
<div className="flex justify-between gap-4">
|
||||
|
||||
{/*{props.defaultValues?.smtpFrom && (*/}
|
||||
{/* <ButtonWithLoading*/}
|
||||
{/* type="button"*/}
|
||||
{/* isPending={mutationSendEmailTest.isPending}*/}
|
||||
{/* onClick={async () => {*/}
|
||||
{/* await mutationSendEmailTest.mutateAsync();*/}
|
||||
{/* }}*/}
|
||||
{/* icon={<Send/>}*/}
|
||||
{/* size="default"*/}
|
||||
{/* className="bg-green-600 hover:bg-green-700 text-white font-medium shadow-sm transition-all"*/}
|
||||
|
||||
{/* >Send email test</ButtonWithLoading>*/}
|
||||
{/*)}*/}
|
||||
|
||||
|
||||
|
||||
{props.defaultValues?.smtpFrom && (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<div>
|
||||
<ButtonWithLoading
|
||||
type="button"
|
||||
disabled={isDirty || mutationSendEmailTest.isPending}
|
||||
isPending={mutationSendEmailTest.isPending}
|
||||
onClick={async () => {
|
||||
await mutationSendEmailTest.mutateAsync();
|
||||
}}
|
||||
icon={<Send />}
|
||||
size="default"
|
||||
className="bg-green-600 hover:bg-green-700 text-white font-medium shadow-sm transition-all"
|
||||
|
||||
>
|
||||
Send email test
|
||||
</ButtonWithLoading>
|
||||
</div>
|
||||
</TooltipTrigger>
|
||||
|
||||
{isDirty && (
|
||||
<TooltipContent>
|
||||
You must save changes before testing the email settings.
|
||||
</TooltipContent>
|
||||
)}
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
<Button
|
||||
type="submit"
|
||||
>Save</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</CardContent>
|
||||
|
||||
@@ -10,7 +10,7 @@ import {NotifierForm} from "@/components/wrappers/dashboard/common/notifier/noti
|
||||
import {OrganizationWithMembers} from "@/db/schema/03_organization";
|
||||
import {NotificationChannel, NotificationChannelWith} from "@/db/schema/09_notification-channel";
|
||||
import {useIsMobile} from "@/hooks/use-mobile";
|
||||
import {useState} from "react";
|
||||
import {useEffect, useState} from "react";
|
||||
import {Tabs, TabsContent, TabsList, TabsTrigger} from "@/components/ui/tabs";
|
||||
import {
|
||||
NotifierChannelOrganisationForm
|
||||
@@ -23,6 +23,7 @@ type OrganizationNotifierAddModalProps = {
|
||||
onOpenChangeAction?: (open: boolean) => void;
|
||||
adminView?: boolean;
|
||||
organizations?: OrganizationWithMembers[]
|
||||
trigger?: boolean;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,33 +33,41 @@ export const NotifierAddEditModal = ({
|
||||
open = false,
|
||||
onOpenChangeAction,
|
||||
adminView,
|
||||
organizations
|
||||
organizations ,
|
||||
trigger= true
|
||||
}: OrganizationNotifierAddModalProps) => {
|
||||
const isMobile = useIsMobile();
|
||||
const [openInternal, setOpen] = useState(open);
|
||||
|
||||
const isCreate = !Boolean(notificationChannel);
|
||||
|
||||
useEffect(() => {
|
||||
setOpen(open);
|
||||
},[open])
|
||||
|
||||
|
||||
return (
|
||||
<Dialog open={openInternal} onOpenChange={(state) => {
|
||||
onOpenChangeAction?.(state);
|
||||
setOpen(state);
|
||||
}}>
|
||||
<DialogTrigger asChild>
|
||||
{isCreate ?
|
||||
<Button>
|
||||
<Plus/>{!isMobile && `Add notification channel`}
|
||||
</Button>
|
||||
:
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
>
|
||||
<Pencil className="h-4 w-4"/>
|
||||
</Button>
|
||||
}
|
||||
</DialogTrigger>
|
||||
{trigger && (
|
||||
<DialogTrigger asChild>
|
||||
{isCreate ?
|
||||
<Button>
|
||||
<Plus/>{!isMobile && `Add notification channel`}
|
||||
</Button>
|
||||
:
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
>
|
||||
<Pencil className="h-4 w-4"/>
|
||||
</Button>
|
||||
}
|
||||
</DialogTrigger>
|
||||
)}
|
||||
|
||||
<DialogContent onOpenAutoFocus={(e) => e.preventDefault()}>
|
||||
<DialogHeader>
|
||||
<DialogTitle> {isCreate ? "Add" : "Edit"} Notification Channel</DialogTitle>
|
||||
|
||||
@@ -35,8 +35,10 @@ export const AlertPolicyForm = ({database, notificationChannels, organizationId,
|
||||
const router = useRouter()
|
||||
const organizationNotificationChannels = notificationChannels.map(channel => channel.id) ?? [];
|
||||
|
||||
|
||||
|
||||
const formattedAlertPoliciesList = (alertPolicies: AlertPolicy[]) => {
|
||||
return alertPolicies.map((alertPolicy) => ({
|
||||
return alertPolicies.filter((alertPolicy)=> organizationNotificationChannels.includes(alertPolicy.notificationChannelId)).map((alertPolicy) => ({
|
||||
notificationChannelId: alertPolicy.notificationChannelId,
|
||||
eventKinds: alertPolicy.eventKinds,
|
||||
enabled: alertPolicy.enabled
|
||||
@@ -273,11 +275,6 @@ export const AlertPolicyForm = ({database, notificationChannels, organizationId,
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<div tabIndex={0} className="inline-flex rounded-md">
|
||||
{/*<Switch*/}
|
||||
{/* checked={true}*/}
|
||||
{/* onCheckedChange={async () => {*/}
|
||||
{/* }}*/}
|
||||
{/*/>*/}
|
||||
|
||||
|
||||
<FormField
|
||||
|
||||
@@ -26,14 +26,22 @@ type AlertPolicyModalProps = {
|
||||
export const AlertPolicyModal = ({database, notificationChannels, organizationId}: AlertPolicyModalProps) => {
|
||||
const [open, setOpen] = useState(false);
|
||||
|
||||
const notificationsChannelsIds = notificationChannels.map(channel => channel.id);
|
||||
const activePolicies = database.alertPolicies?.filter((policy) => notificationsChannelsIds.some(()=> policy.notificationChannelId));
|
||||
|
||||
|
||||
const notificationsChannelsFiltered = notificationChannels
|
||||
.filter((channel) => channel.enabled)
|
||||
|
||||
const notificationsChannelsIds = notificationsChannelsFiltered
|
||||
.map(channel => channel.id);
|
||||
|
||||
const activePolicies = database.alertPolicies?.filter((policy) => notificationsChannelsIds.includes(policy.notificationChannelId));
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="outline" onClick={() => setOpen(true)} className="relative">
|
||||
<Megaphone/>
|
||||
{ activePolicies && activePolicies.length > 0 && (
|
||||
{activePolicies && activePolicies.length > 0 && (
|
||||
<Badge
|
||||
className="absolute -top-1.5 -right-1.5 h-4 w-4 rounded-full p-0 text-[10px] flex items-center justify-center"
|
||||
>
|
||||
@@ -52,7 +60,7 @@ export const AlertPolicyModal = ({database, notificationChannels, organizationId
|
||||
<Separator className="mt-3 mb-3"/>
|
||||
<AlertPolicyForm
|
||||
organizationId={organizationId}
|
||||
notificationChannels={notificationChannels}
|
||||
notificationChannels={notificationsChannelsFiltered}
|
||||
database={database}
|
||||
onSuccess={() => setOpen(false)}
|
||||
/>
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
ALTER TABLE "notification_log" DROP CONSTRAINT "notification_log_channel_id_notification_channel_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "notification_log" DROP CONSTRAINT "notification_log_policy_id_alert_policy_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "notification_log" DROP CONSTRAINT "notification_log_organization_id_organization_id_fk";
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "notification_log" ADD COLUMN "event" text;--> statement-breakpoint
|
||||
ALTER TABLE "notification_log" ADD COLUMN "provider" text NOT NULL;--> statement-breakpoint
|
||||
ALTER TABLE "notification_log" ADD COLUMN "provider_name" text NOT NULL;
|
||||
File diff suppressed because it is too large
Load Diff
@@ -78,6 +78,13 @@
|
||||
"when": 1764497732581,
|
||||
"tag": "0010_past_trauma",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 11,
|
||||
"version": "7",
|
||||
"when": 1765097874110,
|
||||
"tag": "0011_outgoing_blob",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -2,7 +2,7 @@ import {boolean, pgEnum, pgTable, uuid} from "drizzle-orm/pg-core";
|
||||
import {notificationChannel} from "@/db/schema/09_notification-channel";
|
||||
import {timestamps} from "@/db/schema/00_common";
|
||||
import {relations} from "drizzle-orm";
|
||||
import {database, retentionPolicy} from "@/db/schema/07_database";
|
||||
import {database} from "@/db/schema/07_database";
|
||||
import {createSelectSchema} from "drizzle-zod";
|
||||
import {z} from "zod";
|
||||
|
||||
@@ -32,9 +32,7 @@ export const alertPolicyRelations = relations(alertPolicy, ({one}) => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
export const notificationChannelsToAlertPoliciesRelations = relations(notificationChannel, ({many}) => ({
|
||||
alertPolicies: many(alertPolicy),
|
||||
}));
|
||||
|
||||
|
||||
|
||||
export const alertPolicySchema = createSelectSchema(alertPolicy);
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
import {pgTable, uuid, timestamp, jsonb, varchar, boolean, text, pgEnum} from 'drizzle-orm/pg-core';
|
||||
import {notificationChannel} from "@/db/schema/09_notification-channel";
|
||||
import {alertPolicy} from "@/db/schema/10_alert-policy";
|
||||
import {organization} from "@/db/schema/03_organization";
|
||||
import {timestamps} from "@/db/schema/00_common";
|
||||
import {createSelectSchema} from "drizzle-zod";
|
||||
import {z} from "zod";
|
||||
import {relations} from "drizzle-orm";
|
||||
|
||||
|
||||
export const levelEnum = pgEnum('level', ['critical', 'warning', 'info']);
|
||||
@@ -13,13 +13,13 @@ export const levelEnum = pgEnum('level', ['critical', 'warning', 'info']);
|
||||
export const notificationLog = pgTable('notification_log', {
|
||||
id: uuid('id').defaultRandom().primaryKey(),
|
||||
|
||||
channelId: uuid('channel_id')
|
||||
.notNull()
|
||||
.references(() => notificationChannel.id, {onDelete: 'restrict'}),
|
||||
policyId: uuid('policy_id')
|
||||
.references(() => alertPolicy.id, {onDelete: 'restrict'}),
|
||||
organizationId: uuid('organization_id')
|
||||
.references(() => organization.id, {onDelete: 'set null'}),
|
||||
channelId: uuid('channel_id').notNull(),
|
||||
policyId: uuid('policy_id'),
|
||||
organizationId: uuid('organization_id'),
|
||||
|
||||
event: text("event"),
|
||||
provider: text("provider").notNull(),
|
||||
providerName: text("provider_name").notNull(),
|
||||
|
||||
title: varchar('title', {length: 255}).notNull(),
|
||||
message: text('message').notNull(),
|
||||
@@ -35,6 +35,11 @@ export const notificationLog = pgTable('notification_log', {
|
||||
...timestamps
|
||||
});
|
||||
|
||||
|
||||
export const notificationChannelsToAlertPoliciesRelations = relations(notificationChannel, ({many}) => ({
|
||||
alertPolicies: many(alertPolicy),
|
||||
}));
|
||||
|
||||
export const notificationLogSchema = createSelectSchema(notificationLog);
|
||||
export type NotificationLog = z.infer<typeof notificationLogSchema>;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ import {and, desc, eq, gte, lte} from 'drizzle-orm';
|
||||
import {NotificationLevel, notificationLog} from "@/db/schema/11_notification-log";
|
||||
import {notificationChannel} from "@/db/schema/09_notification-channel";
|
||||
import {db} from "@/db";
|
||||
import {alertPolicy} from "@/db/schema/10_alert-policy";
|
||||
import {Json} from "drizzle-zod";
|
||||
|
||||
export type NotificationLogWithRelations = {
|
||||
@@ -18,13 +17,11 @@ export type NotificationLogWithRelations = {
|
||||
message: string;
|
||||
},
|
||||
channel: {
|
||||
id: string;
|
||||
name: string;
|
||||
provider: string;
|
||||
} | null;
|
||||
policy: {
|
||||
id: string;
|
||||
eventKinds: string[];
|
||||
event: string | null;
|
||||
} | null;
|
||||
};
|
||||
|
||||
@@ -63,18 +60,16 @@ export async function getNotificationHistory(
|
||||
message: notificationLog.message,
|
||||
},
|
||||
channel: {
|
||||
id: notificationChannel.id,
|
||||
name: notificationChannel.name,
|
||||
provider: notificationChannel.provider,
|
||||
name: notificationLog.providerName,
|
||||
provider: notificationLog.provider,
|
||||
},
|
||||
policy: {
|
||||
id: alertPolicy.id,
|
||||
eventKinds: alertPolicy.eventKinds,
|
||||
event: notificationLog.event,
|
||||
},
|
||||
})
|
||||
.from(notificationLog)
|
||||
.leftJoin(notificationChannel, eq(notificationLog.channelId, notificationChannel.id))
|
||||
.leftJoin(alertPolicy, eq(notificationLog.policyId, alertPolicy.id))
|
||||
// .leftJoin(alertPolicy, eq(notificationLog.policyId, alertPolicy.id))
|
||||
.where(and(...where))
|
||||
.orderBy(desc(notificationLog.sentAt))
|
||||
.limit(filters?.limit || 100);
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
"use server";
|
||||
import { eq } from "drizzle-orm";
|
||||
import { dispatchViaProvider } from "./providers";
|
||||
import type {EventPayload, DispatchResult} from "./types";
|
||||
import {eq} from "drizzle-orm";
|
||||
import {dispatchViaProvider} from "./providers";
|
||||
import type {EventPayload, DispatchResult, EventKind} from "./types";
|
||||
import * as drizzleDb from "@/db";
|
||||
import { db } from "@/db";
|
||||
import { notificationLog } from "@/db/schema/11_notification-log";
|
||||
import {db} from "@/db";
|
||||
import {notificationLog} from "@/db/schema/11_notification-log";
|
||||
import {NotificationChannel} from "@/db/schema/09_notification-channel";
|
||||
import {Json} from "drizzle-zod";
|
||||
import {AlertPolicy} from "@/db/schema/10_alert-policy";
|
||||
|
||||
export async function dispatchNotification(
|
||||
payload: EventPayload,
|
||||
@@ -18,14 +19,14 @@ export async function dispatchNotification(
|
||||
let channel: NotificationChannel | null = null;
|
||||
|
||||
if (policyId) {
|
||||
const policy = await db.query.alertPolicy.findFirst({
|
||||
const policyDb = await db.query.alertPolicy.findFirst({
|
||||
where: eq(drizzleDb.schemas.alertPolicy.id, policyId),
|
||||
with: {
|
||||
notificationChannel: true
|
||||
},
|
||||
});
|
||||
|
||||
if (!policy || !policy.notificationChannel) {
|
||||
if (!policyDb || !policyDb.notificationChannel) {
|
||||
return {
|
||||
success: false,
|
||||
channelId: "",
|
||||
@@ -34,18 +35,18 @@ export async function dispatchNotification(
|
||||
};
|
||||
}
|
||||
|
||||
if (!policy.enabled || !policy.notificationChannel.enabled) {
|
||||
if (!policyDb.enabled || !policyDb.notificationChannel.enabled) {
|
||||
return {
|
||||
success: false,
|
||||
channelId: policy.notificationChannel.id,
|
||||
provider: policy.notificationChannel.provider as any,
|
||||
channelId: policyDb.notificationChannel.id,
|
||||
provider: policyDb.notificationChannel.provider as any,
|
||||
error: "Policy or channel is disabled",
|
||||
};
|
||||
}
|
||||
|
||||
channel = {
|
||||
...policy.notificationChannel,
|
||||
config : policy.notificationChannel.config as Json,
|
||||
...policyDb.notificationChannel,
|
||||
config: policyDb.notificationChannel.config as Json,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -65,7 +66,7 @@ export async function dispatchNotification(
|
||||
|
||||
channel = {
|
||||
...fetchedChannel,
|
||||
config : fetchedChannel.config as Json,
|
||||
config: fetchedChannel.config as Json,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -91,7 +92,7 @@ export async function dispatchNotification(
|
||||
const result = await dispatchViaProvider(
|
||||
channel.provider,
|
||||
channel.config,
|
||||
{ ...payload, timestamp: payload.timestamp || new Date() },
|
||||
{...payload, timestamp: payload.timestamp || new Date()},
|
||||
channel.id
|
||||
);
|
||||
|
||||
@@ -101,6 +102,11 @@ export async function dispatchNotification(
|
||||
channelId: channel.id,
|
||||
policyId: policyId || null,
|
||||
organizationId: organizationId || null,
|
||||
|
||||
provider: channel.provider,
|
||||
providerName: channel.name,
|
||||
event: payload.event as EventKind,
|
||||
|
||||
title: payload.title,
|
||||
message: payload.message,
|
||||
level: payload.level,
|
||||
@@ -109,9 +115,9 @@ export async function dispatchNotification(
|
||||
error: result.success ? null : result.error,
|
||||
providerResponse: result.response || null,
|
||||
})
|
||||
.returning({ id: notificationLog.id });
|
||||
.returning({id: notificationLog.id});
|
||||
|
||||
return { ...result, channelId: channel.id };
|
||||
return {...result, channelId: channel.id};
|
||||
|
||||
} catch (err: any) {
|
||||
return {
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import {DatabaseWith} from "@/db/schema/07_database";
|
||||
import {EventPayload} from "@/features/notifications/types";
|
||||
import {EventKind, EventPayload} from "@/features/notifications/types";
|
||||
import {dispatchNotification} from "@/features/notifications/dispatch";
|
||||
|
||||
|
||||
type EventKind = ("error_backup" | "error_restore" | "success_restore" | "success_backup" | "weekly_report")
|
||||
|
||||
export async function sendNotificationsBackupRestore(database: DatabaseWith, event: EventKind) {
|
||||
|
||||
if (database.alertPolicies && database.alertPolicies.length > 0) {
|
||||
@@ -52,6 +50,7 @@ export async function sendNotificationsBackupRestore(database: DatabaseWith, eve
|
||||
title: titleMap[event],
|
||||
message,
|
||||
level: level,
|
||||
event: event,
|
||||
data: {
|
||||
host: database.name,
|
||||
id: database.id,
|
||||
|
||||
@@ -14,5 +14,8 @@ export interface EventPayload {
|
||||
message: string;
|
||||
level: 'critical' | 'warning' | 'info';
|
||||
timestamp?: Date;
|
||||
event?: EventKind
|
||||
data?: Record<string, any>;
|
||||
}
|
||||
}
|
||||
|
||||
export type EventKind = ("error_backup" | "error_restore" | "success_restore" | "success_backup" | "weekly_report")
|
||||
|
||||
Reference in New Issue
Block a user