diff --git a/frontend/src/components/common/CommonTable.tsx b/frontend/src/components/common/CommonTable.tsx index 967c6d8..c664760 100644 --- a/frontend/src/components/common/CommonTable.tsx +++ b/frontend/src/components/common/CommonTable.tsx @@ -13,12 +13,14 @@ import { Flex, IconButton, Icon, + Text, } from "@chakra-ui/react"; import EditOutlinedIcon from "@mui/icons-material/EditOutlined"; import ChevronLeftOutlinedIcon from "@mui/icons-material/ChevronLeftOutlined"; import ChevronRightOutlinedIcon from "@mui/icons-material/ChevronRightOutlined"; import KeyboardArrowUpOutlinedIcon from "@mui/icons-material/KeyboardArrowUpOutlined"; import KeyboardArrowDownOutlinedIcon from "@mui/icons-material/KeyboardArrowDownOutlined"; +import ModalContainer from "./ModalContainer"; type TableTypes = string | number | boolean | Date | string[]; @@ -53,6 +55,8 @@ const CommonTable = ({ const [sortingColumn, setSortingColumn] = useState({}); const [originalData, setOriginalData] = useState(data); const [sortedData, setSortedData] = useState(data); + const [isPreviewModalOpen, setIsPreviewModalOpen] = useState(false); + const [selectedRow, setSelectedRow] = useState({}); useEffect(() => { return Math.ceil(data.length / maxResults) >= 5 @@ -70,6 +74,24 @@ const CommonTable = ({ setSortedData(data); }, [data]); + const handleRowClick = (row: TableData) => { + setSelectedRow(row); + setIsPreviewModalOpen(true); + }; + + interface ColumnInfo { + header: string; + value: string; + } + + const colData: ColumnInfo[] = columnInfo.map((col, index) => { + const value = Object.entries(selectedRow)[index]?.[1] || " "; + return { + header: String(col.header), + value: String(value), + }; + }); + // sorting the columns by ascending and descending order based on column indicated const sortColumn = (column: string) => { const newSortingColumn: SortState = {}; @@ -240,9 +262,21 @@ const CommonTable = ({ ) : null} {columnInfo.map((column, i) => ( - {String(row[column.key])} + { + handleRowClick(row); + }} + key={i} + > + {String(row[column.key])} + ))} - onEdit(row)}> + { + e.stopPropagation(); + onEdit(row); + }} + > + {isPreviewModalOpen && selectedRow && ( + + + {colData.slice(1).map((column, index) => ( + + + {column.header}:{" "} + {" "} + {column.value} + + ))} + + + )} + {`Showing ${(page - 1) * maxResults + 1} to ${Math.min( diff --git a/frontend/src/components/common/ModalContainer.tsx b/frontend/src/components/common/ModalContainer.tsx index 8f696d9..37c898f 100644 --- a/frontend/src/components/common/ModalContainer.tsx +++ b/frontend/src/components/common/ModalContainer.tsx @@ -8,6 +8,7 @@ import { Button, } from "@chakra-ui/react"; import DeleteOutlinedIcon from "@mui/icons-material/DeleteOutlined"; +import CloseIcon from "@mui/icons-material/Close"; type Props = { title: string; @@ -39,7 +40,16 @@ const ModalContainer = ({ Delete - ) : null} + ) : ( + + )} {children} diff --git a/frontend/src/components/pages/residents/ResidentsPage.tsx b/frontend/src/components/pages/residents/ResidentsPage.tsx index 6b76042..3fc5d9e 100644 --- a/frontend/src/components/pages/residents/ResidentsPage.tsx +++ b/frontend/src/components/pages/residents/ResidentsPage.tsx @@ -148,6 +148,13 @@ const ResidentsPage = (): React.ReactElement => { setEditInfo(row); }; + // CHANGE + const handleRowClick = (row: any) => { + setIsModalOpen("edit"); + // console.log(row); + setEditInfo(row); + }; + const handleResidentSubmitEdit = () => { setEditInfo(undefined);