Feat/test channel (#371)

* add: test btn

* fix

* fix

---------

Co-authored-by: Théo LAGACHE <theo.lagache@soluce-technologies.com>
This commit is contained in:
Théo LAGACHE
2026-07-13 15:33:46 +02:00
committed by GitHub
co-authored by Théo LAGACHE
parent 3349bfaf3f
commit 1971ff69e3
58 changed files with 78 additions and 58 deletions
@@ -43,7 +43,7 @@ export const ChannelAddEditModal = ({
}: ChannelAddModalProps) => {
const isMobile = useIsMobile();
const [openInternal, setOpen] = useState(open);
const isLocalSystem = channel?.provider == "local";
const isLocalSystem = channel?.provider === "local";
const isCreate = !Boolean(channel);
@@ -33,7 +33,7 @@ export const EditChannelButton = ({
}: EditChannelButtonProps) => {
const router = useRouter();
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
const isLocalSystem = channel.provider == "local";
const isLocalSystem = channel.provider === "local";
const mutation = useMutation({
@@ -51,10 +51,10 @@ export const EditChannelButton = ({
};
let result: any;
if (kind == "notification") {
if (kind === "notification") {
// @ts-expect-error — payload type varies between notification and storage
result = await updateNotificationChannelAction(payload)
} else if (kind == "storage") {
} else if (kind === "storage") {
// @ts-expect-error — payload type varies between notification and storage
result = await updateStorageChannelAction(payload)
} else {
@@ -224,13 +224,11 @@ export const ChannelForm = ({onSuccessAction, organization, defaultValues, kind}
<div className="flex justify-between mt-4">
<div>
{(!isCreate || kind == "storage") && (
<ChannelTestButton
kind={kind}
organizationId={organization?.id}
channel={form.getValues()}
/>
)}
<ChannelTestButton
kind={kind}
organizationId={organization?.id}
channel={form.getValues()}
/>
</div>
<div className="flex gap-2">
<Button
@@ -13,6 +13,7 @@ import {cn} from "@/lib/utils";
import {StorageChannel} from "@/db/schema/12_storage-channel";
import {ChannelKind} from "@/features/channel/components/channels-helpers";
import type {StorageInput} from "@/features/storages/types";
import type {NotificationChannelFormType} from "@/features/channel/schemas/channel-form.schema";
import {dispatchStorage} from "@/features/storages/utils/storages.dispatch";
@@ -34,7 +35,7 @@ export const ChannelTestButton = ({channel, organizationId, kind}: NotifierTestC
message: `We are testing channel ${channel.name}`,
level: 'info',
};
const result = await dispatchNotification(payload, undefined, channel.id, organizationId);
const result = await dispatchNotification(payload, undefined, undefined, organizationId, channel as unknown as NotificationChannelFormType);
if (result.success) {
toast.success(result.message);
@@ -1,49 +1,49 @@
import {UseFormReturn} from "react-hook-form";
import {
NotifierSmtpForm
} from "@/features/channel/components/notifications/smtp.form";
} from "@/features/channel/components/notifications/smtp/smtp.form";
import {
NotifierSlackForm
} from "@/features/channel/components/notifications/slack.form";
} from "@/features/channel/components/notifications/slack/slack.form";
import {
NotifierDiscordForm
} from "@/features/channel/components/notifications/discord.form";
} from "@/features/channel/components/notifications/discord/discord.form";
import {
NotifierTelegramForm
} from "@/features/channel/components/notifications/telegram.form";
} from "@/features/channel/components/notifications/telegram/telegram.form";
import {
NotifierGotifyForm
} from "@/features/channel/components/notifications/gotify.form";
} from "@/features/channel/components/notifications/gotify/gotify.form";
import {
NotifierNtfyForm
} from "@/features/channel/components/notifications/ntfy.form";
} from "@/features/channel/components/notifications/ntfy/ntfy.form";
import {
NotifierWebhookForm
} from "@/features/channel/components/notifications/webhook.form";
} from "@/features/channel/components/notifications/webhook/webhook.form";
import {
NotifierNextcloudForm
} from "@/features/channel/components/notifications/nextcloud.form";
} from "@/features/channel/components/notifications/nextcloud/nextcloud.form";
import {
NotifierPushoverForm
} from "@/features/channel/components/notifications/pushover.form";
} from "@/features/channel/components/notifications/pushover/pushover.form";
import {
notificationProviders,
} from "@/features/channel/components/channels-notification-helper";
import {
NotifierTeamsForm
} from "@/features/channel/components/notifications/teams.form";
} from "@/features/channel/components/notifications/teams/teams.form";
import {storageProviders} from "@/features/channel/components/channels-storage-helper";
import {ForwardRefExoticComponent, JSX, RefAttributes, SVGProps} from "react";
import {LucideProps} from "lucide-react";
import {
StorageS3Form
} from "@/features/channel/components/storages/s3.form";
} from "@/features/channel/components/storages/s3/s3.form";
import {
StorageGoogleDriveForm
} from "@/features/channel/components/storages/google-drive/google-drive.form";
import {
StorageBlobForm
} from "@/features/channel/components/storages/az-blob.form";
} from "@/features/channel/components/storages/az-blob/az-blob.form";
import {
StorageGoogleCloudStorageForm
} from "@/features/channel/components/storages/google-cloud-storage/google-cloud-storage.form";
@@ -0,0 +1 @@
export * from "./discord";
@@ -0,0 +1 @@
export * from "./gotify";
@@ -0,0 +1 @@
export * from "./nextcloud";
@@ -0,0 +1 @@
export * from "./ntfy";
@@ -0,0 +1 @@
export * from "./pushover";
@@ -4,7 +4,7 @@ import {Input} from "@/components/ui/input";
import {Separator} from "@/components/ui/separator";
import {PasswordInput} from "@/components/ui/password-input";
import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select";
import {PUSHOVER_PRIORITIES} from "@/features/channel/components/notifications/pushover.schema";
import {PUSHOVER_PRIORITIES} from "@/features/channel/components/notifications/pushover/pushover.schema";
type NotifierPushoverFormProps = {
form: UseFormReturn<any, any, any>;
@@ -0,0 +1 @@
export * from "./slack";
@@ -0,0 +1 @@
export * from "./smtp";
@@ -0,0 +1 @@
export * from "./teams";
@@ -0,0 +1 @@
export * from "./telegram";
@@ -0,0 +1 @@
export * from "./webhook";
@@ -0,0 +1 @@
export * from "./az-blob";
@@ -0,0 +1 @@
export * from "./local";
@@ -0,0 +1 @@
export * from "./s3";
@@ -1,18 +1,18 @@
import {z} from "zod";
import {SlackChannelConfigSchema} from "@/features/channel/components/notifications/slack.schema";
import {SmtpChannelConfigSchema} from "@/features/channel/components/notifications/smtp.schema";
import {DiscordChannelConfigSchema} from "@/features/channel/components/notifications/discord.schema";
import {TelegramChannelConfigSchema} from "@/features/channel/components/notifications/telegram.schema";
import {GotifyChannelConfigSchema} from "@/features/channel/components/notifications/gotify.schema";
import {NtfyChannelConfigSchema} from "@/features/channel/components/notifications/ntfy.schema";
import {WebhookChannelConfigSchema} from "@/features/channel/components/notifications/webhook.schema";
import {NextcloudChannelConfigSchema} from "@/features/channel/components/notifications/nextcloud.schema";
import {PushoverChannelConfigSchema} from "@/features/channel/components/notifications/pushover.schema";
import {S3ChannelConfigSchema} from "@/features/channel/components/storages/s3.schema";
import {SlackChannelConfigSchema} from "@/features/channel/components/notifications/slack/slack.schema";
import {SmtpChannelConfigSchema} from "@/features/channel/components/notifications/smtp/smtp.schema";
import {DiscordChannelConfigSchema} from "@/features/channel/components/notifications/discord/discord.schema";
import {TelegramChannelConfigSchema} from "@/features/channel/components/notifications/telegram/telegram.schema";
import {GotifyChannelConfigSchema} from "@/features/channel/components/notifications/gotify/gotify.schema";
import {NtfyChannelConfigSchema} from "@/features/channel/components/notifications/ntfy/ntfy.schema";
import {WebhookChannelConfigSchema} from "@/features/channel/components/notifications/webhook/webhook.schema";
import {NextcloudChannelConfigSchema} from "@/features/channel/components/notifications/nextcloud/nextcloud.schema";
import {PushoverChannelConfigSchema} from "@/features/channel/components/notifications/pushover/pushover.schema";
import {S3ChannelConfigSchema} from "@/features/channel/components/storages/s3/s3.schema";
import {GoogleDriveChannelConfigSchema} from "@/features/channel/components/storages/google-drive/google-drive.schema";
import {LocalChannelConfigSchema} from "@/features/channel/components/storages/local.schema";
import {TeamsChannelConfigSchema} from "@/features/channel/components/notifications/teams.schema";
import {BlobChannelConfigSchema} from "@/features/channel/components/storages/az-blob.schema";
import {LocalChannelConfigSchema} from "@/features/channel/components/storages/local/local.schema";
import {TeamsChannelConfigSchema} from "@/features/channel/components/notifications/teams/teams.schema";
import {BlobChannelConfigSchema} from "@/features/channel/components/storages/az-blob/az-blob.schema";
import {
GoogleCloudStorageChannelConfigSchema
} from "@/features/channel/components/storages/google-cloud-storage/google-cloud-storage.schema";
@@ -6,13 +6,15 @@ import * as drizzleDb from "@/db";
import {db} from "@/db";
import {notificationLog} from "@/db/schema/11_notification-log";
import {NotificationChannel} from "@/db/schema/09_notification-channel";
import {NotificationChannelFormType} from "@/features/channel/schemas/channel-form.schema";
import {Json} from "drizzle-zod";
export async function dispatchNotification(
payload: EventPayload,
policyId?: string,
channelId?: string,
organizationId?: string
organizationId?: string,
channelData?: NotificationChannelFormType
): Promise<DispatchResult> {
try {
let channel: NotificationChannel | null = null;
@@ -69,6 +71,10 @@ export async function dispatchNotification(
};
}
if (channelData) {
channel = {...channelData, config: channelData.config as Json};
}
if (!channel) {
return {
success: false,
@@ -95,28 +101,30 @@ export async function dispatchNotification(
channel.id
);
const [log] = await db
.insert(notificationLog)
.values({
channelId: channel.id,
policyId: policyId || null,
organizationId: organizationId || null,
if (!channelData) {
await db
.insert(notificationLog)
.values({
channelId: channel.id,
policyId: policyId || null,
organizationId: organizationId || null,
provider: channel.provider,
providerName: channel.name,
event: payload.event as EventKind,
provider: channel.provider,
providerName: channel.name,
event: payload.event as EventKind,
title: payload.title,
message: payload.message,
level: payload.level,
payload: payload.data || null,
success: result.success,
error: result.success ? null : result.error,
providerResponse: result.response || null,
})
.returning({id: notificationLog.id});
title: payload.title,
message: payload.message,
level: payload.level,
payload: payload.data || null,
success: result.success,
error: result.success ? null : result.error,
providerResponse: result.response || null,
})
.returning({id: notificationLog.id});
}
return {...result, channelId: channel.id};
return {...result, channelId: channel.id ?? ""};
} catch (err: any) {
return {