From b42080deae33478cbb11389277fe9a9e1e2df909 Mon Sep 17 00:00:00 2001 From: Varun Murlidhar Date: Fri, 19 Apr 2024 15:18:23 -0400 Subject: [PATCH] Make email field editable and remove input --- compass/components/Table/Index.tsx | 12 +- compass/components/Table/RowOpenAction.tsx | 5 +- compass/components/page/Drawer.tsx | 155 ++++++++++++--------- 3 files changed, 101 insertions(+), 71 deletions(-) diff --git a/compass/components/Table/Index.tsx b/compass/components/Table/Index.tsx index 7beaff7..77b597f 100644 --- a/compass/components/Table/Index.tsx +++ b/compass/components/Table/Index.tsx @@ -40,7 +40,7 @@ export const Table = () => { }), columnHelper.accessor("username", { header: () => <> Username, - cell: (info) => , + cell: (info) => , }), columnHelper.accessor("role", { cell: (info) => , @@ -56,6 +56,16 @@ export const Table = () => { const [data, setData] = useState([...usersExample]); + // added this fn for editing rows + const handleRowUpdate = (updatedRow: User) => { + const dataIndex = data.findIndex((row) => row.id === updatedRow.id); + if (dataIndex !== -1) { + const updatedData = [...data]; + updatedData[dataIndex] = updatedRow; + setData(updatedData); + } + }; + const table = useReactTable({ columns, data, diff --git a/compass/components/Table/RowOpenAction.tsx b/compass/components/Table/RowOpenAction.tsx index 0543dfc..a38ff51 100644 --- a/compass/components/Table/RowOpenAction.tsx +++ b/compass/components/Table/RowOpenAction.tsx @@ -1,7 +1,7 @@ import Drawer from "@/components/page/Drawer"; import {ChangeEvent, useState} from "react"; -export const RowOpenAction = ({ title, rowData }) => { +export const RowOpenAction = ({ title, rowData, onRowUpdate }) => { const [pageContent, setPageContent] = useState("") const handleDrawerContentChange = (newContent) => { @@ -14,7 +14,8 @@ export const RowOpenAction = ({ title, rowData }) => {
{title} - {pageContent} + {/* Added OnRowUpdate to drawer */} + {pageContent}
); diff --git a/compass/components/page/Drawer.tsx b/compass/components/page/Drawer.tsx index d8e46c7..b22ac8a 100644 --- a/compass/components/page/Drawer.tsx +++ b/compass/components/page/Drawer.tsx @@ -1,8 +1,8 @@ import { FunctionComponent, ReactElement, ReactNode } from 'react'; import React, { useState } from 'react'; import { ChevronDoubleLeftIcon } from '@heroicons/react/24/solid'; -import { BookmarkIcon, XMarkIcon, StarIcon as SolidStarIcon } from "@heroicons/react/24/solid"; -import { ArrowsPointingOutIcon, ArrowsPointingInIcon, StarIcon as OutlineStarIcon } from '@heroicons/react/24/outline'; +import { BookmarkIcon, XMarkIcon, StarIcon as SolidStarIcon, EnvelopeIcon, UserIcon } from "@heroicons/react/24/solid"; +import { ArrowsPointingOutIcon, ArrowsPointingInIcon, StarIcon as OutlineStarIcon, ListBulletIcon } from '@heroicons/react/24/outline'; import Card from '@/components/page/Card' @@ -16,15 +16,16 @@ type DrawerProps = { editableContent?: any; onSave?: (content: any) => void; rowContent?: any; + onRowUpdate?: (content: any) => void; }; interface EditContent { content: string; isEditing: boolean; - } +} -const Drawer: FunctionComponent = ({ title, children, onSave, editableContent, rowContent }) => { +const Drawer: FunctionComponent = ({ title, children, onSave, editableContent, rowContent, onRowUpdate }) => { const [isOpen, setIsOpen] = useState(false); const [isFull, setIsFull] = useState(false); const [isEditing, setIsEditing] = useState(false); @@ -33,7 +34,27 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita const [currentCardIcon, setCurrentCardIcon] = useState(''); const [error, setError] = useState(null); const [isFavorite, setIsFavorite] = useState(false); + const [tempRowContent, setTempRowContent] = useState(rowContent); + const handleTempRowContentChange = (e) => { + const { name, value } = e.target; + console.log(name); + console.log(value); + setTempRowContent((prevContent) => ({ + ...prevContent, + [name]: value, + })); + }; + + const handleEnterPress = (e) => { + if (e.key === 'Enter') { + e.preventDefault(); + // Update the rowContent with the temporaryRowContent + if(onRowUpdate) { + onRowUpdate(tempRowContent); + } + } + }; const toggleDrawer = () => { setIsOpen(!isOpen); @@ -81,7 +102,7 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita if (onSave) { onSave(updatedContents); } - }; + }; const toggleEdit = (index: number) => { const newContents = editContents.map((item, idx) => idx === index ? { ...item, isEditing: !item.isEditing } : item); @@ -107,12 +128,10 @@ const Drawer: FunctionComponent = ({ title, children, onSave, edita
-
-
- - {currentCardIcon} - -

{rowContent.username}

+
+
+ {currentCardIcon} +

{rowContent.username}

-
-
- Username: { rowContent.username } -
-
- Role: { rowContent.role } -
-
- Email: { rowContent.email } -
-
- Program: { rowContent.program } -
+ + + + + + + + + + + + + + + + + + + + + + + +
Username{rowContent.username}
Role{rowContent.role}
Email +
Type of Program{rowContent.program}

- { - editContents.map((item, index) => ( -
- {item.isEditing ? ( - <> - - - - ) : ( - <> - {item.content} - - - )} - {/* Delete button moved here, outside of the editing conditional */} - -
- )) -} - -
+ {/* {editContents.map((item, index) => ( +
+ {item.isEditing ? ( + <> + + + + ) : ( + <> + {item.content} + + + )} + +
+ ))} + */} +
);