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:
kimjaehyeon0101
2025-09-29 21:18:33 +00:00
parent 00b92a8a45
commit d99a0580e6
7 changed files with 113 additions and 46 deletions

View File

@ -8,12 +8,14 @@ import LoginModal from "@/components/LoginModal";
import SearchModal from "@/components/SearchModal";
import { useToast } from "@/hooks/use-toast";
import { queryClient } from "@/lib/queryClient";
import { useLocation } from "wouter";
export default function Home() {
const { user, isAuthenticated } = useAuth();
const [isLoginModalOpen, setIsLoginModalOpen] = useState(false);
const [isSearchModalOpen, setIsSearchModalOpen] = useState(false);
const { toast } = useToast();
const [, setLocation] = useLocation();
const handleLogout = async () => {
try {
@ -24,8 +26,8 @@ export default function Home() {
if (response.ok) {
toast({
title: "로그아웃 완료",
description: "성공적으로 로그아웃되었습니다.",
title: "Logged Out",
description: "You have been successfully logged out.",
});
// Invalidate auth queries to refresh user state
@ -33,15 +35,15 @@ export default function Home() {
}
} catch (error) {
toast({
title: "로그아웃 오류",
description: "로그아웃 중 오류가 발생했습니다.",
title: "Logout Error",
description: "An error occurred while logging out.",
variant: "destructive",
});
}
};
const handleAdminPage = () => {
window.location.href = "/admin";
setLocation("/admin");
};
return (
@ -56,7 +58,7 @@ export default function Home() {
alt="SAPIENS"
className="h-6 w-auto cursor-pointer"
data-testid="logo-sapiens"
onClick={() => window.location.href = "/"}
onClick={() => setLocation("/")}
/>
</div>
@ -79,6 +81,15 @@ export default function Home() {
{isAuthenticated && user ? (
<>
<Button
variant="ghost"
size="sm"
onClick={() => setLocation("/auctions")}
data-testid="button-auctions"
>
Auctions
</Button>
<Button
variant="ghost"
size="sm"
@ -105,14 +116,24 @@ export default function Home() {
</Button>
</>
) : (
<Button
variant="ghost"
size="sm"
onClick={() => setIsLoginModalOpen(true)}
data-testid="button-login"
>
Login
</Button>
<>
<Button
variant="ghost"
size="sm"
onClick={() => setLocation("/auctions")}
data-testid="button-auctions"
>
Auctions
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setIsLoginModalOpen(true)}
data-testid="button-login"
>
Login
</Button>
</>
)}
<Button