import { typeboxResolver } from "@hookform/resolvers/typebox"; import { TextInput } from "@mantine/core"; import { useFocusTrap } from "@mantine/hooks"; import { TypeRegistry } from "@sinclair/typebox"; import { type Static, StringEnum, StringIdentifier, Type, registerCustomTypeboxKinds, } from "core/utils"; import { TRIGGERS } from "flows/flows-schema"; import { forwardRef, useState } from "react"; import { useForm } from "react-hook-form"; import { useFlows } from "ui/client/schema/flows/use-flows"; import { MantineSegmentedControl } from "ui/components/form/hook-form-mantine/MantineSegmentedControl"; import { Modal2, type Modal2Ref, ModalBody, ModalFooter, ModalTitle, } from "../../../components/modal/Modal2"; import { Step, Steps, useStepContext } from "../../../components/steps/Steps"; registerCustomTypeboxKinds(TypeRegistry); export type TCreateFlowModalSchema = any; const triggerNames = Object.keys(TRIGGERS) as unknown as (keyof typeof TRIGGERS)[]; const schema = Type.Object({ name: StringIdentifier, trigger: StringEnum(triggerNames), mode: StringEnum(["async", "sync"]), }); export const FlowCreateModal = forwardRef(function FlowCreateModal(props, ref) { const [path, setPath] = useState([]); function close() { // @ts-ignore ref?.current?.close(); } return ( ); }); export function StepCreate() { const focusTrapRef = useFocusTrap(); const { actions } = useFlows(); const { nextStep, stepBack, state, setState } = useStepContext(); const { handleSubmit, watch, control, register, formState: { isValid, errors }, } = useForm({ resolver: typeboxResolver(schema), defaultValues: { name: "", trigger: "manual", mode: "async", } as Static, mode: "onSubmit", }); async function onSubmit(data: Static) { console.log(data, isValid); actions.flow.create(data.name, { trigger: { type: data.trigger, config: { mode: data.mode, }, }, }); } console.log("errors", errors); return (
{JSON.stringify(watch(), null, 2)}
); }