feat: implement mentor dashboard features including project task management, submission tracking, and modal-based task creation.

This commit is contained in:
Kemas M. Aryadary Rasyad
2026-06-26 18:05:54 +07:00
parent 53b270921d
commit 60aba4180e
19 changed files with 471 additions and 275 deletions
View File
+1 -1
View File
@@ -65,7 +65,7 @@ export const useProjectDetail = (id: string) => {
//Khusus Ambil Intern dari Project/{id}
export const useProjectInterns = (projectId: string) => {
const [interns, setInterns] = useState<ProjectMember[]>([]);
const [interns, setInterns] = useState<ProjectMember[]>([] );
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
+41 -1
View File
@@ -1,6 +1,6 @@
// hooks/useTasks.ts
import { useState, useEffect, useCallback } from "react";
import type { ProjectTask, ProjectTaskDetail, CreateTaskPayload, UpdateTaskPayload, TaskSubmissionData } from "../types/task.types";
import type { ProjectTask, ProjectTaskDetail, CreateTaskPayload, UpdateTaskPayload, TaskSubmissionData, AdminTaskDetail } from "../types/task.types";
import {
getProjectTasks,
getTaskById,
@@ -12,7 +12,10 @@ import {
updateSubmissionFile,
updateSubmissionLink,
deleteSubmission,
getAllMentorTasks,
getTaskSubmissions,
} from "../services/TaskService";
import type { MentorTaskItem } from "../types/task.types";
// GET /task-api/projects/{id_project}/tasks
export const useProjectTasks = (projectId: string) => {
@@ -54,6 +57,25 @@ export const useTaskDetail = (taskId: string, projectId?: string) => {
return { task, loading, error, refetch };
};
export const useTaskSubmissions = (taskId: string, projectId?: string) => {
const [task, setTask] = useState<AdminTaskDetail | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
const refetch = useCallback(() => {
if (!taskId) return;
setLoading(true);
getTaskSubmissions(taskId, projectId)
.then(setTask)
.catch(() => setError("Gagal memuat submissions."))
.finally(() => setLoading(false));
}, [taskId, projectId]);
useEffect(() => { refetch(); }, [refetch]);
return { task, loading, error, refetch };
};
// POST /task-api/projects/{id_project}/tasks
export const useCreateTask = (projectId: string) => {
const [loading, setLoading] = useState(false);
@@ -179,4 +201,22 @@ export const useSubmission = (taskId: string, initialSubmission?: TaskSubmission
};
return { submission, submitFile, submitLink, updateFile, updateLink, remove, loading, error };
};
// hooks/useAllMentorTasks.ts
export const useAllMentorTasks = (enabled: boolean) => {
const [tasks, setTasks] = useState<MentorTaskItem[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!enabled) return; // tidak fetch kalau intern
setLoading(true);
getAllMentorTasks()
.then(setTasks)
.catch(() => setError("Gagal memuat tasks mentor."))
.finally(() => setLoading(false));
}, [enabled]);
return { tasks, loading, error };
};
+24
View File
@@ -0,0 +1,24 @@
import { useState, useEffect } from "react";
import api from "../lib/api";
export interface CurrentUser {
id: number;
full_name: string;
email: string;
role: "mentor" | "intern" | "admin";
}
export const useCurrentUser = () => {
const [user, setUser] = useState<CurrentUser | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
api.get("/auth-api/me")
.then((res) => setUser(res.data.data))
.catch(() => setError("Gagal memuat user."))
.finally(() => setLoading(false));
}, []);
return { user, loading, error };
};