Update site navigation and logout functionality
Refactors client-side navigation to use `wouter`'s `setLocation` instead of `window.location.href` for smoother transitions and improves the logout process by making it an asynchronous POST request with proper error handling and state invalidation. Also adds an "Auctions" button to the main navigation bar on multiple pages. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 069d4324-6c40-4355-955e-c714a50de1ea Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/3df548ff-50ae-432f-9be4-25d34eccc983/069d4324-6c40-4355-955e-c714a50de1ea/bLfICpO
This commit is contained in:
@ -11,10 +11,13 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
|
||||
import type { MediaOutlet } from "@shared/schema";
|
||||
import MediaOutletManagement from "@/components/MediaOutletManagement";
|
||||
import Footer from "@/components/Footer";
|
||||
import { useLocation } from "wouter";
|
||||
import { queryClient } from "@/lib/queryClient";
|
||||
|
||||
export default function AdminDashboard() {
|
||||
const { user, isLoading } = useAuth();
|
||||
const { toast } = useToast();
|
||||
const [, setLocation] = useLocation();
|
||||
const [searchTerm, setSearchTerm] = useState("");
|
||||
const [selectedOutlet, setSelectedOutlet] = useState<MediaOutlet | null>(null);
|
||||
const [managingOutlet, setManagingOutlet] = useState<MediaOutlet | null>(null);
|
||||
@ -29,7 +32,7 @@ export default function AdminDashboard() {
|
||||
variant: "destructive",
|
||||
});
|
||||
setTimeout(() => {
|
||||
window.location.href = "/";
|
||||
setLocation("/");
|
||||
}, 500);
|
||||
}
|
||||
}, [isLoading, user, toast]);
|
||||
@ -78,8 +81,29 @@ export default function AdminDashboard() {
|
||||
});
|
||||
};
|
||||
|
||||
const handleLogout = () => {
|
||||
window.location.href = "/api/logout";
|
||||
const handleLogout = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/logout", {
|
||||
method: "POST",
|
||||
credentials: "include",
|
||||
});
|
||||
|
||||
if (response.ok) {
|
||||
toast({
|
||||
title: "Logged Out",
|
||||
description: "You have been successfully logged out.",
|
||||
});
|
||||
|
||||
queryClient.invalidateQueries({ queryKey: ["/api/auth/user"] });
|
||||
setLocation("/");
|
||||
}
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: "Logout Error",
|
||||
description: "An error occurred while logging out.",
|
||||
variant: "destructive",
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (isLoading || !user || (user.role !== 'admin' && user.role !== 'superadmin')) {
|
||||
@ -107,14 +131,13 @@ export default function AdminDashboard() {
|
||||
<div className="max-w-7xl mx-auto px-6 py-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div className="flex items-center space-x-4">
|
||||
<a href="/" className="cursor-pointer" data-testid="logo-link">
|
||||
<img
|
||||
src="/attached_assets/logo_black_1759162717640.png"
|
||||
alt="SAPIENS"
|
||||
className="h-6 w-auto hover:opacity-80 transition-opacity"
|
||||
data-testid="logo-sapiens"
|
||||
/>
|
||||
</a>
|
||||
<img
|
||||
src="/attached_assets/logo_black_1759162717640.png"
|
||||
alt="SAPIENS"
|
||||
className="h-6 w-auto hover:opacity-80 transition-opacity cursor-pointer"
|
||||
data-testid="logo-sapiens"
|
||||
onClick={() => setLocation("/")}
|
||||
/>
|
||||
<div className="border-l border-gray-300 h-6"></div>
|
||||
<div>
|
||||
<h1 className="text-lg font-bold text-gray-900">Admin Dashboard</h1>
|
||||
@ -135,6 +158,15 @@ export default function AdminDashboard() {
|
||||
/>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setLocation("/auctions")}
|
||||
data-testid="button-auctions"
|
||||
>
|
||||
Auctions
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
|
||||
Reference in New Issue
Block a user