mirror of
https://github.com/ets-cfuhrman-pfe/EvalueTonSavoir.git
synced 2025-08-11 21:23:54 -04:00
error when user uses his own URL to copy a quiz
This commit is contained in:
parent
71f57fd2cf
commit
66ce4937d9
3 changed files with 34 additions and 17 deletions
|
|
@ -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 copied to clipboard!');
|
window.alert('URL a été copiée avec succès.');
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
window.alert('Failed to copy URL to clipboard.');
|
window.alert('Une erreur est survenue lors de la copie de l\'URL.');
|
||||||
});
|
});
|
||||||
|
|
||||||
handleCloseModal();
|
handleCloseModal();
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,12 @@
|
||||||
// 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>();
|
||||||
|
|
||||||
|
|
@ -23,7 +17,6 @@ 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);
|
||||||
|
|
@ -37,6 +30,14 @@ const Share: React.FC = () => {
|
||||||
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) {
|
||||||
|
|
|
||||||
|
|
@ -74,8 +74,6 @@ class ApiService {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("ApiService: isLoggedIn: Token:", token);
|
|
||||||
|
|
||||||
// Update token expiry
|
// Update token expiry
|
||||||
this.saveToken(token);
|
this.saveToken(token);
|
||||||
|
|
||||||
|
|
@ -91,7 +89,6 @@ 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
|
||||||
|
|
@ -103,7 +100,6 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
@ -178,7 +174,6 @@ 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';
|
||||||
|
|
@ -190,7 +185,6 @@ 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;
|
||||||
|
|
@ -553,7 +547,6 @@ 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) {
|
||||||
|
|
@ -1169,6 +1162,29 @@ 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[] = [];
|
||||||
|
|
||||||
|
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();
|
const apiService = new ApiService();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue