Compare commits

..

No commits in common. "2ca21a7d6b80100d297dce32c01a4c918b58b4b2" and "71f57fd2cf5d67e2f84f267ba81162b8374ca113" have entirely different histories.

3 changed files with 17 additions and 38 deletions

View file

@ -40,10 +40,10 @@ const ShareQuizModal: React.FC<ShareQuizModalProps> = ({ quiz }) => {
const quizUrl = `${window.location.origin}/teacher/share/${quiz._id}`; const quizUrl = `${window.location.origin}/teacher/share/${quiz._id}`;
navigator.clipboard.writeText(quizUrl) navigator.clipboard.writeText(quizUrl)
.then(() => { .then(() => {
window.alert('URL a été copiée avec succès.'); window.alert('URL copied to clipboard!');
}) })
.catch(() => { .catch(() => {
window.alert('Une erreur est survenue lors de la copie de l\'URL.'); window.alert('Failed to copy URL to clipboard.');
}); });
handleCloseModal(); handleCloseModal();

View file

@ -1,12 +1,18 @@
// EditorQuiz.tsx
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom'; import { useParams, useNavigate } from 'react-router-dom';
import { FolderType } from '../../../Types/FolderType'; import { FolderType } from '../../../Types/FolderType';
import './share.css'; import './share.css';
import { Button, NativeSelect } from '@mui/material'; import { Button, NativeSelect } from '@mui/material';
import ReturnButton from 'src/components/ReturnButton/ReturnButton'; import ReturnButton from 'src/components/ReturnButton/ReturnButton';
import ApiService from '../../../services/ApiService'; import ApiService from '../../../services/ApiService';
const Share: React.FC = () => { const Share: React.FC = () => {
console.log('Component rendered');
const navigate = useNavigate(); const navigate = useNavigate();
const { id } = useParams<string>(); const { id } = useParams<string>();
@ -17,6 +23,7 @@ const Share: React.FC = () => {
useEffect(() => { useEffect(() => {
const fetchData = async () => { const fetchData = async () => {
console.log("QUIZID : " + id)
if (!id) { if (!id) {
window.alert(`Une erreur est survenue.\n Le quiz n'a pas été trouvé\nVeuillez réessayer plus tard`) 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); console.error('Quiz not found for id:', id);
@ -29,17 +36,9 @@ const Share: React.FC = () => {
navigate("/login"); navigate("/login");
return; 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(); const userFolders = await ApiService.getUserFolders();
if (userFolders.length == 0) { if (userFolders.length == 0) {
window.alert(`Vous n'avez aucun dossier.\nVeuillez en créer un et revenir à ce lien`) window.alert(`Vous n'avez aucun dossier.\nVeuillez en créer un et revenir à ce lien`)
navigate('/teacher/dashboard'); navigate('/teacher/dashboard');

View file

@ -74,6 +74,8 @@ class ApiService {
return false; return false;
} }
console.log("ApiService: isLoggedIn: Token:", token);
// Update token expiry // Update token expiry
this.saveToken(token); this.saveToken(token);
@ -89,6 +91,7 @@ class ApiService {
} }
try { try {
console.log("ApiService: isLoggedInTeacher: Token:", token);
const decodedToken = jwtDecode(token) as { roles: string[] }; const decodedToken = jwtDecode(token) as { roles: string[] };
/////// REMOVE BELOW /////// REMOVE BELOW
@ -100,6 +103,7 @@ class ApiService {
const userRoles = decodedToken.roles; const userRoles = decodedToken.roles;
const requiredRole = 'teacher'; const requiredRole = 'teacher';
console.log("ApiService: isLoggedInTeacher: UserRoles:", userRoles);
if (!userRoles || !userRoles.includes(requiredRole)) { if (!userRoles || !userRoles.includes(requiredRole)) {
return false; return false;
} }
@ -174,6 +178,7 @@ class ApiService {
const result: AxiosResponse = await axios.post(url, body, { headers: headers }); const result: AxiosResponse = await axios.post(url, body, { headers: headers });
console.log(result);
if (result.status == 200) { if (result.status == 200) {
//window.location.href = result.request.responseURL; //window.location.href = result.request.responseURL;
window.location.href = '/login'; window.location.href = '/login';
@ -185,6 +190,7 @@ class ApiService {
return true; return true;
} catch (error) { } catch (error) {
console.log("Error details: ", error);
if (axios.isAxiosError(error)) { if (axios.isAxiosError(error)) {
const err = error as AxiosError; const err = error as AxiosError;
@ -547,6 +553,7 @@ public async login(email: string, password: string): Promise<any> {
const headers = this.constructRequestHeaders(); const headers = this.constructRequestHeaders();
const body = { folderId }; const body = { folderId };
console.log(headers);
const result: AxiosResponse = await axios.post(url, body, { headers: headers }); const result: AxiosResponse = await axios.post(url, body, { headers: headers });
if (result.status !== 200) { if (result.status !== 200) {
@ -1162,33 +1169,6 @@ public async login(email: string, password: string): Promise<any> {
} }
// NOTE : Get Image pas necessaire // NOTE : Get Image pas necessaire
public async getAllQuizIds(): Promise<string[]> {
try {
const folders = await this.getUserFolders();
const allQuizIds: string[] = [];
if (Array.isArray(folders)) {
for (const folder of folders) {
const folderQuizzes = await this.getFolderContent(folder._id);
if (Array.isArray(folderQuizzes)) {
allQuizIds.push(...folderQuizzes.map(quiz => quiz._id));
}
}
} else {
console.error('Failed to get user folders:', folders);
}
return allQuizIds;
} catch (error) {
console.error('Failed to get all quiz ids:', error);
throw error;
}
}
} }
const apiService = new ApiService(); const apiService = new ApiService();