import { Dialog, Transition } from "@headlessui/react"; import { Fragment } from "react"; import type { FieldProps } from "formik"; import { Field, Form, Formik, FormikErrors, FormikValues } from "formik"; import { XMarkIcon } from "@heroicons/react/24/solid"; import Select, { components, ControlProps, InputProps, MenuProps, OptionProps } from "react-select"; import { PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "../../components/inputs"; import DEBUG from "../../components/debug"; import { EventOptions, NotificationTypeOptions, SelectOption } from "../../domain/constants"; import { useMutation } from "react-query"; import { APIClient } from "../../api/APIClient"; import { queryClient } from "../../App"; import { toast } from "react-hot-toast"; import Toast from "../../components/notifications/Toast"; import { SlideOver } from "../../components/panels"; import { componentMapType } from "./DownloadClientForms"; const Input = (props: InputProps) => { return ( ); }; const Control = (props: ControlProps) => { return ( ); }; const Menu = (props: MenuProps) => { return ( ); }; const Option = (props: OptionProps) => { return ( ); }; function FormFieldsDiscord() { return (
Settings

Create a webhook integration in your server.

); } function FormFieldsNotifiarr() { return (
Settings

Enable the autobrr integration and optionally create a new API Key.

); } function FormFieldsTelegram() { return (
Settings

Read how to create a bot.

); } const componentMap: componentMapType = { DISCORD: , NOTIFIARR: , TELEGRAM: }; interface NotificationAddFormValues { name: string; enabled: boolean; } interface AddProps { isOpen: boolean; toggle: () => void; } export function NotificationAddForm({ isOpen, toggle }: AddProps) { const mutation = useMutation( (notification: Notification) => APIClient.notifications.create(notification), { onSuccess: () => { queryClient.invalidateQueries(["notifications"]); toast.custom((t) => ); toggle(); }, onError: () => { toast.custom((t) => ); } } ); const onSubmit = (formData: unknown) => { mutation.mutate(formData as Notification); }; const testMutation = useMutation( (n: Notification) => APIClient.notifications.test(n), { onError: (err) => { console.error(err); } } ); const testNotification = (data: unknown) => { testMutation.mutate(data as Notification); }; const validate = (values: NotificationAddFormValues) => { const errors = {} as FormikErrors; if (!values.name) errors.name = "Required"; return errors; }; return (
{({ values }) => (
Add Notifications

Trigger notifications on different events.

{({ field, form: { setFieldValue, resetForm } }: FieldProps) => ( ({ ...base, color: "unset" }) }} theme={(theme) => ({ ...theme, spacing: { ...theme.spacing, controlHeight: 30, baseUnit: 2 } })} value={field?.value && NotificationTypeOptions.find(o => o.value == field?.value)} onChange={(option: unknown) => { resetForm(); const opt = option as SelectOption; setFieldValue(field.name, opt.value ?? ""); }} options={NotificationTypeOptions} /> )}
Events

Select what events to trigger on

{componentMap[values.type]}
)} ); }