Revert "feat: add-healthcheck"

This commit is contained in:
Charles GTE
2026-03-28 16:27:57 +01:00
committed by GitHub
parent 9098012426
commit 941a9256f0
53 changed files with 1333 additions and 19938 deletions
@@ -1,5 +1,6 @@
"use client";
import {Card, CardContent} from "@/components/ui/card";
import {
FormControl,
FormDescription,
@@ -1,149 +0,0 @@
"use client"
import {Alert, AlertDescription, AlertTitle} from "@/components/ui/alert";
import {Info, Send} from "lucide-react";
import {ButtonWithLoading} from "@/components/wrappers/common/button/button-with-loading";
import {useRouter} from "next/navigation";
import {Setting} from "@/db/schema/01_setting";
import {
Form,
FormField,
FormItem,
FormLabel,
useZodForm
} from "@/components/ui/form";
import {Select, SelectContent, SelectItem, SelectTrigger, SelectValue} from "@/components/ui/select";
import {useMutation} from "@tanstack/react-query";
import {getChannelIcon} from "@/components/wrappers/dashboard/admin/channels/helpers/common";
import {NotificationChannelWith} from "@/db/schema/09_notification-channel";
import {
DefaultNotificationSchema, DefaultNotificationType
} from "@/components/wrappers/dashboard/admin/settings/notification/settings-notification.schema";
import {
updateNotificationSettingsAction
} from "@/components/wrappers/dashboard/admin/settings/notification/settings-notification.action";
import {toast} from "sonner";
import {Badge} from "@/components/ui/badge";
export type SettingsNotificationSectionProps = {
settings: Setting;
notificationChannels: NotificationChannelWith[];
};
export const SettingsNotificationSection = ({settings, notificationChannels}: SettingsNotificationSectionProps) => {
const router = useRouter();
const form = useZodForm({
schema: DefaultNotificationSchema,
defaultValues: {
notificationChannelId: settings.defaultNotificationChannelId ?? "",
}
});
const mutation = useMutation({
mutationFn: async (values: DefaultNotificationType) => {
const result = await updateNotificationSettingsAction({name: "system", data: values})
const inner = result?.data;
if (inner?.success) {
toast.success(inner.actionSuccess?.message);
router.refresh();
} else {
toast.error(inner?.actionError?.message);
}
}
});
return (
<div className="flex flex-col h-full">
<Alert className="mt-3 flex items-start gap-2">
<Info className="h-4 w-4 mt-1"/>
<div>
<AlertTitle>Informations</AlertTitle>
<AlertDescription className="flex flex-wrap items-center gap-1">
The default notification channel will be used to send
<Badge>error_health_agent</Badge>
<Badge>error_health_database</Badge>
<Badge>error_backup</Badge>
<Badge>error_restore</Badge>
events. For more options like notify when success, please set policy at database level
</AlertDescription>
</div>
</Alert>
<div className="flex flex-col h-full py-4 gap-3">
<Form
className="space-y-4"
form={form}
onSubmit={async (values) => {
await mutation.mutateAsync(values);
}}
>
<div className="flex flex-wrap items-center gap-3">
<FormField
control={form.control}
name="notificationChannelId"
render={({ field }) => (
<FormItem className="flex-grow ">
<FormLabel>Default Notification Provider</FormLabel>
{notificationChannels.length === 0 ? (
<div className="text-sm text-muted-foreground">No channel available</div>
) : (
<Select
value={field.value ?? ""}
onValueChange={(value) => field.onChange(value)}
>
<SelectTrigger className="w-full h-full mb-0">
<SelectValue placeholder="Select a default channel" />
</SelectTrigger>
<SelectContent>
{notificationChannels.map((channel) => (
<SelectItem key={channel.id} value={channel.id}>
<div className="flex items-center gap-2">
{getChannelIcon(channel.provider)}
<span className="font-medium">{channel.name}</span>
<span className="text-[9px] uppercase bg-secondary px-1.5 py-0.5 rounded">
{channel.provider}
</span>
</div>
</SelectItem>
))}
</SelectContent>
</Select>
)}
</FormItem>
)}
/>
</div>
<div className="flex justify-between gap-4">
{notificationChannels.length > 0 && (
<ButtonWithLoading
type="submit"
>
Confirm
</ButtonWithLoading>
)}
<div className="flex justify-end">
{notificationChannels.length > 0 && form.getValues("notificationChannelId") ? (
<ButtonWithLoading
type="button"
variant="outline"
onClick={async () => {
form.setValue("notificationChannelId", "");
await mutation.mutateAsync({
notificationChannelId: null,
});
}}
className="flex-shrink-0 w-full sm:w-auto"
>
Reset
</ButtonWithLoading>
) : null}
</div>
</div>
</Form>
</div>
</div>
);
};
@@ -1,51 +0,0 @@
"use server"
import {userAction} from "@/lib/safe-actions/actions";
import {db} from "@/db";
import * as drizzleDb from "@/db";
import {eq} from "drizzle-orm";
import {ServerActionResult} from "@/types/action-type";
import {Setting} from "@/db/schema/01_setting";
import {z} from "zod";
import {
DefaultNotificationSchema
} from "@/components/wrappers/dashboard/admin/settings/notification/settings-notification.schema";
export const updateNotificationSettingsAction = userAction
.schema(
z.object({
name: z.string(),
data: DefaultNotificationSchema,
})
)
.action(async ({parsedInput}): Promise<ServerActionResult<Setting>> => {
const {name, data} = parsedInput;
try {
const [updatedSettings] = await db
.update(drizzleDb.schemas.setting)
.set({
defaultNotificationChannelId: data.notificationChannelId ?? null,
})
.where(eq(drizzleDb.schemas.setting.name, name))
.returning();
return {
success: true,
value: updatedSettings,
actionSuccess: {
message: "Settings successfully updated",
},
};
} catch (error) {
return {
success: false,
actionError: {
message: "Failed update settings.",
status: 500,
cause: error instanceof Error ? error.message : "Unknown error",
},
};
}
});
@@ -1,7 +0,0 @@
import {z} from "zod";
export const DefaultNotificationSchema = z.object({
notificationChannelId: z.string().optional().nullable()
});
export type DefaultNotificationType = z.infer<typeof DefaultNotificationSchema>;
@@ -7,20 +7,14 @@ import {Setting} from "@/db/schema/01_setting";
import {SettingsEmailSection} from "@/components/wrappers/dashboard/admin/settings/email/settings-email-section";
import {SettingsStorageSection} from "@/components/wrappers/dashboard/admin/settings/storage/settings-storage-section";
import {StorageChannelWith} from "@/db/schema/12_storage-channel";
import {AlarmClock, MailboxIcon, Save} from "lucide-react";
import {
SettingsNotificationSection
} from "@/components/wrappers/dashboard/admin/settings/notification/settings-notification-section";
import {NotificationChannelWith} from "@/db/schema/09_notification-channel";
import {MailboxIcon, Save} from "lucide-react";
export type SettingsTabsProps = {
settings: Setting
storageChannels: StorageChannelWith[],
notificationChannels: NotificationChannelWith[];
storageChannels: StorageChannelWith[]
};
export const SettingsTabs = ({settings, storageChannels, notificationChannels}: SettingsTabsProps) => {
export const SettingsTabs = ({settings, storageChannels}: SettingsTabsProps) => {
const router = useRouter();
const searchParams = useSearchParams();
@@ -53,15 +47,6 @@ export const SettingsTabs = ({settings, storageChannels, notificationChannels}:
content: (
<SettingsStorageSection storageChannels={storageChannels} settings={settings}/>
)
},
{
name: 'Notification',
value: 'notification',
icon: AlarmClock,
content: (
<SettingsNotificationSection notificationChannels={notificationChannels} settings={settings}/>
)
}
]
@@ -109,7 +109,7 @@ export const SettingsStorageSection = ({settings, storageChannels}: SettingsStor
control={form.control}
name="storageChannelId"
render={({field}) => (
<FormItem className="flex-grow">
<FormItem className="flex-grow min-w-[200px] sm:flex-grow-0 sm:w-64">
<FormLabel>Default Storage Provider</FormLabel>
<Select value={field.value} onValueChange={field.onChange}>
<SelectTrigger className="w-full h-full mb-0">