import { useEffect } from "react"; import { useRouter } from "next/router"; // mobx import { useMobxStore } from "lib/mobx/store-provider"; import { observer } from "mobx-react-lite"; // components import { CustomCheckboxAttribute, CustomFileAttribute, CustomSelectAttribute, CustomTextAttribute, } from "components/custom-attributes"; // ui import { Loader } from "components/ui"; type Props = { entityId: string; issueId: string; onSubmit: () => Promise; projectId: string; }; export const CustomAttributesList: React.FC = observer( ({ entityId, issueId, onSubmit, projectId }) => { const router = useRouter(); const { workspaceSlug } = router.query; const { customAttributes: customAttributesStore } = useMobxStore(); const { entityAttributes, fetchEntityDetails, fetchEntityDetailsLoader } = customAttributesStore; const attributes = entityAttributes[entityId] ?? {}; useEffect(() => { if (!entityAttributes[entityId]) { if (!workspaceSlug) return; fetchEntityDetails(workspaceSlug.toString(), entityId); } }, [entityAttributes, entityId, fetchEntityDetails, workspaceSlug]); return (
{fetchEntityDetailsLoader ? ( ) : (
{Object.entries(attributes).map(([attributeId, attribute]) => (
{attribute.type === "text" && ( {}} projectId={projectId} value={attribute.default_value ?? ""} /> )} {attribute.type === "select" && ( {}} projectId={projectId} value={attribute.default_value ?? ""} /> )} {attribute.type === "checkbox" && ( {}} projectId={projectId} value={attribute.default_value === "checked" ? true : false} /> )} {attribute.type === "files" && ( {}} projectId={projectId} value={null} /> )}
))}
)}
); } );