diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index 5e1f49b..fdc11bd 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -32,7 +32,11 @@ type User = { export const Table = () => { const columnHelper = createColumnHelper(); + const [presetOptions, setPresetOptions] = useState(["administrator", "volunteer", "employee"]); + const handleAddTag = (newTag) => { + setPresetOptions((prevOptions) => [...prevOptions, newTag]); + } const columns = [ columnHelper.display({ @@ -45,7 +49,9 @@ export const Table = () => { }), columnHelper.accessor("role", { cell: (info) => , + presetOptions={presetOptions} + addOption={handleAddTag} + />, }), columnHelper.accessor("email", { header: () => <> Email, diff --git a/compass/components/TagsInput/Index.tsx b/compass/components/TagsInput/Index.tsx index 6590a88..ab9a98f 100644 --- a/compass/components/TagsInput/Index.tsx +++ b/compass/components/TagsInput/Index.tsx @@ -1,4 +1,4 @@ -import React, { useState, useEffect, useRef } from "react"; +import React, { useState, useRef } from "react"; import "tailwindcss/tailwind.css"; import { TagsArray } from "./TagsArray"; import { TagDropdown } from "./TagDropdown"; @@ -11,6 +11,7 @@ interface TagsInputProps { const TagsInput: React.FC = ({ presetValue, presetOptions, + addOption, }) => { const [inputValue, setInputValue] = useState(""); const [cellSelected, setCellSelected] = useState(false); @@ -20,24 +21,6 @@ const TagsInput: React.FC = ({ const [options, setOptions] = useState>(new Set(presetOptions)); const dropdown = useRef(null); - // useEffect(() => { - // if (!cellSelected) { - // return; - // } - // function handleOutsideClick(event: MouseEvent) { - // if (dropdown.current && !dropdown.current.contains(event.target as Node)) { - // console.log("here2") - // setCellSelected(false); - // } - // } - - // if (cellSelected){ - // window.addEventListener("click", handleOutsideClick); - // } - - // return () => window.removeEventListener("click", handleOutsideClick); - // }, [cellSelected]) - const handleClick = () => { if (!cellSelected) { setCellSelected(true); @@ -63,8 +46,10 @@ const TagsInput: React.FC = ({ }) setInputValue(e.target.value); // Update input value state }; + const handleAddTag = (e: React.KeyboardEvent) => { if (e.key === "Enter" && inputValue.trim()) { + addOption(inputValue); setTags((prevTags) => new Set(prevTags).add(inputValue)); setOptions((prevOptions) => new Set(prevOptions).add(inputValue)); setInputValue(""); diff --git a/compass/components/TagsInput/Tag.tsx b/compass/components/TagsInput/Tag.tsx index 1d5999c..f44ba9c 100644 --- a/compass/components/TagsInput/Tag.tsx +++ b/compass/components/TagsInput/Tag.tsx @@ -1,4 +1,5 @@ import { XMarkIcon } from "@heroicons/react/24/solid"; +import React, { useState } from "react"; export const Tag = ({ children, handleDelete, active = false }) => { @@ -12,4 +13,4 @@ export const Tag = ({ children, handleDelete, active = false }) => { )} ); -}; +}; \ No newline at end of file