import { FC, useCallback, useEffect } from "react"; import { TEMPLATE_TYPES } from "@/constants/TemplateTypes"; import { SchemaEditAtom } from "@/recoil/atoms/schema"; import { Icon } from "@/components/Icon"; import { FieldTypes } from "./fieldtypes"; import { useAtom } from "jotai"; import { useInput } from "@/hooks/useInput"; import { Schema } from "@/types"; interface IProps { templateKey: string; update: (arg0: string, arg1: FieldTypes) => void; fieldType: FieldTypes; } export const TemplateEditor: FC = ({ templateKey, update, fieldType, }) => { const [schema, setSchema] = useAtom(SchemaEditAtom); // const updateTemplate = useCallback( // (t: FieldTypes | ((arg: FieldTypes) => FieldTypes)) => { // update(templateKey, typeof t === "function" ? t(template) : t); // }, // [templateKey, update, template], // ); // const { bindProperty } = useObjectStateWrapper(template, updateTemplate); const { bind: bindFieldType, value } = useInput(fieldType); useEffect(() => { update(templateKey, value); }); const deleteField = useCallback(() => { setSchema((s: Schema) => { const fields = { ...s.fields }; delete fields[templateKey]; return { ...s, schema: fields, }; }); }, [setSchema, templateKey]); return (
  • {templateKey}

  • ); };