/* * Copyright (c) 2021 - 2023, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { useMutation, useQueryClient, useSuspenseQuery } from "@tanstack/react-query"; import { APIClient } from "@api/APIClient"; import { EmptySimple } from "@components/emptystates"; import { useToggle } from "@hooks/hooks"; import { NotificationAddForm, NotificationUpdateForm } from "@forms/settings/NotificationForms"; import { componentMapType } from "@forms/settings/DownloadClientForms"; import Toast from "@components/notifications/Toast"; import toast from "react-hot-toast"; import { Section } from "./_components"; import { PlusIcon } from "@heroicons/react/24/solid"; import { Checkbox } from "@components/Checkbox"; import { DiscordIcon, GotifyIcon, LunaSeaIcon, NotifiarrIcon, NtfyIcon, PushoverIcon, TelegramIcon } from "./_components"; export const notificationKeys = { all: ["notifications"] as const, lists: () => [...notificationKeys.all, "list"] as const, details: () => [...notificationKeys.all, "detail"] as const, detail: (id: number) => [...notificationKeys.details(), id] as const }; function NotificationSettings() { const [addNotificationsIsOpen, toggleAddNotifications] = useToggle(false); const { data } = useSuspenseQuery({ queryKey: notificationKeys.lists(), queryFn: APIClient.notifications.getAll, refetchOnWindowFocus: false } ); return (
Add new } > {data && data.length > 0 ? (
  • Enabled
    Name
    Type
    Events
  • {data.map((n) => )}
) : ( )}
); } const iconStyle = "flex items-center px-2 py-0.5 rounded bg-gray-200 dark:bg-gray-700 text-gray-800 dark:text-gray-400"; const iconComponentMap: componentMapType = { DISCORD: Discord, NOTIFIARR: Notifiarr, TELEGRAM: Telegram, PUSHOVER: Pushover, GOTIFY: Gotify, NTFY: ntfy, SHOUTRRR: Shoutrrr, LUNASEA: LunaSea }; interface ListItemProps { notification: ServiceNotification; } function ListItem({ notification }: ListItemProps) { const [updateFormIsOpen, toggleUpdateForm] = useToggle(false); const queryClient = useQueryClient(); const mutation = useMutation({ mutationFn: (notification: ServiceNotification) => APIClient.notifications.update(notification).then(() => notification), onSuccess: (notification: ServiceNotification) => { toast.custom(t => ); queryClient.invalidateQueries({ queryKey: notificationKeys.lists() }); } }); const onToggleMutation = (newState: boolean) => { mutation.mutate({ ...notification, enabled: newState }); }; return (
  • {notification.name}
    {iconComponentMap[notification.type]}
    {notification.events.length}
    Edit
  • ); } export default NotificationSettings;