Working on notifier system.

This commit is contained in:
charlesgauthereau
2025-11-09 16:47:58 +01:00
parent 411e09f452
commit 7dfd9f02e8
27 changed files with 2755 additions and 81 deletions
@@ -0,0 +1,55 @@
"use client";
import {useMutation} from "@tanstack/react-query";
import {useRouter} from "next/navigation";
import {NotifierAddEditModal} from "@/components/wrappers/dashboard/common/notifier/notifier-add-edit-modal";
import {NotificationChannel} from "@/db/schema/09_notification-channel";
import {Switch} from "@/components/ui/switch";
import {
updateNotificationChannelAction
} from "@/components/wrappers/dashboard/common/notifier/notifier-form/notifier-form.action";
import {toast} from "sonner";
export type EditNotifierButtonProps = {
notificationChannel: NotificationChannel;
};
export const EditNotifierButton = ({notificationChannel}: EditNotifierButtonProps) => {
const router = useRouter();
const mutation = useMutation({
mutationFn: async (value: boolean) => {
const payload = {
data: {
name: notificationChannel.name,
provider: notificationChannel.provider,
config: notificationChannel.config as Record<string, any>,
enabled: value
},
notificationChannelId: notificationChannel.id
};
const result = await updateNotificationChannelAction(payload);
const inner = result?.data;
if (inner?.success) {
toast.success(inner.actionSuccess?.message);
router.refresh();
} else {
toast.error(inner?.actionError?.message);
}
},
});
return (
<>
<Switch checked={notificationChannel.enabled} onCheckedChange={async () => {
await mutation.mutateAsync(!notificationChannel.enabled)
}}
/>
<NotifierAddEditModal
notificationChannel={notificationChannel}
/>
</>
);
};