mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
61 lines
2.0 KiB
TypeScript
61 lines
2.0 KiB
TypeScript
"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";
|
|
import {useState} from "react";
|
|
|
|
export type EditNotifierButtonProps = {
|
|
notificationChannel: NotificationChannel;
|
|
};
|
|
|
|
export const EditNotifierButton = ({notificationChannel}: EditNotifierButtonProps) => {
|
|
const router = useRouter();
|
|
const [isAddModalOpen, setIsAddModalOpen] = useState(false);
|
|
|
|
|
|
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}
|
|
open={isAddModalOpen}
|
|
onOpenChangeAction={setIsAddModalOpen}
|
|
/>
|
|
</>
|
|
);
|
|
};
|