From c1b6b9e7fa4ccfa36153cf6b0f0923abb7e481f8 Mon Sep 17 00:00:00 2001 From: Yvan-David Date: Thu, 26 Sep 2024 16:54:04 +0200 Subject: [PATCH] fix(fix bug on table) - displaying 3 dotted button - modal responsiveness [Delivers #500] --- src/components/DataTable.tsx | 11 ++++++--- src/components/InvitationTable.tsx | 12 ++++++--- src/pages/AdminTraineeDashboard.tsx | 38 ++++++++++++++++++++--------- src/pages/invitation.tsx | 19 +++++++++++++-- 4 files changed, 58 insertions(+), 22 deletions(-) diff --git a/src/components/DataTable.tsx b/src/components/DataTable.tsx index 2c28f42b3..b235f1cef 100644 --- a/src/components/DataTable.tsx +++ b/src/components/DataTable.tsx @@ -1,5 +1,5 @@ // @ts-nocheck -import React, { useState, useMemo } from 'react'; +import React, { useState, useMemo, useEffect } from 'react'; import { useTranslation } from 'react-i18next'; import { useGlobalFilter, @@ -18,6 +18,7 @@ interface TableData { } function DataTable({ data, columns, title, loading }: TableData) { + const [pageIndex, setPageIndex] = useState(0); const [filterInput, setFilterInput] = useState(''); const { t } = useTranslation(); @@ -30,7 +31,7 @@ function DataTable({ data, columns, title, loading }: TableData) { { data: memoizedData, columns: memoizedColumns, - initialState: { pageSize: 3, globalFilter: filterInput }, + initialState: { pageIndex, pageSize: 3, globalFilter: filterInput }, }, useGlobalFilter, useSortBy, @@ -52,9 +53,11 @@ function DataTable({ data, columns, title, loading }: TableData) { pageOptions, headerGroups, prepareRow, - state: { pageIndex, pageSize }, + state: { pageIndex: currentPageIndex, pageSize }, } = tableInstance; - + useEffect(() => { + setPageIndex(currentPageIndex); + }, [currentPageIndex]); const handleFilterChange = (e) => { const value = e.target.value || ''; setGlobalFilter(value); diff --git a/src/components/InvitationTable.tsx b/src/components/InvitationTable.tsx index 32491d45b..cb06324c2 100644 --- a/src/components/InvitationTable.tsx +++ b/src/components/InvitationTable.tsx @@ -1,5 +1,5 @@ // @ts-nocheck -import React, { useState, useMemo } from 'react'; +import React, { useState,useEffect, useMemo } from 'react'; import { useTranslation } from 'react-i18next'; import { useGlobalFilter, @@ -20,6 +20,7 @@ interface TableData { function DataTableStats({ data, columns, error, loading }: TableData) { const [filterInput, setFilterInput] = useState(''); const { t } = useTranslation(); + const [pageIndex, setPageIndex] = useState(0); // Memoize columns and data to prevent unnecessary re-renders const memoizedColumns = useMemo(() => [...columns], [columns]); @@ -30,7 +31,7 @@ function DataTableStats({ data, columns, error, loading }: TableData) { { data: memoizedData, columns: memoizedColumns, - initialState: { pageSize: 3, globalFilter: filterInput }, + initialState: {pageIndex, pageSize: 3, globalFilter: filterInput }, }, useGlobalFilter, useSortBy, @@ -52,9 +53,12 @@ function DataTableStats({ data, columns, error, loading }: TableData) { pageOptions, headerGroups, prepareRow, - state: { pageIndex, pageSize }, + state: { pageIndex: currentPageIndex, pageSize }, } = tableInstance; - + + useEffect(() => { + setPageIndex(currentPageIndex); + }, [currentPageIndex]); const handleFilterChange = (e) => { const value = e.target.value || ''; setGlobalFilter(value); diff --git a/src/pages/AdminTraineeDashboard.tsx b/src/pages/AdminTraineeDashboard.tsx index 59e850f97..7cba1b9a7 100644 --- a/src/pages/AdminTraineeDashboard.tsx +++ b/src/pages/AdminTraineeDashboard.tsx @@ -79,7 +79,19 @@ function AdminTraineeDashboard() { const [gitHubStatistics, setGitHubStatistics] = useState({}); const { traineeData, setAllTrainees } = useTraineesContext(); const [actionTraineeOptions, setActionTraineeOptions] = useState(null); + const modalRef = useRef(null); + useEffect(() => { + const handleClickOutside = (event: any) => { + if (modalRef.current && !modalRef.current.contains(event.target)) { + setSelectedRow(null); + } + }; + document.addEventListener('mousedown', handleClickOutside); + return () => { + document.removeEventListener('mousedown', handleClickOutside); + }; + }, [modalRef]); function PaperComponent(props: PaperProps) { return ( toggleOptions(row.original.email)} /> {selectedRow === row.original.email && ( -
+
<>
@@ -1011,7 +1025,7 @@ function AdminTraineeDashboard() { data-testid="removeInviteModel" variant="info" size="sm" - style="w-[20%] md:w-1/4 text-sm font-sans" + style="w-[40%] md:w-1/4 text-sm font-sans" onClick={() => handleClose()} > {t('Close')} @@ -1069,7 +1083,7 @@ function AdminTraineeDashboard() { data-testid="removeInviteModel" variant="info" size="sm" - style="w-[30%] md:w-1/4 text-sm font-sans" + style="w-[40%] md:w-1/4 text-sm font-sans" onClick={() => inviteModel()} > {t('Cancel')} @@ -1078,7 +1092,7 @@ function AdminTraineeDashboard() {