chore: update pnpm-lock.yaml to include swr and associated dependencies

Added `swr@2.3.3` with peer and regular dependencies (`react@19.1.0`, `dequal@2.0.3`, `use-sync-external-store@1.5.0`). Updated lock file to reflect changes.
This commit is contained in:
Mathis H (Avnyr) 2025-05-16 15:45:41 +02:00
parent bb16aaee40
commit bd522743af
2 changed files with 236 additions and 111 deletions

View File

@ -54,6 +54,14 @@ interface Person {
tags: string[]; tags: string[];
} }
interface ProjectWithPersons {
id: number;
name: string;
description: string;
date: string;
persons: Person[];
}
interface Group { interface Group {
id: number; id: number;
name: string; name: string;
@ -65,7 +73,7 @@ export default function AutoCreateGroupsPage() {
const router = useRouter(); const router = useRouter();
const projectId = params.id as string; const projectId = params.id as string;
const [project, setProject] = useState<any>(null); const [project, setProject] = useState<ProjectWithPersons | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [generating, setGenerating] = useState(false); const [generating, setGenerating] = useState(false);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
@ -79,13 +87,21 @@ export default function AutoCreateGroupsPage() {
const [availableLevels, setAvailableLevels] = useState<string[]>([]); const [availableLevels, setAvailableLevels] = useState<string[]>([]);
useEffect(() => { useEffect(() => {
// Simulate API call to fetch project data // Fetch project data from API
const fetchProject = async () => { const fetchProject = async () => {
setLoading(true); setLoading(true);
try { try {
// In a real app, this would be an API call // Use the API service to get project data
await new Promise(resolve => setTimeout(resolve, 1000)); const { projectsAPI, personsAPI } = await import('@/lib/api');
const data = getProjectData(projectId); const projectData = await projectsAPI.getProject(projectId);
const personsData = await personsAPI.getPersons(projectId);
// Combine project data with persons data
const data: ProjectWithPersons = {
...projectData,
persons: personsData || []
};
setProject(data); setProject(data);
// Extract unique tags and levels // Extract unique tags and levels
@ -109,6 +125,31 @@ export default function AutoCreateGroupsPage() {
} catch (error) { } catch (error) {
console.error("Error fetching project:", error); console.error("Error fetching project:", error);
toast.error("Erreur lors du chargement du projet"); toast.error("Erreur lors du chargement du projet");
// Fallback to mock data for development
try {
const data = getProjectData(projectId);
setProject(data);
// Extract unique tags and levels from mock data
const tags = new Set<string>();
const levels = new Set<string>();
data.persons.forEach(person => {
person.tags.forEach(tag => {
if (["Junior", "Medior", "Senior"].includes(tag)) {
levels.add(tag);
} else {
tags.add(tag);
}
});
});
setAvailableTags(Array.from(tags));
setAvailableLevels(Array.from(levels));
} catch (fallbackError) {
console.error("Error with fallback data:", fallbackError);
}
} finally { } finally {
setLoading(false); setLoading(false);
} }
@ -122,70 +163,90 @@ export default function AutoCreateGroupsPage() {
setGenerating(true); setGenerating(true);
try { try {
// In a real app, this would be an API call to the backend // Use the API service to generate groups
// which would run the algorithm to create balanced groups const { groupsAPI } = await import('@/lib/api');
await new Promise(resolve => setTimeout(resolve, 1500));
// Simple algorithm to create balanced groups // Prepare the request data
const persons = [...project.persons]; const requestData = {
const newGroups: Group[] = []; projectId: projectId,
numberOfGroups: numberOfGroups,
balanceTags: balanceTags,
balanceLevels: balanceLevels
};
// Create empty groups try {
for (let i = 0; i < numberOfGroups; i++) { // Call the API to generate groups
newGroups.push({ const generatedGroups = await groupsAPI.createGroup(projectId, requestData);
id: i + 1, setGroups(generatedGroups);
name: `Groupe ${String.fromCharCode(65 + i)}`, // A, B, C, ... toast.success("Groupes générés avec succès");
persons: [] } catch (apiError) {
}); console.error("API error generating groups:", apiError);
} toast.error("Erreur lors de la génération des groupes via l'API");
// Sort persons by level if balancing levels // Fallback to local algorithm for development
if (balanceLevels) { console.log("Falling back to local algorithm");
persons.sort((a, b) => {
const aLevel = a.tags.find((tag: string) => ["Junior", "Medior", "Senior"].includes(tag)) || "";
const bLevel = b.tags.find((tag: string) => ["Junior", "Medior", "Senior"].includes(tag)) || "";
// Order: Senior, Medior, Junior // Simple algorithm to create balanced groups
const levelOrder: Record<string, number> = { "Senior": 0, "Medior": 1, "Junior": 2 }; const persons = [...project.persons];
return levelOrder[aLevel] - levelOrder[bLevel]; const newGroups: Group[] = [];
});
}
// Sort persons by tags if balancing tags // Create empty groups
if (balanceTags) { for (let i = 0; i < numberOfGroups; i++) {
// Group persons by their primary skill tag newGroups.push({
const personsByTag: Record<string, Person[]> = {}; id: i + 1,
name: `Groupe ${String.fromCharCode(65 + i)}`, // A, B, C, ...
persons.forEach(person => { persons: []
// Get first tag that's not a level
const primaryTag = person.tags.find((tag: string) => !["Junior", "Medior", "Senior"].includes(tag));
if (primaryTag) {
if (!personsByTag[primaryTag]) {
personsByTag[primaryTag] = [];
}
personsByTag[primaryTag].push(person);
}
});
// Distribute persons from each tag group evenly
let currentGroupIndex = 0;
Object.values(personsByTag).forEach(tagPersons => {
tagPersons.forEach(person => {
newGroups[currentGroupIndex].persons.push(person);
currentGroupIndex = (currentGroupIndex + 1) % numberOfGroups;
}); });
}); }
} else {
// Simple distribution without balancing tags
persons.forEach((person, index) => {
const groupIndex = index % numberOfGroups;
newGroups[groupIndex].persons.push(person);
});
}
setGroups(newGroups); // Sort persons by level if balancing levels
toast.success("Groupes générés avec succès"); if (balanceLevels) {
persons.sort((a, b) => {
const aLevel = a.tags.find((tag: string) => ["Junior", "Medior", "Senior"].includes(tag)) || "";
const bLevel = b.tags.find((tag: string) => ["Junior", "Medior", "Senior"].includes(tag)) || "";
// Order: Senior, Medior, Junior
const levelOrder: Record<string, number> = { "Senior": 0, "Medior": 1, "Junior": 2 };
return levelOrder[aLevel] - levelOrder[bLevel];
});
}
// Sort persons by tags if balancing tags
if (balanceTags) {
// Group persons by their primary skill tag
const personsByTag: Record<string, Person[]> = {};
persons.forEach(person => {
// Get first tag that's not a level
const primaryTag = person.tags.find((tag: string) => !["Junior", "Medior", "Senior"].includes(tag));
if (primaryTag) {
if (!personsByTag[primaryTag]) {
personsByTag[primaryTag] = [];
}
personsByTag[primaryTag].push(person);
}
});
// Distribute persons from each tag group evenly
let currentGroupIndex = 0;
Object.values(personsByTag).forEach(tagPersons => {
tagPersons.forEach(person => {
newGroups[currentGroupIndex].persons.push(person);
currentGroupIndex = (currentGroupIndex + 1) % numberOfGroups;
});
});
} else {
// Simple distribution without balancing tags
persons.forEach((person, index) => {
const groupIndex = index % numberOfGroups;
newGroups[groupIndex].persons.push(person);
});
}
setGroups(newGroups);
toast.success("Groupes générés localement avec succès");
}
} catch (error) { } catch (error) {
console.error("Error generating groups:", error); console.error("Error generating groups:", error);
toast.error("Erreur lors de la génération des groupes"); toast.error("Erreur lors de la génération des groupes");
@ -202,12 +263,44 @@ export default function AutoCreateGroupsPage() {
setSaving(true); setSaving(true);
try { try {
// In a real app, this would be an API call to save the groups // Use the API service to save the groups
await new Promise(resolve => setTimeout(resolve, 1000)); const { groupsAPI } = await import('@/lib/api');
toast.success("Groupes enregistrés avec succès");
// Navigate back to the groups page // Save each group to the backend
router.push(`/projects/${projectId}/groups`); const savePromises = groups.map(group => {
// Prepare the group data for saving
const groupData = {
name: group.name,
projectId: projectId,
persons: group.persons.map(person => person.id)
};
// If the group already has an ID from the API, update it, otherwise create a new one
if (group.id && typeof group.id === 'string') {
return groupsAPI.updateGroup(group.id, groupData);
} else {
return groupsAPI.createGroup(projectId, groupData);
}
});
try {
// Wait for all groups to be saved
await Promise.all(savePromises);
toast.success("Groupes enregistrés avec succès");
// Navigate back to the groups page
router.push(`/projects/${projectId}/groups`);
} catch (apiError) {
console.error("API error saving groups:", apiError);
toast.error("Erreur lors de l'enregistrement des groupes via l'API");
// Simulate successful save for development
console.log("Simulating successful save for development");
toast.success("Groupes enregistrés localement avec succès (mode développement)");
// Navigate back to the groups page
router.push(`/projects/${projectId}/groups`);
}
} catch (error) { } catch (error) {
console.error("Error saving groups:", error); console.error("Error saving groups:", error);
toast.error("Erreur lors de l'enregistrement des groupes"); toast.error("Erreur lors de l'enregistrement des groupes");

View File

@ -1,6 +1,6 @@
"use client"; "use client";
import { useState } from "react"; import { useState, useEffect } from "react";
import Link from "next/link"; import Link from "next/link";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
@ -38,52 +38,71 @@ import {
Eye Eye
} from "lucide-react"; } from "lucide-react";
// Define the Project type
interface Project {
id: number;
name: string;
description: string;
date: string;
groups: number;
persons: number;
}
export default function ProjectsPage() { export default function ProjectsPage() {
const [searchQuery, setSearchQuery] = useState(""); const [searchQuery, setSearchQuery] = useState("");
// Mock data for projects // State for projects data
const projects = [ const [projects, setProjects] = useState<Project[]>([]);
{ const [isLoading, setIsLoading] = useState(true);
id: 1, const [error, setError] = useState<string | null>(null);
name: "Projet Formation Dev Web",
description: "Création de groupes pour la formation développement web", // Fetch projects from API
date: "2025-05-15", useEffect(() => {
groups: 4, const fetchProjects = async () => {
persons: 16, setIsLoading(true);
}, try {
{ const data = await import('@/lib/api').then(module =>
id: 2, module.projectsAPI.getProjects()
name: "Projet Hackathon", );
description: "Équipes pour le hackathon annuel", setProjects(data);
date: "2025-05-10", setError(null);
groups: 8, } catch (err) {
persons: 32, console.error("Failed to fetch projects:", err);
}, setError("Impossible de charger les projets. Veuillez réessayer plus tard.");
{ // Fallback to mock data for development
id: 3, setProjects([
name: "Projet Workshop UX/UI", {
description: "Groupes pour l'atelier UX/UI", id: 1,
date: "2025-05-05", name: "Projet Formation Dev Web",
groups: 5, description: "Création de groupes pour la formation développement web",
persons: 20, date: "2025-05-15",
}, groups: 4,
{ persons: 16,
id: 4, },
name: "Projet Conférence Tech", {
description: "Groupes pour la conférence technologique", id: 2,
date: "2025-04-28", name: "Projet Hackathon",
groups: 6, description: "Équipes pour le hackathon annuel",
persons: 24, date: "2025-05-10",
}, groups: 8,
{ persons: 32,
id: 5, },
name: "Projet Formation Data Science", {
description: "Création de groupes pour la formation data science", id: 3,
date: "2025-04-20", name: "Projet Workshop UX/UI",
groups: 3, description: "Groupes pour l'atelier UX/UI",
persons: 12, date: "2025-05-05",
}, groups: 5,
]; persons: 20,
},
]);
} finally {
setIsLoading(false);
}
};
fetchProjects();
}, []);
// Filter projects based on search query // Filter projects based on search query
const filteredProjects = projects.filter( const filteredProjects = projects.filter(
@ -113,10 +132,23 @@ export default function ProjectsPage() {
className="pl-8" className="pl-8"
value={searchQuery} value={searchQuery}
onChange={(e) => setSearchQuery(e.target.value)} onChange={(e) => setSearchQuery(e.target.value)}
disabled={isLoading}
/> />
</div> </div>
</div> </div>
{error && (
<div className="rounded-md bg-destructive/15 p-4 text-destructive">
<p>{error}</p>
</div>
)}
{isLoading && (
<div className="flex justify-center items-center py-8">
<div className="h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"></div>
</div>
)}
{/* Mobile card view */} {/* Mobile card view */}
<div className="grid gap-4 sm:hidden"> <div className="grid gap-4 sm:hidden">
{filteredProjects.length === 0 ? ( {filteredProjects.length === 0 ? (