Skip to content

Commit 75d247a

Browse files
authored
average ratings (#617)
1 parent 643274e commit 75d247a

File tree

4 files changed

+58
-31
lines changed

4 files changed

+58
-31
lines changed

src/components/InvitationTable.tsx

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import React, { useMemo } from "react";
1+
import React, { useMemo } from 'react';
22
import {
33
createColumnHelper,
44
flexRender,
55
getCoreRowModel,
66
useReactTable,
7-
} from "@tanstack/react-table";
8-
import Pagination from "../components/InvitationDataPagination";
7+
} from '@tanstack/react-table';
8+
import Pagination from '../components/InvitationDataPagination';
99
import SkeletonTable from '../Skeletons/SkeletonTable';
1010

1111
interface Column {
@@ -19,7 +19,10 @@ interface TableProps {
1919
data: any[];
2020
loading: boolean;
2121
rowCount: number;
22-
onPaginationChange: (pagination: { pageIndex: number; pageSize: number }) => void;
22+
onPaginationChange: (pagination: {
23+
pageIndex: number;
24+
pageSize: number;
25+
}) => void;
2326
pagination: { pageSize: number; pageIndex: number };
2427
}
2528

@@ -42,22 +45,29 @@ function InvitationTable({
4245
cols.map((column) => {
4346
if (typeof column.accessor === 'string') {
4447
return columnHelper.accessor(column.accessor, {
45-
header: typeof column.header === 'string' ? column.header : column.header(),
48+
header:
49+
typeof column.header === 'string'
50+
? column.header
51+
: column.header(),
4652
cell: column.cell,
4753
});
48-
} else if (typeof column.accessor === 'function') {
54+
}
55+
if (typeof column.accessor === 'function') {
4956
return columnHelper.accessor((row) => column.accessor(row), {
50-
header: typeof column.header === 'string' ? column.header : column.header(),
51-
cell: column.cell,
52-
});
53-
} else {
54-
return columnHelper.display({
55-
header: typeof column.header === 'string' ? column.header : column.header(),
57+
header:
58+
typeof column.header === 'string'
59+
? column.header
60+
: column.header(),
5661
cell: column.cell,
5762
});
5863
}
64+
return columnHelper.display({
65+
header:
66+
typeof column.header === 'string' ? column.header : column.header(),
67+
cell: column.cell,
68+
});
5969
}),
60-
[cols]
70+
[cols],
6171
);
6272

6373
const tableLib = useReactTable({
@@ -83,11 +93,11 @@ function InvitationTable({
8393
{tableLib.getHeaderGroups().map((headerGroup) => (
8494
<tr key={headerGroup.id}>
8595
{headerGroup.headers.map((header) => (
86-
<th
87-
key={header.id}
88-
className="thead"
89-
>
90-
{flexRender(header.column.columnDef.header, header.getContext())}
96+
<th key={header.id} className="thead">
97+
{flexRender(
98+
header.column.columnDef.header,
99+
header.getContext(),
100+
)}
91101
</th>
92102
))}
93103
</tr>
@@ -116,18 +126,21 @@ function InvitationTable({
116126
}`}
117127
>
118128
{row.getVisibleCells().map((cell) => (
119-
<td
120-
key={cell.id}
121-
className="data-cell "
122-
>
123-
{flexRender(cell.column.columnDef.cell, cell.getContext())}
129+
<td key={cell.id} className="data-cell ">
130+
{flexRender(
131+
cell.column.columnDef.cell,
132+
cell.getContext(),
133+
)}
124134
</td>
125135
))}
126136
</tr>
127137
))}
128138
{!loading && data.length === 0 && (
129139
<tr>
130-
<td colSpan={tableColumns.length || 100} className="text-center p-4">
140+
<td
141+
colSpan={tableColumns.length || 100}
142+
className="text-center p-4"
143+
>
131144
<div className="flex flex-col items-center justify-center space-y-4">
132145
<p className="text-gray-600 dark:text-gray-400 text-lg font-medium">
133146
No records available

src/components/NotFoundPage.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
21
import React from 'react';
32
import { Link } from 'react-router-dom';
43

5-
const NotFound=() => {
4+
function NotFound() {
65
return (
76
<div className="flex items-center justify-center h-screen bg-gray-100">
87
<div className="text-center">
98
<h1 className="text-4xl font-bold text-red-600">404</h1>
109
<p className="text-lg text-gray-700 mt-4">Page not found</p>
11-
<Link to="/" className="mt-6 inline-block px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600">
10+
<Link
11+
to="/"
12+
className="mt-6 inline-block px-4 py-2 bg-blue-500 text-white rounded hover:bg-blue-600"
13+
>
1214
Go Back Home
1315
</Link>
1416
</div>
1517
</div>
1618
);
17-
};
19+
}
1820

1921
export default NotFound;

src/containers/admin-dashBoard/TeamTraineeModal.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { toast } from 'react-toastify';
55
import { Team } from './Teams';
66
import ModalDataTable from '../../components/ModalDataTable';
77
import { GET_TEAM_TRAINEE_QUERY } from '../../queries/manageStudent.queries';
8+
import { TRAINEE_RATING } from '../../queries/ratings.queries';
89
import ButtonLoading from '../../components/ButtonLoading';
910

1011
const organizationToken = localStorage.getItem('orgToken');
@@ -23,6 +24,7 @@ export default function TeamTraineeModal({
2324
const { t } = useTranslation();
2425

2526
const [traineeData, setTraineeData] = useState<any[]>([]);
27+
2628
const columns = [
2729
{ Header: t('name'), accessor: 'name' },
2830
{ Header: t('email'), accessor: 'email' },
@@ -41,13 +43,20 @@ export default function TeamTraineeModal({
4143
},
4244
},
4345
);
44-
4546
if (traineeData && traineeData.length > 0) {
4647
traineeData?.map((data: any, index: number): any => {
4748
datum[index] = {};
4849
datum[index].name = data.profile.name;
4950
datum[index].email = data.email;
50-
datum[index].rating = '2';
51+
datum[index].rating =
52+
data.ratings.length > 0
53+
? (
54+
data.ratings.reduce(
55+
(acc: number, rating: any) => acc + parseFloat(rating.average),
56+
0,
57+
) / data.ratings.length
58+
).toFixed(2)
59+
: '0';
5160
datum[index].cohort = data.team?.cohort.name;
5261
datum[index].program = data.team?.cohort.program.name;
5362
return datum;

src/queries/manageStudent.queries.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const GET_ALL_USERS_QUERY = gql`
1515
id
1616
email
1717
role
18-
profile{
18+
profile {
1919
firstName
2020
lastName
2121
}
@@ -214,6 +214,9 @@ export const GET_TEAM_TRAINEE_QUERY = gql`
214214
reason
215215
status
216216
}
217+
ratings {
218+
average
219+
}
217220
profile {
218221
firstName
219222
lastName

0 commit comments

Comments
 (0)