File size: 7,099 Bytes
c616a87 86219a8 c616a87 86219a8 c616a87 1b3e319 c616a87 86219a8 48eb982 86219a8 c616a87 1b3e319 c616a87 86219a8 c616a87 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 1b3e319 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 1b3e319 86219a8 1b3e319 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 48eb982 86219a8 c616a87 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | // frontend/src/components/admin/ClassesTable.jsx
import React from "react";
import { Edit2, Trash2, Users } from "lucide-react";
export default function ClassesTable({
classes,
isLoading,
onEdit,
onDelete,
onManageStudents,
}) {
if (isLoading) {
return (
<div className="space-y-3">
{[1, 2, 3].map((i) => (
<div
key={i}
className="h-16 w-full animate-pulse rounded-md bg-stone-100"
/>
))}
</div>
);
}
if (!classes || classes.length === 0) {
return (
<div className="text-center py-12 text-stone-500">
<p>No classes created yet.</p>
</div>
);
}
return (
<>
{/* Desktop table */}
<div className="hidden md:block overflow-x-auto">
<table className="min-w-full text-sm border border-stone-200 rounded-lg overflow-hidden">
<thead className="bg-stone-50">
<tr>
<th className="px-4 py-2 text-left font-semibold text-stone-800">
Class Name
</th>
<th className="px-4 py-2 text-left font-semibold text-stone-800">
Schedule
</th>
<th className="px-4 py-2 text-left font-semibold text-stone-800">
Status
</th>
<th className="px-4 py-2 text-right font-semibold text-stone-800">
Actions
</th>
</tr>
</thead>
<tbody>
{classes.map((cls) => (
<tr key={cls.id} className="border-t border-stone-200">
<td className="px-4 py-3 align-top">
<div>
<div className="font-medium text-stone-900">
{cls.name}
</div>
{cls.description && (
<div className="text-xs text-stone-500 max-w-xs truncate">
{cls.description}
</div>
)}
</div>
</td>
<td className="px-4 py-3 align-top">
<div className="space-y-1 text-sm">
{(cls.schedule || []).map((slot, idx) => (
<div key={idx}>
<span className="font-medium">{slot.day}:</span>{" "}
{slot.start_time && slot.end_time
? `${slot.start_time} - ${slot.end_time}`
: slot.time || ""}
</div>
))}
</div>
</td>
<td className="px-4 py-3 align-top">
<span
className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
cls.is_active
? "bg-green-100 text-green-800"
: "bg-stone-200 text-stone-700"
}`}
>
{cls.is_active ? "Active" : "Inactive"}
</span>
</td>
<td className="px-4 py-3 align-top text-right">
<div className="flex justify-end gap-2">
<button
type="button"
onClick={() => onManageStudents(cls)}
className="inline-flex items-center gap-1 rounded-md border border-stone-300 px-2.5 py-1 text-xs font-medium text-stone-800 hover:bg-stone-50"
>
<Users className="w-4 h-4" />
Students
</button>
<button
type="button"
onClick={() => onEdit(cls)}
className="inline-flex items-center justify-center rounded-md border border-stone-300 px-2.5 py-1 text-xs text-stone-800 hover:bg-stone-50"
>
<Edit2 className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => onDelete(cls.id)}
className="inline-flex items-center justify-center rounded-md border border-red-200 px-2.5 py-1 text-xs text-red-700 hover:bg-red-50"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</td>
</tr>
))}
</tbody>
</table>
</div>
{/* Mobile cards */}
<div className="md:hidden space-y-3">
{classes.map((cls) => (
<div
key={cls.id}
className="rounded-lg border border-stone-200 p-4 bg-white shadow-sm"
>
<div className="flex justify-between items-start mb-2">
<div className="font-semibold text-stone-900">{cls.name}</div>
<span
className={`inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
cls.is_active
? "bg-green-100 text-green-800"
: "bg-stone-200 text-stone-700"
}`}
>
{cls.is_active ? "Active" : "Inactive"}
</span>
</div>
{cls.description && (
<p className="text-sm text-stone-600 mb-3">
{cls.description}
</p>
)}
<div className="space-y-1 mb-3 text-sm">
{(cls.schedule || []).map((slot, idx) => (
<div key={idx}>
<span className="font-medium">{slot.day}:</span>{" "}
{slot.start_time && slot.end_time
? `${slot.start_time} - ${slot.end_time}`
: slot.time || ""}
</div>
))}
</div>
<div className="flex gap-2">
<button
type="button"
onClick={() => onManageStudents(cls)}
className="flex-1 inline-flex items-center justify-center gap-1 rounded-md border border-stone-300 px-2.5 py-1.5 text-xs font-medium text-stone-800 hover:bg-stone-50"
>
<Users className="w-4 h-4" />
Students
</button>
<button
type="button"
onClick={() => onEdit(cls)}
className="inline-flex items-center justify-center rounded-md border border-stone-300 px-2.5 py-1.5 text-xs text-stone-800 hover:bg-stone-50"
>
<Edit2 className="w-4 h-4" />
</button>
<button
type="button"
onClick={() => onDelete(cls.id)}
className="inline-flex items-center justify-center rounded-md border border-red-200 px-2.5 py-1.5 text-xs text-red-700 hover:bg-red-50"
>
<Trash2 className="w-4 h-4" />
</button>
</div>
</div>
))}
</div>
</>
);
}
|