import { useRef, useState } from "react"; import { Button } from "ui/components/buttons/Button"; import { JsonSchemaForm, type JsonSchemaFormProps, type JsonSchemaFormRef } from "ui/components/form/json-schema/JsonSchemaForm"; import type { ContextModalProps } from "@mantine/modals"; type Props = JsonSchemaFormProps & { onSubmit?: (data: any) => void | Promise; }; export function SchemaFormModal({ context, id, innerProps: { schema, uiSchema, onSubmit } }: ContextModalProps) { const [valid, setValid] = useState(false); const formRef = useRef(null); function handleChange(data) { const valid = formRef.current?.validateForm() ?? false; console.log("Data changed", data, valid); setValid(valid); } function handleClose() { context.closeModal(id); } async function handleClickAdd() { await onSubmit?.(formRef.current?.formData()); handleClose(); } return (
); } SchemaFormModal.defaultTitle = "JSON Schema Form Modal"; SchemaFormModal.modalProps = { classNames: { size: "md", root: "bknd-admin", header: "!bg-primary/5 border-b border-b-muted !py-3 px-5 !h-auto !min-h-px", content: "rounded-lg select-none", title: "font-bold !text-md", body: "!p-0" } };