import { Fragment, useRef } from "react"; import { useMutation } from "react-query"; import { Indexer } from "../../domain/interfaces"; import { sleep } from "../../utils/utils"; import { ExclamationIcon, XIcon } from "@heroicons/react/solid"; import { Dialog, Transition } from "@headlessui/react"; import { Field, Form } from "react-final-form"; import DEBUG from "../../components/debug"; import { SwitchGroup, TextFieldWide } from "../../components/inputs"; import { useToggle } from "../../hooks/hooks"; import APIClient from "../../api/APIClient"; import { queryClient } from "../../App"; import { PasswordFieldWide } from "../../components/inputs/wide"; import { toast } from 'react-hot-toast' import Toast from '../../components/notifications/Toast'; interface props { isOpen: boolean; toggle: any; indexer: Indexer; } function IndexerUpdateForm({ isOpen, toggle, indexer }: props) { const [deleteModalIsOpen, toggleDeleteModal] = useToggle(false) const mutation = useMutation((indexer: Indexer) => APIClient.indexers.update(indexer), { onSuccess: () => { queryClient.invalidateQueries(['indexer']); toast.custom((t) => ) sleep(1500) toggle() } }) const deleteMutation = useMutation((id: number) => APIClient.indexers.delete(id), { onSuccess: () => { queryClient.invalidateQueries(['indexer']); toast.custom((t) => ) } }) const cancelModalButtonRef = useRef(null) const onSubmit = (data: any) => { // TODO clear data depending on type mutation.mutate(data) }; const deleteAction = () => { deleteMutation.mutate(indexer.id) } const renderSettingFields = (settings: any[]) => { if (settings !== []) { return (
{settings && settings.map((f: any, idx: number) => { switch (f.type) { case "text": return ( ) case "secret": return ( ) } })}
) } } return (
{/* This element is to trick the browser into centering the modal contents. */}
Remove indexer

Are you sure you want to remove this indexer? This action cannot be undone.

({ ...o, [obj.name]: obj.value }), {}), }} onSubmit={onSubmit} > {({ handleSubmit, values }) => { return (
Update indexer

Update indexer.

{({ input, meta }) => (
{meta.touched && meta.error && {meta.error}}
)}
{renderSettingFields(indexer.settings)}
) }}
) } export default IndexerUpdateForm;