/* * Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { useMutation, useQueryClient, useSuspenseQuery } from "@tanstack/react-query"; import { PlusIcon } from "@heroicons/react/24/solid"; import toast from "react-hot-toast"; import { APIClient } from "@api/APIClient"; import { NotificationKeys } from "@api/query_keys"; import { NotificationsQueryOptions } from "@api/queries"; 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 { DiscordIcon, GotifyIcon, LunaSeaIcon, NotifiarrIcon, NtfyIcon, PushoverIcon, Section, TelegramIcon } from "./_components"; import { Checkbox } from "@components/Checkbox"; function NotificationSettings() { const [addNotificationsIsOpen, toggleAddNotifications] = useToggle(false); const notificationsQuery = useSuspenseQuery(NotificationsQueryOptions()) return (
Add new } > {notificationsQuery.data && notificationsQuery.data.length > 0 ? (
  • Enabled
    Name
    Type
    Events
  • {notificationsQuery.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;