Update frontend/src/pages/AdminClasses.jsx
Browse files
frontend/src/pages/AdminClasses.jsx
CHANGED
|
@@ -2,17 +2,7 @@
|
|
| 2 |
import React, { useState } from "react";
|
| 3 |
import api from "../api/client";
|
| 4 |
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
| 5 |
-
|
| 6 |
-
import { Button } from "../components/ui/button";
|
| 7 |
-
import {
|
| 8 |
-
Card,
|
| 9 |
-
CardContent,
|
| 10 |
-
CardHeader,
|
| 11 |
-
CardTitle,
|
| 12 |
-
CardDescription,
|
| 13 |
-
} from "../components/ui/card";
|
| 14 |
import { Plus } from "lucide-react";
|
| 15 |
-
|
| 16 |
import ClassForm from "../components/admin/ClassForm";
|
| 17 |
import ClassesTable from "../components/admin/ClassesTable";
|
| 18 |
import ClassStudentManager from "../components/admin/ClassStudentManager";
|
|
@@ -21,7 +11,7 @@ import ClassStudentManager from "../components/admin/ClassStudentManager";
|
|
| 21 |
|
| 22 |
async function fetchClasses() {
|
| 23 |
const res = await api.get("/api/admin/classes");
|
| 24 |
-
return res.data
|
| 25 |
}
|
| 26 |
|
| 27 |
async function createClassRequest(classData) {
|
|
@@ -38,6 +28,8 @@ async function deleteClassRequest(id) {
|
|
| 38 |
await api.delete(`/api/admin/classes/${id}`);
|
| 39 |
}
|
| 40 |
|
|
|
|
|
|
|
| 41 |
export default function AdminClasses() {
|
| 42 |
const queryClient = useQueryClient();
|
| 43 |
const [showForm, setShowForm] = useState(false);
|
|
@@ -98,30 +90,30 @@ export default function AdminClasses() {
|
|
| 98 |
</p>
|
| 99 |
</div>
|
| 100 |
|
| 101 |
-
{/* Class Form */}
|
| 102 |
-
<
|
| 103 |
-
<
|
| 104 |
-
<div
|
| 105 |
-
<
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
</CardDescription>
|
| 110 |
-
</div>
|
| 111 |
-
<Button
|
| 112 |
-
onClick={() => {
|
| 113 |
-
setEditingClass(null);
|
| 114 |
-
setShowForm(!showForm);
|
| 115 |
-
}}
|
| 116 |
-
className="gap-2 bg-red-600 hover:bg-red-700"
|
| 117 |
-
>
|
| 118 |
-
<Plus className="w-4 h-4" />
|
| 119 |
-
{showForm ? "Cancel" : "New Class"}
|
| 120 |
-
</Button>
|
| 121 |
</div>
|
| 122 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
{showForm && (
|
| 124 |
-
<
|
| 125 |
<ClassForm
|
| 126 |
classData={editingClass}
|
| 127 |
onSave={handleSaveClass}
|
|
@@ -133,9 +125,9 @@ export default function AdminClasses() {
|
|
| 133 |
createClassMutation.isPending || updateClassMutation.isPending
|
| 134 |
}
|
| 135 |
/>
|
| 136 |
-
</
|
| 137 |
)}
|
| 138 |
-
</
|
| 139 |
|
| 140 |
{/* Student Manager (when a class is selected) */}
|
| 141 |
{managingClass && (
|
|
@@ -147,15 +139,15 @@ export default function AdminClasses() {
|
|
| 147 |
</div>
|
| 148 |
)}
|
| 149 |
|
| 150 |
-
{/* Classes Table */}
|
| 151 |
-
<
|
| 152 |
-
<
|
| 153 |
-
<
|
| 154 |
-
<
|
| 155 |
Manage class schedules and enrollments
|
| 156 |
-
</
|
| 157 |
-
</
|
| 158 |
-
<
|
| 159 |
<ClassesTable
|
| 160 |
classes={classes}
|
| 161 |
isLoading={isLoading}
|
|
@@ -170,8 +162,8 @@ export default function AdminClasses() {
|
|
| 170 |
}}
|
| 171 |
onManageStudents={(cls) => setManagingClass(cls)}
|
| 172 |
/>
|
| 173 |
-
</
|
| 174 |
-
</
|
| 175 |
</div>
|
| 176 |
);
|
| 177 |
}
|
|
|
|
| 2 |
import React, { useState } from "react";
|
| 3 |
import api from "../api/client";
|
| 4 |
import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
import { Plus } from "lucide-react";
|
|
|
|
| 6 |
import ClassForm from "../components/admin/ClassForm";
|
| 7 |
import ClassesTable from "../components/admin/ClassesTable";
|
| 8 |
import ClassStudentManager from "../components/admin/ClassStudentManager";
|
|
|
|
| 11 |
|
| 12 |
async function fetchClasses() {
|
| 13 |
const res = await api.get("/api/admin/classes");
|
| 14 |
+
return res.data || [];
|
| 15 |
}
|
| 16 |
|
| 17 |
async function createClassRequest(classData) {
|
|
|
|
| 28 |
await api.delete(`/api/admin/classes/${id}`);
|
| 29 |
}
|
| 30 |
|
| 31 |
+
// --- Page component ---
|
| 32 |
+
|
| 33 |
export default function AdminClasses() {
|
| 34 |
const queryClient = useQueryClient();
|
| 35 |
const [showForm, setShowForm] = useState(false);
|
|
|
|
| 90 |
</p>
|
| 91 |
</div>
|
| 92 |
|
| 93 |
+
{/* Class Form Card */}
|
| 94 |
+
<div className="mb-6 border rounded-xl bg-white shadow-sm">
|
| 95 |
+
<div className="px-4 py-3 border-b flex items-center justify-between">
|
| 96 |
+
<div>
|
| 97 |
+
<h2 className="font-semibold text-stone-900">Class Setup</h2>
|
| 98 |
+
<p className="text-xs text-stone-500">
|
| 99 |
+
Create classes with flexible schedules
|
| 100 |
+
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
</div>
|
| 102 |
+
<button
|
| 103 |
+
type="button"
|
| 104 |
+
onClick={() => {
|
| 105 |
+
setEditingClass(null);
|
| 106 |
+
setShowForm((prev) => !prev);
|
| 107 |
+
}}
|
| 108 |
+
className="inline-flex items-center gap-2 rounded-md bg-red-600 px-3 py-1.5 text-sm font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-red-600 focus:ring-offset-2"
|
| 109 |
+
>
|
| 110 |
+
<Plus className="w-4 h-4" />
|
| 111 |
+
{showForm ? "Cancel" : "New Class"}
|
| 112 |
+
</button>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
{showForm && (
|
| 116 |
+
<div className="p-4">
|
| 117 |
<ClassForm
|
| 118 |
classData={editingClass}
|
| 119 |
onSave={handleSaveClass}
|
|
|
|
| 125 |
createClassMutation.isPending || updateClassMutation.isPending
|
| 126 |
}
|
| 127 |
/>
|
| 128 |
+
</div>
|
| 129 |
)}
|
| 130 |
+
</div>
|
| 131 |
|
| 132 |
{/* Student Manager (when a class is selected) */}
|
| 133 |
{managingClass && (
|
|
|
|
| 139 |
</div>
|
| 140 |
)}
|
| 141 |
|
| 142 |
+
{/* Classes Table Card */}
|
| 143 |
+
<div className="border rounded-xl bg-white shadow-sm">
|
| 144 |
+
<div className="px-4 py-3 border-b">
|
| 145 |
+
<h2 className="font-semibold text-stone-900">All Classes</h2>
|
| 146 |
+
<p className="text-xs text-stone-500">
|
| 147 |
Manage class schedules and enrollments
|
| 148 |
+
</p>
|
| 149 |
+
</div>
|
| 150 |
+
<div className="p-4">
|
| 151 |
<ClassesTable
|
| 152 |
classes={classes}
|
| 153 |
isLoading={isLoading}
|
|
|
|
| 162 |
}}
|
| 163 |
onManageStudents={(cls) => setManagingClass(cls)}
|
| 164 |
/>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
</div>
|
| 168 |
);
|
| 169 |
}
|