feat(v3): restructure project + add complete frontend
- Restructure: move backend from new_project/ to backend/ - Add full React/TypeScript frontend (37 pages, 17 services, 16 type defs, 11 query hooks) - Add docs/ with SRS specs, user stories, and workflow documentation - Update .gitignore for new directory layout Workflows implemented: WF1 User Signup, WF2 Placement Test, WF3 Exam Configuration, WF4 General English Exam, WF5 Course Generation, WF6 Entity Student Onboarding, AI Course Generation, Adaptive Learning Engine UI, White-Label Branding, Score Release Made-with: Cursor
This commit is contained in:
97
src/hooks/queries/useLms.ts
Normal file
97
src/hooks/queries/useLms.ts
Normal file
@@ -0,0 +1,97 @@
|
||||
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
||||
import { queryKeys } from "./keys";
|
||||
import { lmsService } from "@/services";
|
||||
import type { PaginationParams, CourseCreateRequest, LmsStudentCreateRequest, LmsTeacherCreateRequest } from "@/types";
|
||||
|
||||
export function useCourses(params?: PaginationParams & { status?: string }) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.courses(params),
|
||||
queryFn: () => lmsService.listCourses(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCourse(id: number) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.course(id),
|
||||
queryFn: () => lmsService.getCourse(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateCourse() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: CourseCreateRequest) => lmsService.createCourse(data),
|
||||
onSuccess: () => qc.invalidateQueries({ queryKey: ["lms", "courses"] }),
|
||||
});
|
||||
}
|
||||
|
||||
export function useStudents(params?: PaginationParams & { search?: string; batch_id?: number }) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.students(params),
|
||||
queryFn: () => lmsService.listStudents(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateStudent() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: LmsStudentCreateRequest) => lmsService.createStudent(data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["lms", "students"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useTeachers(params?: PaginationParams & { search?: string }) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.teachers(params),
|
||||
queryFn: () => lmsService.listTeachers(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useCreateTeacher() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: LmsTeacherCreateRequest) => lmsService.createTeacher(data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: ["lms", "teachers"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useBatches(params?: PaginationParams) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.batches(params),
|
||||
queryFn: () => lmsService.listBatches(params),
|
||||
});
|
||||
}
|
||||
|
||||
export function useBatch(id: number) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.batch(id),
|
||||
queryFn: () => lmsService.getBatch(id),
|
||||
enabled: !!id,
|
||||
});
|
||||
}
|
||||
|
||||
export function useTimetable(params?: Record<string, unknown>) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.timetable(params),
|
||||
queryFn: () => lmsService.getTimetable(params as Record<string, string | number | boolean | undefined>),
|
||||
});
|
||||
}
|
||||
|
||||
export function useAttendance(params?: Record<string, unknown>) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.attendance(params),
|
||||
queryFn: () => lmsService.getAttendance(params as Record<string, string | number | boolean | undefined>),
|
||||
});
|
||||
}
|
||||
|
||||
export function useGrades(params?: Record<string, unknown>) {
|
||||
return useQuery({
|
||||
queryKey: queryKeys.lms.grades(params),
|
||||
queryFn: () => lmsService.getGrades(params as Record<string, string | number | boolean | undefined>),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user