Cài đặt tính năng quản lí người dùng cho admin

This commit is contained in:
2026-06-13 18:24:14 +07:00
parent ea5799ffb5
commit 7b42058d77
21 changed files with 458 additions and 30 deletions
+24 -4
View File
@@ -9,6 +9,7 @@ const App = () => {
const [view, setView] = useState<View>('landing');
const [isInitialSetup, setIsInitialSetup] = useState(false);
const [user, setUser] = useState<any>(null);
const [isUserLoaded, setIsUserLoaded] = useState(false); // Trạng thái để biết user đã được load từ localStorage chưa
useEffect(() => {
// Tự động xác định địa chỉ IP của Backend dựa trên hostname hiện tại
@@ -17,19 +18,34 @@ const App = () => {
// Khôi phục phiên đăng nhập từ localStorage
const savedUser = localStorage.getItem('user');
if (savedUser) {
setUser(JSON.parse(savedUser));
const parsedUser = JSON.parse(savedUser);
setUser(parsedUser);
}
setIsUserLoaded(true); // Đánh dấu user đã được load
// Kiểm tra xem hệ thống đã được cài đặt chưa
fetch(`${API_BASE}/api/v1/auth/status`)
.then(res => res.ok ? res.json() : Promise.reject())
.then(data => setIsInitialSetup(!!data.isInitialSetup))
.catch(() => setIsInitialSetup(false));
}, [view]);
}, []); // Chạy một lần khi component mount
// Effect để xử lý chuyển hướng nếu user đã đăng nhập và đang ở trang landing
useEffect(() => {
if (isUserLoaded && user && view === 'landing') {
setView('explore');
}
}, [isUserLoaded, user, view]);
const handleLoginSuccess = (userData: any) => {
setUser(userData);
setView('explore'); // Chuyển sang bản đồ khám phá sau khi đăng nhập
};
const handleLogout = () => {
localStorage.removeItem('user');
localStorage.removeItem('token');
setUser(null);
setView('landing');
};
return (
@@ -52,7 +68,11 @@ const App = () => {
)}
{view === 'explore' && (
<ExploreMap onBack={() => setView('landing')} />
<ExploreMap
onBack={() => setView('landing')}
onLogout={user ? handleLogout : undefined}
user={user}
/>
)}
{view === 'detail' && (