Implementasi Backend pada login, FAQ, Settings Intern, Projects Intern, Home Intern

This commit is contained in:
Kemas M. Aryadary Rasyad
2026-06-25 00:35:53 +07:00
parent 9e5a97ef10
commit f63efb0e12
29 changed files with 682 additions and 280 deletions
+59
View File
@@ -0,0 +1,59 @@
// hooks/useProjectDetail.ts
/**
* Bagian Detail dari Project: Ketika User sudah masuk ke dalam Project Card
* Komponen yang masuk: IDProject, ParticipantTab, ForumTab, Submissions
*/
import { useEffect, useState } from "react";
import { getProjectById, getProjectInterns, getProjectTasks } from "../services/ProjectService";
import type { Project, Intern, ProjectTask } from "../types/project.types";
export const useProjectDetail = (id: string) => {
const [project, setProject] = useState<Project | null>(null);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!id) return;
setLoading(true);
getProjectById(id)
.then(setProject)
.catch(() => setError("Gagal memuat detail project."))
.finally(() => setLoading(false));
}, [id]);
return { project, loading, error };
};
export const useProjectInterns = (projectId: string) => {
const [interns, setInterns] = useState<Intern[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!projectId) return;
setLoading(true);
getProjectInterns(projectId)
.then(setInterns)
.catch(() => setError("Gagal memuat participants."))
.finally(() => setLoading(false));
}, [projectId]);
return { interns, loading, error };
};
export const useProjectTasks = (projectId: string) => {
const [tasks, setTasks] = useState<ProjectTask[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!projectId) return;
setLoading(true);
getProjectTasks(projectId)
.then(setTasks)
.catch(() => setError("Gagal memuat tasks."))
.finally(() => setLoading(false));
}, [projectId]);
return { tasks, loading, error };
};
+40
View File
@@ -0,0 +1,40 @@
import { useEffect, useState } from "react";
// Projects
import { getMyProjects } from "../services/ProjectService";
import type { Project } from "../types/project.types";
// Tasks
import { getMyTasks } from "../services/ProjectService";
import type { InternTask } from "../types/project.types";
export const useProjects = () => {
const [projects, setProjects] = useState<Project[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
setLoading(true);
getMyProjects()
.then(setProjects)
.catch(() => setError("Gagal memuat project."))
.finally(() => setLoading(false));
}, []);
return { projects, loading, error };
};
export const useInternTasks = () => {
const [tasks, setTasks] = useState<InternTask[]>([]);
const [loading, setLoading] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
setLoading(true);
getMyTasks()
.then(setTasks)
.catch(() => setError("Gagal memuat tasks."))
.finally(() => setLoading(false));
}, []);
return { tasks, loading, error };
};