/* * Copyright (c) 2021-2024, Ludvig Lundgren and the autobrr contributors. * SPDX-License-Identifier: GPL-2.0-or-later */ import { Fragment } from "react"; import { Form, Formik, FormikValues } from "formik"; import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react"; import { XMarkIcon } from "@heroicons/react/24/solid"; import { useMutation, useQueryClient } from "@tanstack/react-query"; import { toast } from "react-hot-toast"; import { AddProps } from "@forms/settings/IndexerForms"; import { DEBUG } from "@components/debug.tsx"; import { PasswordFieldWide, SwitchGroupWide, TextFieldWide } from "@components/inputs"; import { SelectFieldBasic } from "@components/inputs/select_wide"; import { ProxyTypeOptions } from "@domain/constants"; import { APIClient } from "@api/APIClient"; import { ProxyKeys } from "@api/query_keys"; import Toast from "@components/notifications/Toast"; import { SlideOver } from "@components/panels"; export function ProxyAddForm({ isOpen, toggle }: AddProps) { const queryClient = useQueryClient(); const createMutation = useMutation({ mutationFn: (req: ProxyCreate) => APIClient.proxy.store(req), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ProxyKeys.lists() }); toast.custom((t) => ); toggle(); }, onError: () => { toast.custom((t) => ); } }); const onSubmit = (formData: FormikValues) => { createMutation.mutate(formData as ProxyCreate); } const testMutation = useMutation({ mutationFn: (data: Proxy) => APIClient.proxy.test(data), onError: (err) => { console.error(err); } }); const testProxy = (data: unknown) => testMutation.mutate(data as Proxy); const initialValues: ProxyCreate = { enabled: true, name: "Proxy", type: "SOCKS5", addr: "socks5://ip:port", user: "", pass: "", } return (
{({ values }) => (
Add proxy

Add proxy to be used with Indexers or IRC.

Proxy type. Commonly SOCKS5.} help="Usually SOCKS5" />
)}
); } interface UpdateFormProps { isOpen: boolean; toggle: () => void; data: T; } export function ProxyUpdateForm({ isOpen, toggle, data }: UpdateFormProps) { const queryClient = useQueryClient(); const updateMutation = useMutation({ mutationFn: (req: Proxy) => APIClient.proxy.update(req), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ProxyKeys.lists() }); toast.custom((t) => ); toggle(); }, onError: () => { toast.custom((t) => ); } }); const onSubmit = (formData: unknown) => { updateMutation.mutate(formData as Proxy); } const deleteMutation = useMutation({ mutationFn: (proxyId: number) => APIClient.proxy.delete(proxyId), onSuccess: () => { queryClient.invalidateQueries({ queryKey: ProxyKeys.lists() }); toast.custom((t) => ); } }); const deleteFn = () => deleteMutation.mutate(data.id); const testMutation = useMutation({ mutationFn: (data: Proxy) => APIClient.proxy.test(data), onError: (err) => { console.error(err); } }); const testProxy = (data: unknown) => testMutation.mutate(data as Proxy); const initialValues: Proxy = { id: data.id, enabled: data.enabled, name: data.name, type: data.type, addr: data.addr, user: data.user, pass: data.pass, } return ( title="Proxy" initialValues={initialValues} onSubmit={onSubmit} deleteAction={deleteFn} testFn={testProxy} isOpen={isOpen} toggle={toggle} type="UPDATE" > {() => (
Proxy type. Commonly SOCKS5.} help="Usually SOCKS5" />
)} ); }