From 1f1658c708905ff28870de319456d69d58890696 Mon Sep 17 00:00:00 2001 From: pmoharana-cmd Date: Fri, 3 Jan 2025 21:58:03 -0500 Subject: [PATCH] Implement 'Create New' button and fix no tags bug --- compass/components/Drawer/CreateDrawer.tsx | 171 +++++++++++++++++++ compass/components/Table/ResourceTable.tsx | 9 +- compass/components/Table/ServiceTable.tsx | 9 +- compass/components/Table/Table.tsx | 15 +- compass/components/Table/UserTable.tsx | 9 +- compass/components/TagsInput/TagDropdown.tsx | 34 ++-- compass/components/TagsInput/TagsArray.tsx | 32 ++-- 7 files changed, 242 insertions(+), 37 deletions(-) create mode 100644 compass/components/Drawer/CreateDrawer.tsx diff --git a/compass/components/Drawer/CreateDrawer.tsx b/compass/components/Drawer/CreateDrawer.tsx new file mode 100644 index 0000000..97203be --- /dev/null +++ b/compass/components/Drawer/CreateDrawer.tsx @@ -0,0 +1,171 @@ +import { Dispatch, FunctionComponent, ReactNode, SetStateAction } from "react"; +import React, { useState } from "react"; +import { ChevronDoubleLeftIcon } from "@heroicons/react/24/solid"; +import { + ArrowsPointingOutIcon, + ArrowsPointingInIcon, +} from "@heroicons/react/24/outline"; +import TagsInput from "../TagsInput/Index"; +import { Details } from "./Drawer"; + +type CreateDrawerProps = { + details: Details[]; + onCreate: (newItem: any) => void; +}; + +const CreateDrawer: FunctionComponent = ({ + details, + onCreate, +}: CreateDrawerProps) => { + const [isOpen, setIsOpen] = useState(false); + const [isFull, setIsFull] = useState(false); + const [newItemContent, setNewItemContent] = useState({}); + + const handleContentChange = ( + e: React.ChangeEvent + ) => { + const { name, value } = e.target; + setNewItemContent((prev: any) => ({ + ...prev, + [name]: value, + })); + }; + + const handleCreate = () => { + onCreate(newItemContent); + setNewItemContent({}); + setIsOpen(false); + }; + + const toggleDrawer = () => { + setIsOpen(!isOpen); + if (isFull) { + setIsFull(!isFull); + } + }; + + const toggleDrawerFullScreen = () => setIsFull(!isFull); + + const drawerClassName = `fixed top-0 right-0 h-full bg-white transform ease-in-out duration-300 z-20 overflow-y-auto ${ + isOpen ? "translate-x-0 shadow-2xl" : "translate-x-full" + } ${isFull ? "w-full" : "w-[600px]"}`; + + const iconComponent = isFull ? ( + + ) : ( + + ); + + return ( +
+ +
+
+

+ Create New Item +

+
+ + +
+
+
+
+ {details.map((detail, index) => { + const value = newItemContent[detail.key] || ""; + let inputField; + + switch (detail.inputType) { + case "select-one": + case "select-multiple": + inputField = ( + {}) + } + /> + ); + break; + case "textarea": + inputField = ( +