feat: enhance project and mentor management features

- Updated MentorProjectCard to provide more detailed success/error messages upon archiving and completing projects.
- Adjusted layout for certificate generation to improve visual alignment.
- Introduced resolveErrorMessage utility to standardize error message handling across the application.
- Enhanced customToast functionality to handle hook failures more gracefully.
- Refactored useCertificates hook to return structured responses for certificate claims and generation.
- Updated useMentors hook to improve error handling and response structure for mentor operations.
- Improved useNotification hook to return structured responses for marking notifications as read.
- Refactored useProjects hook to provide structured responses for project creation, updates, and member assignments.
- Enhanced useTasks hook to return structured responses for task creation, updates, and deletions.
- Updated services to return structured responses with messages for various API calls related to certificates, mentors, notifications, projects, tasks, and user management.
- Moved mentor-related types to a dedicated user.types file for better organization.
This commit is contained in:
Kemas M. Aryadary Rasyad
2026-07-16 22:50:56 +07:00
parent 99082efbdb
commit 62aaf2bcba
34 changed files with 408 additions and 425 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ const LAYOUT = {
internNameSmall: { x: 0.82, y: 0.889, size: 33, font: "Great Vibes", color: "#800000" },
projectName: { x: 0.815, y: 0.598, size: 46, font: "Grenze", color: "#800000" },
duration: { x: 0.692, y: 0.645, size: 48, font: "Grenze", color: "#090909" },
certNo: { x: 0.6, y: 0.305, size: 50, font: "Grenze", color: "#090909" },
certNo: { x: 0.6, y: 0.28, size: 50, font: "Grenze", color: "#090909" },
certNoSmall: { x: 0.825, y: 0.91, size: 22, font: "Grenze", color: "#800000" },
qr: { x: 0.77, y: 0.715, size: 0.103 },
};
+12
View File
@@ -0,0 +1,12 @@
// Ubah message backend (string ATAU object field-errors) jadi satu string aman
export function resolveErrorMessage(message: unknown, fallback = "Silakan coba lagi."): string {
if (typeof message === "string") return message;
if (message && typeof message === "object") {
// ambil semua value error, gabung: { end_date: "...", start_date: "..." } -> "... \n ..."
return Object.values(message as Record<string, unknown>)
.flat()
.filter((v): v is string => typeof v === "string")
.join(" ") || fallback;
}
return fallback;
}
+11 -1
View File
@@ -53,6 +53,16 @@ export const customToast = {
const loadingId = toast.loading(messages.loading);
try {
const data = await promise;
const isHookFailure = typeof data === 'object' && data !== null && 'success' in data && (data as { success?: boolean }).success === false;
if (isHookFailure) {
toast.dismiss(loadingId);
const result = data as { success: boolean; message?: string };
const { title, description } = messages.error(result);
customToast.error(title, description ?? result.message);
throw new Error(result.message ?? 'Operasi gagal.');
}
toast.dismiss(loadingId);
const { title, description } = messages.success(data);
customToast.success(title, description);
@@ -60,7 +70,7 @@ export const customToast = {
} catch (err) {
toast.dismiss(loadingId);
const { title, description } = messages.error(err);
customToast.error(title, description);
customToast.error(title, description ?? (err as Error)?.message);
throw err;
}
},