/* * Copyright (c) 2021 - 2025, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { Fragment, JSX, useEffect, useRef, useState } from "react"; import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import Select from "react-select"; import { Field, FieldProps, Form, Formik, FormikErrors, FormikValues, useFormikContext } from "formik"; import { Dialog, DialogPanel, DialogTitle, Listbox, ListboxButton, ListboxOption, ListboxOptions, Transition, TransitionChild } from "@headlessui/react"; import { CheckIcon, ChevronUpDownIcon, XMarkIcon } from "@heroicons/react/24/solid"; import { APIClient } from "@api/APIClient"; import { ListKeys } from "@api/query_keys"; import { toast } from "@components/hot-toast"; import Toast from "@components/notifications/Toast"; import * as common from "@components/inputs/common"; import { MultiSelectOption, PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs"; import { ListsMDBListOptions, ListsMetacriticOptions, ListsTraktOptions, ListsAniListOptions, ListTypeOptions, OptionBasicTyped } from "@domain/constants"; import { DEBUG } from "@components/debug"; import { DownloadClientsArrTagsQueryOptions, DownloadClientsQueryOptions, FiltersGetAllQueryOptions } from "@api/queries"; import { classNames, sleep } from "@utils"; import { ListFilterMultiSelectField, SelectFieldBasic, SelectFieldCreatable } from "@components/inputs/select_wide"; import { DocsTooltip } from "@components/tooltips/DocsTooltip"; import { MultiSelect as RMSC } from "react-multi-select-component"; import { useToggle } from "@hooks/hooks.ts"; import { DeleteModal } from "@components/modals"; import {DocsLink} from "@components/ExternalLink.tsx"; interface ListAddFormValues { name: string; enabled: boolean; } interface AddFormProps { isOpen: boolean; toggle: () => void; } export function ListAddForm({ isOpen, toggle }: AddFormProps) { const queryClient = useQueryClient(); const { data: clients } = useQuery(DownloadClientsQueryOptions()); const filterQuery = useQuery(FiltersGetAllQueryOptions()); const createMutation = useMutation({ mutationFn: (list: List) => APIClient.lists.store(list), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ListKeys.lists() }); toast.custom((t) => ); toggle(); }, onError: () => { toast.custom((t) => ); } }); const onSubmit = (formData: unknown) => createMutation.mutate(formData as List); const validate = (values: ListAddFormValues) => { const errors = {} as FormikErrors; if (!values.name) errors.name = "Required"; return errors; }; return (
{({ values }) => (
Add List

Auto update filters from lists and arrs.

{({ field, form: { setFieldValue } }: FieldProps) => (