From c1b055f2f8dad394c81601a6ded2786932a53a95 Mon Sep 17 00:00:00 2001 From: pmoharana-cmd Date: Fri, 3 Jan 2025 15:18:09 -0500 Subject: [PATCH] Update drawer + tag dropdown for proper functionality --- compass/components/Drawer/Drawer.tsx | 276 +++++++++--------- compass/components/Table/ResourceTable.tsx | 83 ++++-- compass/components/Table/RowOpenAction.tsx | 28 +- compass/components/Table/ServiceTable.tsx | 100 +++++-- compass/components/Table/UserTable.tsx | 71 ++++- .../TagsInput/CreateNewTagAction.tsx | 18 +- .../components/TagsInput/DropdownAction.tsx | 14 +- compass/components/TagsInput/Index.tsx | 110 +++---- compass/components/TagsInput/Tag.tsx | 15 +- compass/components/TagsInput/TagDropdown.tsx | 9 +- compass/components/page/Drawer.tsx | 247 ---------------- 11 files changed, 462 insertions(+), 509 deletions(-) delete mode 100644 compass/components/page/Drawer.tsx diff --git a/compass/components/Drawer/Drawer.tsx b/compass/components/Drawer/Drawer.tsx index 57a95e9..2b69f3c 100644 --- a/compass/components/Drawer/Drawer.tsx +++ b/compass/components/Drawer/Drawer.tsx @@ -14,61 +14,56 @@ import { } from "@heroicons/react/24/outline"; import TagsInput from "../TagsInput/Index"; -type DrawerProps = { - title: string; - children: ReactNode; - onClick?: (event: React.MouseEvent) => void; - type?: "button" | "submit" | "reset"; // specify possible values for type - disabled?: boolean; - editableContent?: any; - onSave?: (content: any) => void; - rowContent?: any; - setData: Dispatch>; -}; +type InputType = + | "text" + | "email" + | "textarea" + | "select-one" + | "select-multiple"; -interface EditContent { - content: string; - isEditing: boolean; +export interface Details { + key: string; + label: string; + inputType: InputType; + icon: ReactNode; + presetOptionsValues?: string[]; + presetOptionsSetter?: Dispatch>; } +type DrawerProps = { + titleKey: string; + details: Details[]; + rowContent?: any; + setRowContent?: Dispatch>; +}; + const Drawer: FunctionComponent = ({ - title, - children, - onSave, - editableContent, + titleKey, + details, rowContent, - setData, -}) => { + setRowContent, +}: DrawerProps) => { const [isOpen, setIsOpen] = useState(false); const [isFull, setIsFull] = useState(false); const [isFavorite, setIsFavorite] = useState(false); const [tempRowContent, setTempRowContent] = useState(rowContent); - const onRowUpdate = (updatedRow: any) => { - setData((prevData: any) => - prevData.map((row: any) => - row.id === updatedRow.id ? updatedRow : row - ) - ); - }; + const onRowUpdate = (updatedRow: any) => {}; - const handleTempRowContentChange = (e) => { + const handleTempRowContentChange = ( + e: React.ChangeEvent + ) => { const { name, value } = e.target; - console.log(name); - console.log(value); - setTempRowContent((prevContent) => ({ - ...prevContent, + setTempRowContent((prev: any) => ({ + ...prev, [name]: value, })); }; - const handleEnterPress = (e) => { + const handleEnterPress = ( + e: React.KeyboardEvent + ) => { if (e.key === "Enter") { - e.preventDefault(); - // Update the rowContent with the temporaryRowContent - if (onRowUpdate) { - onRowUpdate(tempRowContent); - } } }; @@ -99,34 +94,6 @@ const Drawer: FunctionComponent = ({ ); - const [presetOptions, setPresetOptions] = useState([ - "administrator", - "volunteer", - "employee", - ]); - const [rolePresetOptions, setRolePresetOptions] = useState([ - "domestic", - "community", - "economic", - ]); - const [tagColors, setTagColors] = useState(new Map()); - - const getTagColor = (tag: string) => { - if (!tagColors.has(tag)) { - const colors = [ - "bg-cyan-100", - "bg-blue-100", - "bg-green-100", - "bg-yellow-100", - "bg-purple-100", - ]; - const randomColor = - colors[Math.floor(Math.random() * colors.length)]; - setTagColors(new Map(tagColors).set(tag, randomColor)); - } - return tagColors.get(tag); - }; - return (
@@ -169,71 +136,116 @@ const Drawer: FunctionComponent = ({
- - - - - - - - - - - - - - - - - - - - - - -
- - Username - - -
- - Role - -
- - Email - -
- - Type of Program - {/* {rowContent.program} */} - -
+
+ {details.map((detail, index) => { + const value = tempRowContent[detail.key]; + let valueToRender = <>; + + switch (detail.inputType) { + case "select-one": + case "select-multiple": + valueToRender = ( +
+
+ {}) + } + /> +
+
+ ); + break; + case "textarea": + valueToRender = ( +
+
+