import { typeboxResolver } from "@hookform/resolvers/typebox"; import { Input, NativeSelect, Select, TextInput } from "@mantine/core"; import { useToggle } from "@mantine/hooks"; import { IconMinus, IconPlus, IconWorld } from "@tabler/icons-react"; import type { Node, NodeProps } from "@xyflow/react"; import type { Static } from "core/utils"; import { Type } from "core/utils"; import { FetchTask } from "flows"; import { useRef, useState } from "react"; import { useForm } from "react-hook-form"; import { Button } from "ui/components/buttons/Button"; import { JsonViewer } from "ui/components/code/JsonViewer"; import { SegmentedControl } from "ui/components/form/SegmentedControl"; import { MantineSelect } from "ui/components/form/hook-form-mantine/MantineSelect"; import { type TFlowNodeData, useFlowSelector } from "../../../hooks/use-flow"; import { KeyValueInput } from "../../form/KeyValueInput"; import { BaseNode } from "../BaseNode"; const schema = Type.Composite([ FetchTask.schema, Type.Object({ query: Type.Optional(Type.Record(Type.String(), Type.String())), }), ]); type TFetchTaskSchema = Static; type FetchTaskFormProps = NodeProps> & { params: TFetchTaskSchema; onChange: (params: any) => void; }; export function FetchTaskForm({ onChange, params, ...props }: FetchTaskFormProps) { const [advanced, toggle] = useToggle([true, false]); const [bodyType, setBodyType] = useState("None"); const { register, handleSubmit, setValue, getValues, formState: { isValid, errors }, watch, control, } = useForm({ resolver: typeboxResolver(schema), defaultValues: params as Static, mode: "onChange", //defaultValues: (state.relations?.create?.[0] ?? {}) as Static }); function onSubmit(data) { console.log("submit task", data); onChange(data); } //console.log("FetchTaskForm", watch()); return (
{advanced && ( <> setValue("query", items)} error={errors.query?.message} />
Body setBodyType(value)} />
{bodyType === "Form" && } {bodyType === "JSON" && }
)}
); } const TaskNodeTabs = ({ watch }: any) => [ { id: "json", label: "JSON", content: () => (
), }, { id: "test", label: "test", content: () =>
test
, }, ];