Skip to content

Commit

Permalink
Merge branch 'develop' into fx-rating-trainee
Browse files Browse the repository at this point in the history
  • Loading branch information
igorihimbazwe authored Sep 27, 2024
2 parents 87bf078 + 4b677fb commit 333c476
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 23 deletions.
11 changes: 7 additions & 4 deletions src/components/DataTable.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,6 +18,7 @@ interface TableData {
}

function DataTable({ data, columns, title, loading, className }: TableData) {
const [pageIndex, setPageIndex] = useState(0);
const [filterInput, setFilterInput] = useState('');
const { t } = useTranslation();

Expand All @@ -30,7 +31,7 @@ function DataTable({ data, columns, title, loading, className }: TableData) {
{
data: memoizedData,
columns: memoizedColumns,
initialState: { pageSize: 3, globalFilter: filterInput },
initialState: { pageIndex, pageSize: 3, globalFilter: filterInput },
},
useGlobalFilter,
useSortBy,
Expand All @@ -52,9 +53,11 @@ function DataTable({ data, columns, title, loading, className }: 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);
Expand Down
12 changes: 8 additions & 4 deletions src/components/InvitationTable.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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]);
Expand All @@ -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,
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function Sidebar({ style, toggle }: { style: string; toggle: () => void }) {
</SideNavLink>
</CheckRole>
{/* INVITATION */}
<CheckRole roles={['admin', 'coordinator']}>
<CheckRole roles={['admin']}>
<SideNavLink onClick={toggle} to="/invitation" name="Invitation">
<FaEnvelopeOpenText className="w-5" />
</SideNavLink>
Expand Down
40 changes: 28 additions & 12 deletions src/pages/AdminTraineeDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,23 @@ function AdminTraineeDashboard() {
const [gitHubStatistics, setGitHubStatistics] = useState<any>({});
const { traineeData, setAllTrainees } = useTraineesContext() || [];
const [actionTraineeOptions, setActionTraineeOptions] = useState<any>(null);
const modalRef = useRef<any>(null);

const [selectedTraineeId, setSelectedTraineeId]= useState<string[]>()


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 (
<Draggable
Expand Down Expand Up @@ -280,7 +294,9 @@ function AdminTraineeDashboard() {
onClick={() => toggleOptions(row.original.email)}
/>
{selectedRow === row.original.email && (
<div className="absolute z-50 w-64 p-4 mt-2 overflow-hidden border border-gray-300 rounded-lg shadow-md dropdown right-4 bg-light-bg max-h-30 dark:bg-dark-bg">
<div
ref={modalRef}
className="absolute z-50 w-64 p-4 mt-2 overflow-hidden border border-gray-300 rounded-lg shadow-md dropdown right-4 bg-light-bg max-h-30 dark:bg-dark-bg">
<>
<div className="mb-4"></div>
<div className="mb-4">
Expand Down Expand Up @@ -1019,7 +1035,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')}
Expand Down Expand Up @@ -1077,7 +1093,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')}
Expand All @@ -1086,7 +1102,7 @@ function AdminTraineeDashboard() {
<Button
variant="primary"
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={HandleInvite}
loading={buttonLoading}
>
Expand Down Expand Up @@ -1165,15 +1181,15 @@ function AdminTraineeDashboard() {
data-testid="removeModel1"
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={() => removeEditModel()}
>
{t('Cancel')}
</Button>
<Button
variant="primary"
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={() => {
setButtonLoading(true);
setButtonLoading(true);
Expand Down Expand Up @@ -1223,7 +1239,7 @@ function AdminTraineeDashboard() {
data-testid="removeModel2"
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={() => removeTraineeMod()}
>
{t('Cancel')}
Expand All @@ -1232,7 +1248,7 @@ function AdminTraineeDashboard() {
variant="primary"
size="sm"
data-testid="removeMemberFromCohort"
style="w-[30%] md:w-1/4 text-sm font-sans"
style="w-[40%] md:w-1/4 text-sm font-sans"
onClick={() => {
setButtonLoading(true);
if (deleteEmail && deleteFromCohort) {
Expand Down Expand Up @@ -1310,7 +1326,7 @@ function AdminTraineeDashboard() {
data-testid="dropModel"
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={() => setDropTraineeModel(false)}
>
{t('Cancel')}
Expand All @@ -1320,7 +1336,7 @@ function AdminTraineeDashboard() {
variant="primary"
size="sm"
data-testid="dropMemberFromCohort"
style="w-[30%] md:w-1/4 text-sm font-sans"
style="w-[40%] md:w-1/4 text-sm font-sans"
onClick={() => {
setButtonLoading(true);

Expand Down Expand Up @@ -1411,7 +1427,7 @@ function AdminTraineeDashboard() {
data-testid="removeModel"
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={() => removeModel()}
>
{t('Cancel')}
Expand All @@ -1420,7 +1436,7 @@ function AdminTraineeDashboard() {
variant="primary"
size="sm"
data-testid="saveButton"
style="w-[30%] md:w-1/4 text-sm font-sans"
style="w-[40%] md:w-1/4 text-sm font-sans"
onClick={() => {
if (
Object.values(email)[1] &&
Expand Down
19 changes: 17 additions & 2 deletions src/pages/invitation.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable */
/* istanbul ignore file */

import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef } from 'react';
import { useQuery, gql, useLazyQuery, useMutation } from '@apollo/client';
import { IoIosAddCircleOutline, IoIosSearch } from 'react-icons/io';
import { FaCheck, FaFilter } from 'react-icons/fa';
Expand Down Expand Up @@ -80,6 +80,7 @@ function Invitation() {
role: '',
status: '',
});
const modalRef = useRef<any>(null);

const organizationToken = localStorage.getItem('orgToken');

Expand Down Expand Up @@ -147,6 +148,18 @@ function Invitation() {
}
}, [data, selectedInvitationId]);

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]);

useEffect(() => {
if (isLoading) {
setFilterLoading(true);
Expand Down Expand Up @@ -334,7 +347,9 @@ function Invitation() {
onClick={() => toggleOptions(row.id)}
/>
{selectedRow === row.id && (
<div className="absolute z-50 w-64 p-4 mt-2 overflow-hidden border border-gray-300 rounded-lg shadow-md dropdown right-4 bg-light-bg max-h-30 dark:bg-dark-bg">
<div
ref={modalRef}
className="absolute z-50 w-64 p-4 mt-2 overflow-hidden border border-gray-300 rounded-lg shadow-md dropdown right-4 bg-light-bg max-h-30 dark:bg-dark-bg">
<>
<div className="mb-4"></div>
<div className="mb-4">
Expand Down

0 comments on commit 333c476

Please sign in to comment.