import {Fragment} from "react"; import {useMutation} from "react-query"; import {Network} from "../../domain/interfaces"; import {Dialog, Transition} from "@headlessui/react"; import {XIcon} from "@heroicons/react/solid"; import {Field, Form} from "react-final-form"; import DEBUG from "../../components/debug"; import {SwitchGroup, TextAreaWide, TextFieldWide} from "../../components/inputs"; import {queryClient} from "../../index"; import arrayMutators from "final-form-arrays"; import { FieldArray } from "react-final-form-arrays"; import {classNames} from "../../styles/utils"; import APIClient from "../../api/APIClient"; // interface radioFieldsetOption { // label: string; // description: string; // value: string; // } // const saslTypeOptions: radioFieldsetOption[] = [ // {label: "None", description: "None", value: ""}, // {label: "Plain", description: "SASL plain", value: "PLAIN"}, // {label: "NickServ", description: "/NS identify", value: "NICKSERV"}, // ]; function IrcNetworkAddForm({isOpen, toggle}: any) { const mutation = useMutation((network: Network) => APIClient.irc.createNetwork(network), { onSuccess: data => { queryClient.invalidateQueries(['networks']); toggle() } }) const onSubmit = (data: any) => { console.log(data) // easy way to split textarea lines into array of strings for each newline. // parse on the field didn't really work. let cmds = data.connect_commands && data.connect_commands.length > 0 ? data.connect_commands.replace(/\r\n/g,"\n").split("\n") : []; data.connect_commands = cmds console.log("formated", data) mutation.mutate(data) }; const validate = (values: any) => { const errors = {} as any; if (!values.name) { errors.name = "Required"; } if (!values.addr) { errors.addr = "Required"; } if (!values.nick) { errors.nick = "Required"; } return errors; } return (
{({handleSubmit, values, pristine, invalid}) => { return (
{/* Header */}
Add network

Add irc network.

{/* (*/} {/* */} {/* {({open}) => (*/} {/*
*/} {/*
*/} {/* SASL / auth*/} {/*
*/} {/*
*/} {/* */} {/* {input.value ? saslTypeOptions.find(c => c.value === input.value)!.label : "Choose auth method"}*/} {/* */} {/* */} {/* */} {/* */} {/* */} {/* {saslTypeOptions.map((opt: any) => (*/} {/* */} {/* classNames(*/} {/* active ? 'text-white bg-indigo-600' : 'text-gray-900',*/} {/* 'cursor-default select-none relative py-2 pl-3 pr-9'*/} {/* )*/} {/* }*/} {/* value={opt.value}*/} {/* >*/} {/* {({selected, active}) => (*/} {/* <>*/} {/* */} {/* {opt.label}*/} {/* */} {/* {selected ? (*/} {/* */} {/*
*/} {/*
*/} {/* )}*/} {/*
*/} {/* )} />*/}
{({ fields }) => (
{fields && (fields.length as any) > 0 ? ( fields.map((name, index) => (
)) ) : ( No channels! )}
)}
) }}
) } export default IrcNetworkAddForm;