refactor: integrate EvaluationClient and remove legacy evaluation actions
- Added EvaluationClient to clients/index.ts and created an instance for use. - Updated client-wrapper.tsx and welcome-screen.tsx to utilize EvaluationClient for evaluation actions. - Removed obsolete evaluation-actions.ts file to streamline codebase and reduce redundancy.
This commit is contained in:
122
clients/domains/evaluation-client.ts
Normal file
122
clients/domains/evaluation-client.ts
Normal file
@@ -0,0 +1,122 @@
|
||||
import { BaseHttpClient } from "../base/http-client";
|
||||
import { SkillLevel } from "../../lib/types";
|
||||
|
||||
export class EvaluationClient extends BaseHttpClient {
|
||||
/**
|
||||
* Met à jour le niveau d'une compétence
|
||||
*/
|
||||
updateSkillLevel = async (
|
||||
category: string,
|
||||
skillId: string,
|
||||
level: SkillLevel
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await this.put("/evaluations/skills", {
|
||||
action: "updateLevel",
|
||||
category,
|
||||
skillId,
|
||||
level,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to update skill level:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Met à jour le statut mentor d'une compétence
|
||||
*/
|
||||
updateSkillMentorStatus = async (
|
||||
category: string,
|
||||
skillId: string,
|
||||
canMentor: boolean
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await this.put("/evaluations/skills", {
|
||||
action: "updateMentorStatus",
|
||||
category,
|
||||
skillId,
|
||||
canMentor,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to update skill mentor status:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Met à jour le statut d'apprentissage d'une compétence
|
||||
*/
|
||||
updateSkillLearningStatus = async (
|
||||
category: string,
|
||||
skillId: string,
|
||||
wantsToLearn: boolean
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await this.put("/evaluations/skills", {
|
||||
action: "updateLearningStatus",
|
||||
category,
|
||||
skillId,
|
||||
wantsToLearn,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to update skill learning status:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Ajoute une compétence à l'évaluation
|
||||
*/
|
||||
addSkillToEvaluation = async (
|
||||
category: string,
|
||||
skillId: string
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await this.put("/evaluations/skills", {
|
||||
action: "addSkill",
|
||||
category,
|
||||
skillId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to add skill to evaluation:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Supprime une compétence de l'évaluation
|
||||
*/
|
||||
removeSkillFromEvaluation = async (
|
||||
category: string,
|
||||
skillId: string
|
||||
): Promise<void> => {
|
||||
try {
|
||||
await this.put("/evaluations/skills", {
|
||||
action: "removeSkill",
|
||||
category,
|
||||
skillId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to remove skill from evaluation:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialise une évaluation vide pour un profil
|
||||
*/
|
||||
initializeEmptyEvaluation = async (
|
||||
profile: import("../../lib/types").UserProfile
|
||||
): Promise<void> => {
|
||||
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("../index");
|
||||
await authClient.login(profile);
|
||||
} catch (error) {
|
||||
console.error("Failed to initialize evaluation:", error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -2,13 +2,16 @@
|
||||
import { SkillsClient } from "./domains/skills-client";
|
||||
import { AuthClient } from "./domains/auth-client";
|
||||
import { AdminClient } from "./domains/admin-client";
|
||||
import { EvaluationClient } from "./domains/evaluation-client";
|
||||
|
||||
// Export all client classes
|
||||
export { SkillsClient } from "./domains/skills-client";
|
||||
export { AuthClient } from "./domains/auth-client";
|
||||
export { AdminClient } from "./domains/admin-client";
|
||||
export { EvaluationClient } from "./domains/evaluation-client";
|
||||
|
||||
// Create and export client instances
|
||||
export const skillsClient = new SkillsClient();
|
||||
export const authClient = new AuthClient();
|
||||
export const adminClient = new AdminClient();
|
||||
export const evaluationClient = new EvaluationClient();
|
||||
|
||||
@@ -9,13 +9,14 @@ import {
|
||||
UserProfile,
|
||||
CategoryEvaluation,
|
||||
} from "@/lib/types";
|
||||
import {
|
||||
updateSkillLevel as updateSkillLevelAction,
|
||||
updateSkillMentorStatus as updateSkillMentorStatusAction,
|
||||
updateSkillLearningStatus as updateSkillLearningStatusAction,
|
||||
addSkillToEvaluation as addSkillToEvaluationAction,
|
||||
removeSkillFromEvaluation as removeSkillFromEvaluationAction,
|
||||
} from "@/lib/evaluation-actions";
|
||||
import { evaluationClient } from "@/clients";
|
||||
const {
|
||||
updateSkillLevel: updateSkillLevelAction,
|
||||
updateSkillMentorStatus: updateSkillMentorStatusAction,
|
||||
updateSkillLearningStatus: updateSkillLearningStatusAction,
|
||||
addSkillToEvaluation: addSkillToEvaluationAction,
|
||||
removeSkillFromEvaluation: removeSkillFromEvaluationAction,
|
||||
} = evaluationClient;
|
||||
import { createEmptyEvaluation } from "@/lib/evaluation-utils";
|
||||
|
||||
interface EvaluationClientWrapperProps {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { useState } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { ProfileForm } from "@/components/profile-form";
|
||||
import { initializeEmptyEvaluation } from "@/lib/evaluation-actions";
|
||||
import { evaluationClient } from "@/clients";
|
||||
import { Team, UserProfile } from "@/lib/types";
|
||||
import { Code2 } from "lucide-react";
|
||||
|
||||
@@ -20,7 +20,7 @@ export function WelcomeEvaluationScreen({
|
||||
const handleProfileSubmit = async (profile: UserProfile) => {
|
||||
setIsSubmitting(true);
|
||||
try {
|
||||
await initializeEmptyEvaluation(profile);
|
||||
await evaluationClient.initializeEmptyEvaluation(profile);
|
||||
// Rafraîchir la page pour que le SSR prenne en compte la nouvelle évaluation
|
||||
router.refresh();
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,169 +0,0 @@
|
||||
"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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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<void> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user