import React, { useState } from "react"; import { useRouter } from "next/router"; // mobx import { observer } from "mobx-react-lite"; import { useMobxStore } from "lib/mobx/store-provider"; // components import { ColorPicker } from "components/custom-attributes"; // ui import { PrimaryButton } from "components/ui"; // types import { ICustomAttribute } from "types"; type Props = { objectId: string; parentId: string; }; export const OptionForm: React.FC = observer(({ objectId, parentId }) => { const [optionName, setOptionName] = useState(""); const [optionColor, setOptionColor] = useState("#000000"); const router = useRouter(); const { workspaceSlug } = router.query; const { customAttributes: customAttributesStore } = useMobxStore(); const { createAttributeOption, createAttributeOptionLoader } = customAttributesStore; const handleCreateOption = async () => { if (!workspaceSlug) return; if (!optionName || optionName === "") return; const payload: Partial = { color: optionColor, display_name: optionName, type: "option", }; await createAttributeOption(workspaceSlug.toString(), objectId, { ...payload, parent: parentId, }).then(() => { setOptionName(""); setOptionColor("#000000"); }); }; return (
{/* 🚀 */} setOptionName(e.target.value)} placeholder="Enter new option" /> setOptionColor(val)} selectedColor={optionColor} />
{createAttributeOptionLoader ? "Adding..." : "Add"}
); });