mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
cleanup admin page
This commit is contained in:
parent
4e33165d9b
commit
81b5c4a42d
5 changed files with 15 additions and 34 deletions
9
client/src/Types/AdminTableType.tsx
Normal file
9
client/src/Types/AdminTableType.tsx
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
export interface AdminTableType {
|
||||
_id: string;
|
||||
email: string;
|
||||
created_at: Date;
|
||||
updated_at?: Date;
|
||||
title?: string;
|
||||
name?: string;
|
||||
roles?: string[];
|
||||
}
|
||||
|
|
@ -1,12 +1,2 @@
|
|||
|
||||
export type LabelMap = { [key: string]: string };
|
||||
|
||||
export interface AdminTableType {
|
||||
_id: string;
|
||||
email: string;
|
||||
title: string;
|
||||
created_at: Date;
|
||||
updated_at: Date;
|
||||
name: string;
|
||||
roles: string[];
|
||||
}
|
||||
|
|
@ -21,8 +21,8 @@ import {
|
|||
} from "@mui/material";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import SearchIcon from "@mui/icons-material/Search";
|
||||
import { QuizTypeShort } from "../../Types/QuizType";
|
||||
import { LabelMap, AdminTableType } from "../../Types/LabelMap";
|
||||
import { AdminTableType } from "../../Types/AdminTableType";
|
||||
import { LabelMap } from "../../Types/LabelMap";
|
||||
|
||||
|
||||
interface AdminTableProps {
|
||||
|
|
@ -87,7 +87,7 @@ const AdminTable: React.FC<AdminTableProps> = ({
|
|||
<Paper sx={{ width: "100%", overflow: "hidden", padding: "16px" }}>
|
||||
<Box display="flex" justifyContent="flex-start" marginBottom={2}>
|
||||
<Input
|
||||
placeholder="Search"
|
||||
placeholder="Recherche: Enseignant, Courriel..."
|
||||
value={searchQuery}
|
||||
onChange={handleSearchChange}
|
||||
startAdornment={
|
||||
|
|
|
|||
|
|
@ -1,27 +1,21 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import { Paper, Grid, Typography, CircularProgress, Box, TextField, Accordion, AccordionSummary, AccordionDetails} from "@mui/material";
|
||||
import { Paper, Grid, Typography, CircularProgress, Box } from "@mui/material";
|
||||
import ApiService from '../../services/ApiService';
|
||||
import ExpandMoreIcon from "@mui/icons-material/ExpandMore";
|
||||
import { AdminTableType } from "../../Types/LabelMap/AdminTableType";
|
||||
import { AdminTableType } from "../../Types/AdminTableType";
|
||||
import AdminTable from "../../components/AdminTable/AdminTable";
|
||||
|
||||
|
||||
const Users: React.FC = () => {
|
||||
const [quizzes, setQuizzes] = useState<AdminTableType[]>([]);
|
||||
const [filteredQuizzes, setFilteredQuizzes] = useState<AdminTableType[]>([]);
|
||||
const [monthlyQuizzes, setMonthlyQuizzes] = useState(0);
|
||||
const [totalUsers, setTotalUsers] = useState(0);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [emailFilter, setEmailFilter] = useState("");
|
||||
const [dateFilter, setDateFilter] = useState("");
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const data = await ApiService.getStats();
|
||||
setQuizzes(data.quizzes);
|
||||
setFilteredQuizzes(data.quizzes);
|
||||
setTotalUsers(data.total);
|
||||
|
||||
const currentMonth = new Date().getMonth();
|
||||
|
|
@ -41,15 +35,6 @@ const Users: React.FC = () => {
|
|||
fetchStats();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const filtered = quizzes.filter(quiz =>
|
||||
quiz.email.toLowerCase().includes(emailFilter.toLowerCase()) &&
|
||||
((new Date(quiz.created_at).toLocaleDateString().includes(dateFilter) ||
|
||||
new Date(quiz.updated_at).toLocaleDateString().includes(dateFilter)))
|
||||
);
|
||||
setFilteredQuizzes(filtered);
|
||||
}, [emailFilter, dateFilter, quizzes]);
|
||||
|
||||
const handleQuizDelete = (rowToDelete: AdminTableType) => {
|
||||
setQuizzes((prevData) => prevData.filter((row) => row._id !== rowToDelete._id));
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,8 +1,6 @@
|
|||
import React, { useState, useEffect } from "react";
|
||||
import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Paper, IconButton } from "@mui/material";
|
||||
import DeleteIcon from "@mui/icons-material/Delete";
|
||||
import ApiService from '../../services/ApiService';
|
||||
import { LabelMap, AdminTableType } from "../../Types/LabelMap";
|
||||
import { AdminTableType } from "../../Types/AdminTableType";
|
||||
import AdminTable from "../../components/AdminTable/AdminTable";
|
||||
|
||||
const Users: React.FC = () => {
|
||||
|
|
@ -12,7 +10,6 @@ const Users: React.FC = () => {
|
|||
const fetchUsers = async () => {
|
||||
try {
|
||||
const data = await ApiService.getUsers();
|
||||
console.log(data);
|
||||
setUsers(data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching users:", error);
|
||||
|
|
|
|||
Loading…
Reference in a new issue