import { Button, Form, Input, message, Checkbox } from "antd"; import { FormInstance } from "antd"; import { useEffect, useRef, useState } from "react"; import { Term } from "@nicestack/common"; // Adjust the import path if necessary import { useTerm } from "@web/src/hooks/useTerm"; import DepartmentSelect from "../department/department-select"; import DomainSelect from "../domain/domain-select"; import StaffSelect from "../staff/staff-select"; import TaxonomySelect from "../taxonomy/taxonomy-select"; import TermSelect from "./term-select"; export default function TermForm({ data, taxonomyId, parentId, domainId }: { data?: Partial; taxonomyId: string; parentId?: string; domainId?: string }) { const { create, update, addFetchParentId } = useTerm(); // Ensure you have these methods in your hooks const [loading, setLoading] = useState(false); const formRef = useRef(null); const [selectedDomainId, setSelectedDomainId] = useState(domainId); useEffect(() => { if (taxonomyId) formRef.current?.setFieldValue("taxonomyId", taxonomyId); }, [taxonomyId]); useEffect(() => { if (domainId) { formRef.current?.setFieldValue("domainId", domainId); setSelectedDomainId(domainId) } }, [domainId]); return (
{ setLoading(true); addFetchParentId(values.parentId) if (data) { try { await update.mutateAsync({ id: data.id, ...values }); } catch (err) { message.error("更新失败"); } } else { try { await create.mutateAsync(values); formRef.current?.resetFields(); if (taxonomyId) formRef.current?.setFieldValue("taxonomyId", taxonomyId); if (domainId) formRef.current?.setFieldValue("domainId", domainId); } catch (err) { message.error("创建失败"); } } setLoading(false); }} > { setSelectedDomainId(value); formRef.current?.setFieldValue('domainId', value); }}> {/* */}
); }