fix: guest and admin logic
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { X, User, Trash2, Shield, ShieldAlert, Lock, Unlock, Loader2, Image as ImageIcon, Map, FileText, CheckCircle, Star, Settings } from 'lucide-react';
|
||||
import { useConfirm } from '../hooks/useConfirm';
|
||||
|
||||
interface UserManagementModalProps {
|
||||
isOpen: boolean;
|
||||
@@ -7,6 +8,7 @@ interface UserManagementModalProps {
|
||||
}
|
||||
|
||||
export const UserManagementModal: React.FC<UserManagementModalProps> = ({ isOpen, onClose }) => {
|
||||
const confirm = useConfirm();
|
||||
const [activeTab, setActiveTab] = useState<'users' | 'tours' | 'photos' | 'notes' | 'recommendations' | 'trash' | 'filters' | 'reports'>('users');
|
||||
const [users, setUsers] = useState<any[]>([]);
|
||||
const [photos, setPhotos] = useState<any[]>([]);
|
||||
@@ -68,7 +70,10 @@ export const UserManagementModal: React.FC<UserManagementModalProps> = ({ isOpen
|
||||
};
|
||||
|
||||
const handleDeleteReport = async (id: string) => {
|
||||
if (!confirm('Bạn có chắc muốn xóa báo cáo này?')) return;
|
||||
if (!await confirm({
|
||||
title: 'Xóa báo cáo',
|
||||
message: 'Bạn có chắc muốn xóa báo cáo này?'
|
||||
})) return;
|
||||
try {
|
||||
const response = await fetch(`/api/v1/admin/reports/${id}`, {
|
||||
method: 'DELETE',
|
||||
@@ -492,8 +497,13 @@ export const UserManagementModal: React.FC<UserManagementModalProps> = ({ isOpen
|
||||
const handleDeletePermanentTrash = async () => {
|
||||
if (selectedTrashIds.length === 0) return;
|
||||
if (!confirm(`CẢNH BÁO: Bạn có chắc muốn xóa VĨNH VIỄN ${selectedTrashIds.length} mục đã chọn? Thao tác này không thể hoàn tác.`)) return;
|
||||
|
||||
setTrashLoading(true);
|
||||
const idsToDelete = [...selectedTrashIds];
|
||||
setSelectedTrashIds([]);
|
||||
|
||||
try {
|
||||
console.log('[Trash] Starting permanent delete for', idsToDelete.length, 'items');
|
||||
const res = await fetch('/api/v1/admin/trash/delete-permanent', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -502,16 +512,42 @@ export const UserManagementModal: React.FC<UserManagementModalProps> = ({ isOpen
|
||||
},
|
||||
body: JSON.stringify({
|
||||
type: trashSubTab,
|
||||
ids: selectedTrashIds
|
||||
ids: idsToDelete
|
||||
})
|
||||
});
|
||||
|
||||
console.log('[Trash] Delete response status:', res.status);
|
||||
|
||||
if (res.ok) {
|
||||
setSelectedTrashIds([]);
|
||||
console.log('[Trash] Delete successful, clearing state immediately');
|
||||
setError('');
|
||||
alert('Đã xóa vĩnh viễn thành công!');
|
||||
|
||||
// Small delay to let alert close, then refresh data
|
||||
setTimeout(() => {
|
||||
console.log('[Trash] Refreshing trash data after delete');
|
||||
fetchTrashData();
|
||||
setTrashLoading(false);
|
||||
}, 500);
|
||||
return; // Important: exit early so finally doesn't run again
|
||||
} else {
|
||||
const errorData = await res.json().catch(() => ({}));
|
||||
const errorMsg = errorData.message || `HTTP ${res.status}`;
|
||||
console.error('[Trash] Delete failed:', errorMsg);
|
||||
setError(errorMsg);
|
||||
alert(`Xóa thất bại: ${errorMsg}`);
|
||||
|
||||
// Refresh on error
|
||||
fetchTrashData();
|
||||
setTrashLoading(false);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
} catch (e: any) {
|
||||
console.error('[Trash] Delete error:', e);
|
||||
setError(e.message || 'Lỗi khi xóa các mục');
|
||||
alert(`Lỗi: ${e.message}`);
|
||||
|
||||
// Refresh on error
|
||||
fetchTrashData();
|
||||
setTrashLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user