diff --git a/client/src/components/ShareQuizModal/ShareQuizModal.tsx b/client/src/components/ShareQuizModal/ShareQuizModal.tsx index 7bd5dd5..336aadb 100644 --- a/client/src/components/ShareQuizModal/ShareQuizModal.tsx +++ b/client/src/components/ShareQuizModal/ShareQuizModal.tsx @@ -40,10 +40,10 @@ const ShareQuizModal: React.FC = ({ quiz }) => { const quizUrl = `${window.location.origin}/teacher/share/${quiz._id}`; navigator.clipboard.writeText(quizUrl) .then(() => { - window.alert('URL copied to clipboard!'); + window.alert('URL a été copiée avec succès.'); }) .catch(() => { - window.alert('Failed to copy URL to clipboard.'); + window.alert('Une erreur est survenue lors de la copie de l\'URL.'); }); handleCloseModal(); diff --git a/client/src/pages/Teacher/Share/Share.tsx b/client/src/pages/Teacher/Share/Share.tsx index 093787e..613d290 100644 --- a/client/src/pages/Teacher/Share/Share.tsx +++ b/client/src/pages/Teacher/Share/Share.tsx @@ -1,18 +1,12 @@ -// EditorQuiz.tsx import React, { useState, useEffect } from 'react'; import { useParams, useNavigate } from 'react-router-dom'; - import { FolderType } from '../../../Types/FolderType'; - - import './share.css'; import { Button, NativeSelect } from '@mui/material'; import ReturnButton from 'src/components/ReturnButton/ReturnButton'; - import ApiService from '../../../services/ApiService'; const Share: React.FC = () => { - console.log('Component rendered'); const navigate = useNavigate(); const { id } = useParams(); @@ -23,7 +17,6 @@ const Share: React.FC = () => { useEffect(() => { const fetchData = async () => { - console.log("QUIZID : " + id) if (!id) { window.alert(`Une erreur est survenue.\n Le quiz n'a pas été trouvé\nVeuillez réessayer plus tard`) console.error('Quiz not found for id:', id); @@ -36,9 +29,17 @@ const Share: React.FC = () => { navigate("/login"); return; } + + const quizIds = await ApiService.getAllQuizIds(); + + if (quizIds.includes(id)) { + window.alert(`Le quiz que vous essayez d'importer existe déjà sur votre compte.`) + navigate('/teacher/dashboard'); + return; + } const userFolders = await ApiService.getUserFolders(); - + if (userFolders.length == 0) { window.alert(`Vous n'avez aucun dossier.\nVeuillez en créer un et revenir à ce lien`) navigate('/teacher/dashboard'); diff --git a/client/src/services/ApiService.tsx b/client/src/services/ApiService.tsx index b13a369..7764555 100644 --- a/client/src/services/ApiService.tsx +++ b/client/src/services/ApiService.tsx @@ -74,8 +74,6 @@ class ApiService { return false; } - console.log("ApiService: isLoggedIn: Token:", token); - // Update token expiry this.saveToken(token); @@ -91,7 +89,6 @@ class ApiService { } try { - console.log("ApiService: isLoggedInTeacher: Token:", token); const decodedToken = jwtDecode(token) as { roles: string[] }; /////// REMOVE BELOW @@ -103,7 +100,6 @@ class ApiService { const userRoles = decodedToken.roles; const requiredRole = 'teacher'; - console.log("ApiService: isLoggedInTeacher: UserRoles:", userRoles); if (!userRoles || !userRoles.includes(requiredRole)) { return false; } @@ -178,7 +174,6 @@ class ApiService { const result: AxiosResponse = await axios.post(url, body, { headers: headers }); - console.log(result); if (result.status == 200) { //window.location.href = result.request.responseURL; window.location.href = '/login'; @@ -190,7 +185,6 @@ class ApiService { return true; } catch (error) { - console.log("Error details: ", error); if (axios.isAxiosError(error)) { const err = error as AxiosError; @@ -553,7 +547,6 @@ public async login(email: string, password: string): Promise { const headers = this.constructRequestHeaders(); const body = { folderId }; - console.log(headers); const result: AxiosResponse = await axios.post(url, body, { headers: headers }); if (result.status !== 200) { @@ -1169,6 +1162,29 @@ public async login(email: string, password: string): Promise { } // NOTE : Get Image pas necessaire + public async getAllQuizIds(): Promise { + try { + const folders = await this.getUserFolders(); + + const allQuizIds: string[] = []; + + for (const folder of folders) { + const folderQuizzes = await this.getFolderContent(folder._id); + + if (Array.isArray(folderQuizzes)) { + allQuizIds.push(...folderQuizzes.map(quiz => quiz._id)); + } + } + + return allQuizIds; + } catch (error) { + console.error('Failed to get all quiz ids:', error); + throw error; + } + } + + + } const apiService = new ApiService();