fix: login page reload + custom logout dialog

1. Login fix:
   - Added window.location.reload() after setting hash URL
   - Forces full page reload to refresh cookies from server
   - Resolves 'Cookie check failed' error after login

2. Logout UX improvement:
   - Created alert-dialog.tsx component (Radix UI AlertDialog)
   - Replaced window.confirm() with custom AlertDialog
   - Dialog shows: title, description, Cancel/Log Out buttons
   - Red 'Log Out' action button for clear intent
This commit is contained in:
Dwindi Ramadhana
2026-01-01 17:08:34 +07:00
parent c83ea78911
commit 508ec682a7
3 changed files with 190 additions and 14 deletions

View File

@@ -2,6 +2,17 @@ import React, { ReactNode, useState } from 'react';
import { Link, useLocation } from 'react-router-dom';
import { LayoutDashboard, ShoppingBag, Download, MapPin, Heart, User, LogOut } from 'lucide-react';
import { useModules } from '@/hooks/useModules';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
interface AccountLayoutProps {
children: ReactNode;
@@ -58,6 +69,38 @@ export function AccountLayout({ children }: AccountLayoutProps) {
return location.pathname.startsWith(path);
};
// Logout Button with AlertDialog
const LogoutButton = () => (
<AlertDialog>
<AlertDialogTrigger asChild>
<button
disabled={isLoggingOut}
className="w-full font-[inherit] flex items-center gap-3 px-4 py-2.5 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors disabled:opacity-50"
>
<LogOut className="w-5 h-5" />
<span className="font-medium">{isLoggingOut ? 'Logging out...' : 'Logout'}</span>
</button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Log out?</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to log out of your account? You'll need to sign in again to access your orders and account details.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleLogout}
className="bg-red-600 hover:bg-red-700 text-white"
>
Log Out
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
// Sidebar Navigation
const SidebarNav = () => (
<aside className="bg-white rounded-lg border p-4">
@@ -91,18 +134,7 @@ export function AccountLayout({ children }: AccountLayoutProps) {
);
})}
<button
onClick={() => {
if (window.confirm('Are you sure you want to log out?')) {
handleLogout();
}
}}
disabled={isLoggingOut}
className="w-full font-[inherit] flex items-center gap-3 px-4 py-2.5 rounded-lg text-gray-700 hover:bg-gray-100 transition-colors disabled:opacity-50"
>
<LogOut className="w-5 h-5" />
<span className="font-medium">{isLoggingOut ? 'Logging out...' : 'Logout'}</span>
</button>
<LogoutButton />
</nav>
</aside>
);
@@ -151,3 +183,4 @@ export function AccountLayout({ children }: AccountLayoutProps) {
</div>
);
}