From dadaabcd3a90458c355abba31adac03fc8cc5682 Mon Sep 17 00:00:00 2001 From: Malopieds Date: Sat, 19 Oct 2024 09:49:35 +0200 Subject: [PATCH] feat: changes --- src/App.tsx | 1 - src/component/Navigation/Navigation.tsx | 4 ++-- src/pages/Dashboard.tsx | 9 ++++++--- src/pages/Login.tsx | 10 +++++----- src/pages/Practical.tsx | 3 ++- src/pages/admin/BulkCreateUser.tsx | 21 ++++++++------------- src/pages/admin/CreateTp.tsx | 9 ++++++--- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index b2c141c..0da2361 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,4 +1,3 @@ -import { useState } from "react"; import "./App.css"; import { BrowserRouter, Route, Routes } from "react-router-dom"; import Navigation from "./component/Navigation/Navigation"; diff --git a/src/component/Navigation/Navigation.tsx b/src/component/Navigation/Navigation.tsx index bca690c..33b4f1d 100644 --- a/src/component/Navigation/Navigation.tsx +++ b/src/component/Navigation/Navigation.tsx @@ -32,7 +32,7 @@ const Navigation: React.FC = ({ localStorage.removeItem("root"); }; - const handleToggle = (e) => { + const handleToggle = () => { if (theme === "light") { setTheme("dark"); } else { @@ -49,7 +49,7 @@ const Navigation: React.FC = ({ localStorage.setItem("theme", theme); const localTheme = localStorage.getItem("theme"); document.querySelector("html").setAttribute("data-theme", localTheme); - }, [theme]); + }, [theme, navigate]); return ( <> diff --git a/src/pages/Dashboard.tsx b/src/pages/Dashboard.tsx index f257e1f..72cad8f 100644 --- a/src/pages/Dashboard.tsx +++ b/src/pages/Dashboard.tsx @@ -1,10 +1,11 @@ import { useEffect, useState } from "react"; -import Card from "../component/Card/Card"; import axios from "axios"; import { Link } from "react-router-dom"; +import { Tp } from "../type/TpType"; function Dashboard() { const [dashboard, setDashboard] = useState(null); + const username = localStorage.getItem("username"); useEffect(() => { axios.get("/api/dashboard").then((res) => { setDashboard(res.data); @@ -15,7 +16,9 @@ function Dashboard() { <>
-

Welcome to La Banquise

+

+ Welcome to La Banquise {username} +

You will find here all of your instances and practicals

@@ -29,7 +32,7 @@ function Dashboard() { Practicals
- {dashboard.tps.map((tp) => ( + {dashboard.tps.map((tp: Tp) => (
{ axios.get("/api/users/me").then((res) => { localStorage.setItem("username", res.data.username); if (res.data.roles.includes("root")) { - localStorage.setItem("root", true); + localStorage.setItem("root", "true"); } else { localStorage.removeItem("root"); } @@ -35,7 +35,7 @@ const LoginPage: React.FC = () => { }) .catch((response) => { if (response.status === 401) { - setError("wrong_user_pwd"); + setError("Wrong user or password"); } }); }; @@ -44,11 +44,11 @@ const LoginPage: React.FC = () => {
-

{"login"}

+

Login

{
(); const copyText = (copy: string) => { navigator.clipboard.writeText(copy); diff --git a/src/pages/admin/BulkCreateUser.tsx b/src/pages/admin/BulkCreateUser.tsx index 0be3b64..a58023a 100644 --- a/src/pages/admin/BulkCreateUser.tsx +++ b/src/pages/admin/BulkCreateUser.tsx @@ -1,15 +1,16 @@ import axios from "axios"; import { useEffect, useState } from "react"; import { useNavigate } from "react-router-dom"; +import { User } from "../../type/UserType"; +import { Tp } from "../../type/TpType"; function BulkUsers() { - const [file, setFile] = useState(null); const [userData, setUserData] = useState([]); const [practical, setPractical] = useState("0"); const navigate = useNavigate(); const [tps, setTps] = useState([]); - const handlePracticalChange = (e) => { + const handlePracticalChange = (e: React.ChangeEvent) => { setPractical(e.target.value); }; @@ -19,19 +20,14 @@ function BulkUsers() { }); }, []); - const handleFileChange = (event) => { + const handleFileChange = (event: React.ChangeEvent) => { const selectedFile = event.target.files[0]; - // if (selectedFile && selectedFile.type === "text/csv") { - setFile(selectedFile); parseCSV(selectedFile); - // } else { - // alert("Please upload a valid CSV file."); - // } }; - const parseCSV = (file) => { + const parseCSV = (file: File) => { const reader = new FileReader(); - reader.onload = (event) => { + reader.onload = (event: ProgressEvent) => { const text = event.target.result; const rows = text.split("\n").map((row) => row.split(",")); const formattedData = rows.map((row) => ({ @@ -71,7 +67,6 @@ function BulkUsers() { Name Email - {/* Add other headers as necessary */} @@ -91,11 +86,11 @@ function BulkUsers() { diff --git a/src/pages/admin/CreateTp.tsx b/src/pages/admin/CreateTp.tsx index d4aa53f..f685dac 100644 --- a/src/pages/admin/CreateTp.tsx +++ b/src/pages/admin/CreateTp.tsx @@ -14,14 +14,17 @@ function CreateTp() { }); const navigate = useNavigate(); - const handleInputChange = (e) => { + const handleInputChange = ( + e: React.ChangeEvent< + HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement + >, + ) => { const { name, value } = e.target; setPractical({ ...practical, [name]: value }); }; - const handleSubmit = (e) => { + const handleSubmit = (e: React.FormEvent) => { e.preventDefault(); - console.log("Practical created :", practical); axios.post("/api/tps", practical).then((res) => { if (res.status === 200) { navigate(`/tps/${res.data.id}`);