add tai lieu system
All checks were successful
Deploy on Master Change / deploy (push) Successful in 43s

This commit is contained in:
2026-07-01 14:47:46 +07:00
parent 6919513165
commit dd766206f7
15 changed files with 952 additions and 140 deletions

View File

@@ -1,6 +1,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { apiExam, type ExamRoomItem } from '../api';
import { openExam } from './NavHistoryBar';
import { useAuth } from '../auth/AuthContext';
function fmtTime(iso: string) {
try {
@@ -32,6 +33,9 @@ function localInputToISO(v: string) {
}
export const ExamsTab: React.FC = () => {
const { staff } = useAuth();
const isSuperAdmin = staff?.email === 'phuocntb@rikkeiacademy.com';
const [rooms, setRooms] = useState<ExamRoomItem[]>([]);
const [loading, setLoading] = useState(true);
const [showCreate, setShowCreate] = useState(false);
@@ -94,6 +98,18 @@ export const ExamsTab: React.FC = () => {
}
};
const handleDeleteRoom = async (roomId: number, roomName: string) => {
if (window.confirm(`Bạn có chắc chắn muốn xóa hoàn toàn phòng thi "${roomName}" không? Hành động này sẽ xóa sạch dữ liệu phòng thi, các bài nộp, và không thể khôi phục.`)) {
try {
await apiExam.remove(roomId);
alert('Đã xóa phòng thi thành công!');
await load();
} catch (err: any) {
alert(err.message || 'Xóa phòng thi thất bại');
}
}
};
return (
<div className="tab-page exams-page">
<header className="page-header page-header--row">
@@ -190,9 +206,40 @@ export const ExamsTab: React.FC = () => {
<span>{r.studentCount} sinh viên · {r.paperCount} đ</span>
</div>
</div>
<button type="button" className="btn btn-primary btn-sm exam-list-card-open" onClick={() => openExam(r.id, r.name)}>
Mở phòng thi
</button>
<div style={{ display: 'flex', gap: '8px', marginTop: '1.25rem' }}>
<button type="button" className="btn btn-primary btn-sm exam-list-card-open" onClick={() => openExam(r.id, r.name)} style={{ flex: 1, margin: 0 }}>
Mở phòng thi
</button>
{isSuperAdmin && (
<button
type="button"
className="btn btn-secondary btn-sm"
onClick={(e) => {
e.stopPropagation();
handleDeleteRoom(r.id, r.name);
}}
style={{
borderColor: 'var(--danger)',
color: 'var(--danger)',
backgroundColor: 'transparent',
padding: '0.5rem 0.75rem',
fontWeight: 600,
transition: 'var(--transition)',
margin: 0
}}
onMouseEnter={(e) => {
e.currentTarget.style.backgroundColor = 'var(--danger)';
e.currentTarget.style.color = '#fff';
}}
onMouseLeave={(e) => {
e.currentTarget.style.backgroundColor = 'transparent';
e.currentTarget.style.color = 'var(--danger)';
}}
>
Xóa
</button>
)}
</div>
</article>
);
})}