|
|
@@ -12,6 +12,7 @@ import { Input } from '@/client/components/ui/input';
|
|
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/client/components/ui/select';
|
|
|
import { Badge } from '@/client/components/ui/badge';
|
|
|
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/client/components/ui/dialog';
|
|
|
+import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from '@/client/components/ui/alert-dialog';
|
|
|
import { ActivityForm } from '../components/ActivityForm';
|
|
|
import type { CreateActivityInput, UpdateActivityInput } from '@/server/modules/activities/activity.schema';
|
|
|
|
|
|
@@ -50,6 +51,10 @@ export const ActivitiesPage: React.FC = () => {
|
|
|
const [typeFilter, setTypeFilter] = useState<string>('all');
|
|
|
const [isFormOpen, setIsFormOpen] = useState(false);
|
|
|
const [editingActivity, setEditingActivity] = useState<ActivityResponse | null>(null);
|
|
|
+ const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
|
|
|
+ const [activityToDelete, setActivityToDelete] = useState<ActivityResponse | null>(null);
|
|
|
+ const [statusConfirmOpen, setStatusConfirmOpen] = useState(false);
|
|
|
+ const [activityToToggle, setActivityToToggle] = useState<ActivityResponse | null>(null);
|
|
|
|
|
|
// 防抖搜索
|
|
|
const debouncedSearch = useCallback(
|
|
|
@@ -181,15 +186,8 @@ export const ActivitiesPage: React.FC = () => {
|
|
|
|
|
|
// 切换活动状态
|
|
|
const handleToggleStatus = (activity: ActivityResponse) => {
|
|
|
- const newStatus = activity.isDisabled === 0 ? 1 : 0;
|
|
|
- const statusText = newStatus === 0 ? '启用' : '禁用';
|
|
|
-
|
|
|
- if (confirm(`确定要${statusText}这个活动吗?`)) {
|
|
|
- toggleStatusMutation.mutate({
|
|
|
- id: activity.id,
|
|
|
- isDisabled: newStatus
|
|
|
- });
|
|
|
- }
|
|
|
+ setActivityToToggle(activity);
|
|
|
+ setStatusConfirmOpen(true);
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -366,9 +364,8 @@ export const ActivitiesPage: React.FC = () => {
|
|
|
variant="destructive"
|
|
|
size="sm"
|
|
|
onClick={() => {
|
|
|
- if (confirm('确定要删除这个活动吗?')) {
|
|
|
- deleteMutation.mutate(activity.id);
|
|
|
- }
|
|
|
+ setActivityToDelete(activity);
|
|
|
+ setDeleteConfirmOpen(true);
|
|
|
}}
|
|
|
data-testid={`delete-activity-${activity.id}`}
|
|
|
>
|
|
|
@@ -429,6 +426,63 @@ export const ActivitiesPage: React.FC = () => {
|
|
|
/>
|
|
|
</DialogContent>
|
|
|
</Dialog>
|
|
|
+
|
|
|
+ {/* 删除确认对话框 */}
|
|
|
+ <AlertDialog open={deleteConfirmOpen} onOpenChange={setDeleteConfirmOpen}>
|
|
|
+ <AlertDialogContent>
|
|
|
+ <AlertDialogHeader>
|
|
|
+ <AlertDialogTitle>确认删除</AlertDialogTitle>
|
|
|
+ <AlertDialogDescription>
|
|
|
+ 确定要删除活动 "{activityToDelete?.name}" 吗?此操作不可撤销。
|
|
|
+ </AlertDialogDescription>
|
|
|
+ </AlertDialogHeader>
|
|
|
+ <AlertDialogFooter>
|
|
|
+ <AlertDialogCancel>取消</AlertDialogCancel>
|
|
|
+ <AlertDialogAction
|
|
|
+ onClick={() => {
|
|
|
+ if (activityToDelete) {
|
|
|
+ deleteMutation.mutate(activityToDelete.id);
|
|
|
+ }
|
|
|
+ setDeleteConfirmOpen(false);
|
|
|
+ setActivityToDelete(null);
|
|
|
+ }}
|
|
|
+ className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
|
|
|
+ >
|
|
|
+ 删除
|
|
|
+ </AlertDialogAction>
|
|
|
+ </AlertDialogFooter>
|
|
|
+ </AlertDialogContent>
|
|
|
+ </AlertDialog>
|
|
|
+
|
|
|
+ {/* 启用/禁用确认对话框 */}
|
|
|
+ <AlertDialog open={statusConfirmOpen} onOpenChange={setStatusConfirmOpen}>
|
|
|
+ <AlertDialogContent>
|
|
|
+ <AlertDialogHeader>
|
|
|
+ <AlertDialogTitle>确认状态切换</AlertDialogTitle>
|
|
|
+ <AlertDialogDescription>
|
|
|
+ 确定要{activityToToggle?.isDisabled === 0 ? '禁用' : '启用'}活动 "{activityToToggle?.name}" 吗?
|
|
|
+ </AlertDialogDescription>
|
|
|
+ </AlertDialogHeader>
|
|
|
+ <AlertDialogFooter>
|
|
|
+ <AlertDialogCancel>取消</AlertDialogCancel>
|
|
|
+ <AlertDialogAction
|
|
|
+ onClick={() => {
|
|
|
+ if (activityToToggle) {
|
|
|
+ const newStatus = activityToToggle.isDisabled === 0 ? 1 : 0;
|
|
|
+ toggleStatusMutation.mutate({
|
|
|
+ id: activityToToggle.id,
|
|
|
+ isDisabled: newStatus
|
|
|
+ });
|
|
|
+ }
|
|
|
+ setStatusConfirmOpen(false);
|
|
|
+ setActivityToToggle(null);
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {activityToToggle?.isDisabled === 0 ? '禁用' : '启用'}
|
|
|
+ </AlertDialogAction>
|
|
|
+ </AlertDialogFooter>
|
|
|
+ </AlertDialogContent>
|
|
|
+ </AlertDialog>
|
|
|
</div>
|
|
|
);
|
|
|
};
|