"use client"; import { SkillLevel } from "@/lib/types"; /** * Actions d'évaluation standalone pour SSR * Ces fonctions utilisent directement l'API sans refetch de toutes les données */ export async function updateSkillLevel( category: string, skillId: string, level: SkillLevel ): Promise { try { const response = await fetch("/api/evaluations/skills", { method: "PUT", headers: { "Content-Type": "application/json", }, credentials: "same-origin", body: JSON.stringify({ action: "updateLevel", category, skillId, level, }), }); if (!response.ok) { const errorData = await response.text(); console.error("API Error:", response.status, errorData); throw new Error( `Failed to update skill level: ${response.status} - ${errorData}` ); } // Note: La page se rafraîchira via router.refresh() appelé par le composant } catch (error) { console.error("Failed to update skill level:", error); throw error; } } export async function updateSkillMentorStatus( category: string, skillId: string, canMentor: boolean ): Promise { try { const response = await fetch("/api/evaluations/skills", { method: "PUT", headers: { "Content-Type": "application/json", }, credentials: "same-origin", body: JSON.stringify({ action: "updateMentorStatus", category, skillId, canMentor, }), }); if (!response.ok) { throw new Error("Failed to update skill mentor status"); } } catch (error) { console.error("Failed to update skill mentor status:", error); throw error; } } export async function updateSkillLearningStatus( category: string, skillId: string, wantsToLearn: boolean ): Promise { try { const response = await fetch("/api/evaluations/skills", { method: "PUT", headers: { "Content-Type": "application/json", }, credentials: "same-origin", body: JSON.stringify({ action: "updateLearningStatus", category, skillId, wantsToLearn, }), }); if (!response.ok) { throw new Error("Failed to update skill learning status"); } } catch (error) { console.error("Failed to update skill learning status:", error); throw error; } } export async function addSkillToEvaluation( category: string, skillId: string ): Promise { try { const response = await fetch("/api/evaluations/skills", { method: "PUT", headers: { "Content-Type": "application/json", }, credentials: "same-origin", body: JSON.stringify({ action: "addSkill", category, skillId, }), }); if (!response.ok) { throw new Error("Failed to add skill to evaluation"); } } catch (error) { console.error("Failed to add skill to evaluation:", error); throw error; } } export async function removeSkillFromEvaluation( category: string, skillId: string ): Promise { try { const response = await fetch("/api/evaluations/skills", { method: "PUT", headers: { "Content-Type": "application/json", }, credentials: "same-origin", body: JSON.stringify({ action: "removeSkill", category, skillId, }), }); if (!response.ok) { throw new Error("Failed to remove skill from evaluation"); } } catch (error) { console.error("Failed to remove skill from evaluation:", error); throw error; } } export async function initializeEmptyEvaluation( profile: import("@/lib/types").UserProfile ): Promise { try { // Simplement créer le profil via l'auth, pas besoin de créer une évaluation vide // Le backend créera automatiquement l'évaluation lors du premier accès const { authClient } = await import("@/clients"); await authClient.login(profile); } catch (error) { console.error("Failed to initialize evaluation:", error); throw error; } }