|
|
@@ -3,27 +3,71 @@ import { useClassroomContext } from './ClassroomProvider';
|
|
|
import { UserGroupIcon, XMarkIcon } from '@heroicons/react/24/outline';
|
|
|
import { Button } from '@/client/components/ui/button';
|
|
|
import { Card, CardContent, CardHeader, CardTitle } from '@/client/components/ui/card';
|
|
|
+import {
|
|
|
+ AlertDialog,
|
|
|
+ AlertDialogAction,
|
|
|
+ AlertDialogCancel,
|
|
|
+ AlertDialogContent,
|
|
|
+ AlertDialogDescription,
|
|
|
+ AlertDialogFooter,
|
|
|
+ AlertDialogHeader,
|
|
|
+ AlertDialogTitle,
|
|
|
+} from '@/client/components/ui/alert-dialog';
|
|
|
|
|
|
export const TeacherStudentManagementButton: React.FC = () => {
|
|
|
const { students, toggleMuteMember, kickStudent } = useClassroomContext();
|
|
|
const [showPanel, setShowPanel] = useState(false);
|
|
|
+ const [confirmDialog, setConfirmDialog] = useState<{
|
|
|
+ open: boolean;
|
|
|
+ action: 'mute' | 'unmute' | 'kick' | null;
|
|
|
+ studentId: string;
|
|
|
+ studentName: string;
|
|
|
+ }>({
|
|
|
+ open: false,
|
|
|
+ action: null,
|
|
|
+ studentId: '',
|
|
|
+ studentName: '',
|
|
|
+ });
|
|
|
|
|
|
- const handleMuteStudent = (studentId: string, studentName: string) => {
|
|
|
- if (window.confirm(`确定要静音 ${studentName} 吗?`)) {
|
|
|
- toggleMuteMember(studentId, true);
|
|
|
- }
|
|
|
+ const openConfirmDialog = (action: 'mute' | 'unmute' | 'kick', studentId: string, studentName: string) => {
|
|
|
+ setConfirmDialog({
|
|
|
+ open: true,
|
|
|
+ action,
|
|
|
+ studentId,
|
|
|
+ studentName,
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
- const handleUnmuteStudent = (studentId: string, studentName: string) => {
|
|
|
- if (window.confirm(`确定要取消静音 ${studentName} 吗?`)) {
|
|
|
- toggleMuteMember(studentId, false);
|
|
|
+ const handleConfirm = () => {
|
|
|
+ const { action, studentId } = confirmDialog;
|
|
|
+
|
|
|
+ switch (action) {
|
|
|
+ case 'mute':
|
|
|
+ toggleMuteMember(studentId, true);
|
|
|
+ break;
|
|
|
+ case 'unmute':
|
|
|
+ toggleMuteMember(studentId, false);
|
|
|
+ break;
|
|
|
+ case 'kick':
|
|
|
+ kickStudent(studentId);
|
|
|
+ break;
|
|
|
}
|
|
|
+
|
|
|
+ setConfirmDialog({
|
|
|
+ open: false,
|
|
|
+ action: null,
|
|
|
+ studentId: '',
|
|
|
+ studentName: '',
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
- const handleKickStudent = (studentId: string, studentName: string) => {
|
|
|
- if (window.confirm(`确定要移出 ${studentName} 吗?`)) {
|
|
|
- kickStudent(studentId);
|
|
|
- }
|
|
|
+ const handleCancel = () => {
|
|
|
+ setConfirmDialog({
|
|
|
+ open: false,
|
|
|
+ action: null,
|
|
|
+ studentId: '',
|
|
|
+ studentName: '',
|
|
|
+ });
|
|
|
};
|
|
|
|
|
|
return (
|
|
|
@@ -72,29 +116,29 @@ export const TeacherStudentManagementButton: React.FC = () => {
|
|
|
<span>{student.name}</span>
|
|
|
<div className="flex gap-1">
|
|
|
<Button
|
|
|
- onClick={() => handleMuteStudent(student.id, student.name)}
|
|
|
- variant="outline"
|
|
|
- size="sm"
|
|
|
- className="text-xs bg-yellow-100 text-yellow-700 hover:bg-yellow-200 border-yellow-300"
|
|
|
- >
|
|
|
- 静音
|
|
|
- </Button>
|
|
|
- <Button
|
|
|
- onClick={() => handleUnmuteStudent(student.id, student.name)}
|
|
|
- variant="outline"
|
|
|
- size="sm"
|
|
|
- className="text-xs bg-green-100 text-green-700 hover:bg-green-200 border-green-300"
|
|
|
- >
|
|
|
- 取消
|
|
|
- </Button>
|
|
|
- <Button
|
|
|
- onClick={() => handleKickStudent(student.id, student.name)}
|
|
|
- variant="outline"
|
|
|
- size="sm"
|
|
|
- className="text-xs bg-red-100 text-red-700 hover:bg-red-200 border-red-300"
|
|
|
- >
|
|
|
- 移出
|
|
|
- </Button>
|
|
|
+ onClick={() => openConfirmDialog('mute', student.id, student.name)}
|
|
|
+ variant="outline"
|
|
|
+ size="sm"
|
|
|
+ className="text-xs bg-yellow-100 text-yellow-700 hover:bg-yellow-200 border-yellow-300"
|
|
|
+ >
|
|
|
+ 静音
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ onClick={() => openConfirmDialog('unmute', student.id, student.name)}
|
|
|
+ variant="outline"
|
|
|
+ size="sm"
|
|
|
+ className="text-xs bg-green-100 text-green-700 hover:bg-green-200 border-green-300"
|
|
|
+ >
|
|
|
+ 取消
|
|
|
+ </Button>
|
|
|
+ <Button
|
|
|
+ onClick={() => openConfirmDialog('kick', student.id, student.name)}
|
|
|
+ variant="outline"
|
|
|
+ size="sm"
|
|
|
+ className="text-xs bg-red-100 text-red-700 hover:bg-red-200 border-red-300"
|
|
|
+ >
|
|
|
+ 移出
|
|
|
+ </Button>
|
|
|
</div>
|
|
|
</div>
|
|
|
))}
|
|
|
@@ -104,6 +148,25 @@ export const TeacherStudentManagementButton: React.FC = () => {
|
|
|
</Card>
|
|
|
</div>
|
|
|
)}
|
|
|
+
|
|
|
+ <AlertDialog open={confirmDialog.open} onOpenChange={(open) => !open && handleCancel()}>
|
|
|
+ <AlertDialogContent>
|
|
|
+ <AlertDialogHeader>
|
|
|
+ <AlertDialogTitle>操作确认</AlertDialogTitle>
|
|
|
+ <AlertDialogDescription>
|
|
|
+ {confirmDialog.action === 'mute' && `确定要静音 ${confirmDialog.studentName} 吗?`}
|
|
|
+ {confirmDialog.action === 'unmute' && `确定要取消静音 ${confirmDialog.studentName} 吗?`}
|
|
|
+ {confirmDialog.action === 'kick' && `确定要移出 ${confirmDialog.studentName} 吗?`}
|
|
|
+ </AlertDialogDescription>
|
|
|
+ </AlertDialogHeader>
|
|
|
+ <AlertDialogFooter>
|
|
|
+ <AlertDialogCancel>取消</AlertDialogCancel>
|
|
|
+ <AlertDialogAction onClick={handleConfirm}>
|
|
|
+ 确定
|
|
|
+ </AlertDialogAction>
|
|
|
+ </AlertDialogFooter>
|
|
|
+ </AlertDialogContent>
|
|
|
+ </AlertDialog>
|
|
|
</div>
|
|
|
);
|
|
|
};
|