fix: replace all Link components with native anchor tags and router.push with window.location.href to fix navigation bugs in admin dashboard

This commit is contained in:
Erik Silva
2026-01-21 15:20:04 -03:00
parent 88c1a0b681
commit 2381e6e70f
7 changed files with 36 additions and 54 deletions

View File

@@ -12,7 +12,6 @@ import {
ArrowUpRight, ArrowUpRight,
ArrowRight, ArrowRight,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
import { Sidebar } from "@/components/Sidebar"; import { Sidebar } from "@/components/Sidebar";
import { DynamicFavicon } from "@/components/DynamicFavicon"; import { DynamicFavicon } from "@/components/DynamicFavicon";
@@ -79,16 +78,14 @@ export default function DashboardClient({
</div> </div>
<div className="flex items-center"> <div className="flex items-center">
<Button <a
asChild href="/dashboard/documentos?upload=true"
style={{ backgroundColor: primaryColor }} style={{ backgroundColor: primaryColor }}
className="w-full sm:w-auto h-11 sm:h-10 px-4 sm:px-6 rounded-xl sm:rounded-lg font-bold text-xs shadow-none hover:opacity-90 active:scale-95 transition-all text-white" className="w-full sm:w-auto h-11 sm:h-10 px-4 sm:px-6 rounded-xl sm:rounded-lg font-bold text-xs shadow-none hover:opacity-90 active:scale-95 transition-all text-white flex items-center justify-center"
> >
<Link href="/dashboard/documentos?upload=true"> <Plus size={18} className="mr-2 stroke-[3]" />
<Plus size={18} className="mr-2 stroke-[3]" /> Novo Documento
Novo Documento </a>
</Link>
</Button>
</div> </div>
</div> </div>
@@ -165,9 +162,9 @@ export default function DashboardClient({
<motion.div initial={{ opacity: 0, y: 15 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: 0.3 }} className="lg:col-span-8"> <motion.div initial={{ opacity: 0, y: 15 }} animate={{ opacity: 1, y: 0 }} transition={{ delay: 0.3 }} className="lg:col-span-8">
<div className="flex items-center justify-between mb-3 lg:mb-4 px-1"> <div className="flex items-center justify-between mb-3 lg:mb-4 px-1">
<h3 className="text-base lg:text-lg font-black text-slate-900 tracking-tight">Atividade Recente</h3> <h3 className="text-base lg:text-lg font-black text-slate-900 tracking-tight">Atividade Recente</h3>
<Link href="/dashboard/documentos" className="group flex items-center gap-2 text-[9px] font-bold uppercase tracking-widest text-slate-400 hover:text-slate-900 transition-colors"> <a href="/dashboard/documentos" className="group flex items-center gap-2 text-[9px] font-bold uppercase tracking-widest text-slate-400 hover:text-slate-900 transition-colors">
Ver Todos <ArrowRight size={12} className="group-hover:translate-x-0.5 transition-transform" /> Ver Todos <ArrowRight size={12} className="group-hover:translate-x-0.5 transition-transform" />
</Link> </a>
</div> </div>
<div className="bg-white rounded-2xl lg:rounded-[24px] border-2 border-slate-100 overflow-hidden"> <div className="bg-white rounded-2xl lg:rounded-[24px] border-2 border-slate-100 overflow-hidden">
@@ -177,14 +174,12 @@ export default function DashboardClient({
<FileText size={20} className="text-slate-300" /> <FileText size={20} className="text-slate-300" />
</div> </div>
<p className="text-slate-500 font-medium mb-4 text-sm">Nenhum documento encontrado.</p> <p className="text-slate-500 font-medium mb-4 text-sm">Nenhum documento encontrado.</p>
<Button asChild variant="outline" className="rounded-lg border-2 font-bold px-6 h-9 text-[10px] uppercase tracking-widest"> <a href="/dashboard/documentos/novo" className="inline-flex items-center justify-center rounded-lg border-2 border-slate-200 font-bold px-6 h-9 text-[10px] uppercase tracking-widest hover:bg-slate-50 transition-colors">Começar Agora</a>
<Link href="/dashboard/documentos/novo">Começar Agora</Link>
</Button>
</div> </div>
) : ( ) : (
<div className="divide-y-2 divide-slate-50"> <div className="divide-y-2 divide-slate-50">
{stats.recentDocs.map((doc) => ( {stats.recentDocs.map((doc) => (
<Link <a
key={doc.id} key={doc.id}
href={`/dashboard/documentos/${doc.id}`} href={`/dashboard/documentos/${doc.id}`}
className="flex items-center gap-3 lg:gap-4 py-3 lg:py-3.5 px-4 lg:px-6 hover:bg-slate-50/50 transition-all group" className="flex items-center gap-3 lg:gap-4 py-3 lg:py-3.5 px-4 lg:px-6 hover:bg-slate-50/50 transition-all group"
@@ -207,7 +202,7 @@ export default function DashboardClient({
</div> </div>
</div> </div>
<ChevronRight size={18} className="sm:hidden text-slate-300 shrink-0" /> <ChevronRight size={18} className="sm:hidden text-slate-300 shrink-0" />
</Link> </a>
))} ))}
</div> </div>
)} )}

View File

@@ -31,7 +31,6 @@ import {
Pencil, Pencil,
Calendar, Calendar,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation"; import { useRouter, useSearchParams } from "next/navigation";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -212,11 +211,10 @@ export default function DocumentsClient({
// Navigation Handler // Navigation Handler
const handleRowClick = (item: any) => { const handleRowClick = (item: any) => {
if (item.isFolder) { const url = item.isFolder
router.push(`/dashboard/documentos?folder=${item.id}`); ? `/dashboard/documentos?folder=${item.id}`
} else { : `/dashboard/documentos/${item.id}`;
router.push(`/dashboard/documentos/${item.id}`); window.location.href = url;
}
}; };
// Unified Filters (Folders + Documents) // Unified Filters (Folders + Documents)
@@ -580,12 +578,12 @@ export default function DocumentsClient({
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
{/* Breadcrumbs */} {/* Breadcrumbs */}
<nav className="flex items-center gap-1.5 mb-3 flex-wrap overflow-x-auto"> <nav className="flex items-center gap-1.5 mb-3 flex-wrap overflow-x-auto">
<Link <a
href="/dashboard/documentos" href="/dashboard/documentos"
className="p-1.5 rounded-lg hover:bg-slate-100 border border-transparent hover:border-slate-200 transition-all text-slate-400 hover:text-slate-900 shrink-0" className="p-1.5 rounded-lg hover:bg-slate-100 border border-transparent hover:border-slate-200 transition-all text-slate-400 hover:text-slate-900 shrink-0"
> >
<Home size={14} /> <Home size={14} />
</Link> </a>
{breadcrumb.length === 0 ? ( {breadcrumb.length === 0 ? (
<> <>
<ChevronRight size={10} className="text-slate-300 shrink-0" /> <ChevronRight size={10} className="text-slate-300 shrink-0" />
@@ -602,12 +600,12 @@ export default function DocumentsClient({
{folder.name} {folder.name}
</span> </span>
) : ( ) : (
<Link <a
href={`/dashboard/documentos?folder=${folder.id}`} href={`/dashboard/documentos?folder=${folder.id}`}
className="px-2 py-0.5 bg-slate-100 hover:bg-slate-200 border border-slate-200 rounded-md text-[9px] font-bold uppercase tracking-widest text-slate-600 hover:text-slate-900 transition-all truncate max-w-[80px] sm:max-w-none" className="px-2 py-0.5 bg-slate-100 hover:bg-slate-200 border border-slate-200 rounded-md text-[9px] font-bold uppercase tracking-widest text-slate-600 hover:text-slate-900 transition-all truncate max-w-[80px] sm:max-w-none"
> >
{folder.name} {folder.name}
</Link> </a>
)} )}
</React.Fragment> </React.Fragment>
)) ))
@@ -857,7 +855,7 @@ export default function DocumentsClient({
</td> </td>
<td className="px-4 py-2.5"> <td className="px-4 py-2.5">
{item.isFolder ? ( {item.isFolder ? (
<Link <a
href={`/dashboard/documentos?folder=${item.id}`} href={`/dashboard/documentos?folder=${item.id}`}
className="flex items-center gap-3" className="flex items-center gap-3"
onClick={(e) => e.stopPropagation()} onClick={(e) => e.stopPropagation()}
@@ -875,7 +873,7 @@ export default function DocumentsClient({
<p className="text-sm font-bold text-slate-700 truncate leading-none mb-0.5 group-hover:text-red-600 transition-colors uppercase tracking-tight">{item.name}</p> <p className="text-sm font-bold text-slate-700 truncate leading-none mb-0.5 group-hover:text-red-600 transition-colors uppercase tracking-tight">{item.name}</p>
<p className="text-[10px] font-medium text-slate-400 uppercase tracking-tighter">{item._count?.documents || 0} itens</p> <p className="text-[10px] font-medium text-slate-400 uppercase tracking-tighter">{item._count?.documents || 0} itens</p>
</div> </div>
</Link> </a>
) : ( ) : (
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<div className="w-8 h-8 flex items-center justify-center text-slate-400 shrink-0"> <div className="w-8 h-8 flex items-center justify-center text-slate-400 shrink-0">
@@ -927,16 +925,12 @@ export default function DocumentsClient({
> >
<Trash2 size={14} /> <Trash2 size={14} />
</Button> </Button>
<Button <a
asChild href={item.isFolder ? `/dashboard/documentos?folder=${item.id}` : `/dashboard/documentos/${item.id}`}
variant="ghost" className="h-8 w-8 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-all flex items-center justify-center"
size="icon"
className="h-8 w-8 rounded-lg text-slate-400 hover:text-red-600 hover:bg-red-50 transition-all"
> >
<Link href={item.isFolder ? `/dashboard/documentos?folder=${item.id}` : `/dashboard/documentos/${item.id}`}> <ChevronRight size={16} />
<ChevronRight size={16} /> </a>
</Link>
</Button>
</div> </div>
</td> </td>
</tr> </tr>

View File

@@ -16,7 +16,6 @@ import {
Share2, Share2,
Info, Info,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link";
import { updateDocument, deleteDocument } from "@/app/actions/documents"; import { updateDocument, deleteDocument } from "@/app/actions/documents";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
@@ -124,8 +123,7 @@ export default function DocumentDetailClient({
const result = await deleteDocument(document.id); const result = await deleteDocument(document.id);
if (result.success) { if (result.success) {
router.push("/dashboard/documentos"); window.location.href = "/dashboard/documentos";
router.refresh();
} else { } else {
setMessage({ type: "error", text: result.error || "Erro ao excluir." }); setMessage({ type: "error", text: result.error || "Erro ao excluir." });
setIsDeleting(false); setIsDeleting(false);
@@ -154,7 +152,7 @@ export default function DocumentDetailClient({
<div className="flex flex-col md:flex-row md:items-end justify-between gap-6"> <div className="flex flex-col md:flex-row md:items-end justify-between gap-6">
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<nav className="flex items-center gap-2 mb-3 text-[10px] font-bold uppercase tracking-widest text-slate-400"> <nav className="flex items-center gap-2 mb-3 text-[10px] font-bold uppercase tracking-widest text-slate-400">
<Link href="/dashboard/documentos" className="hover:text-slate-900 transition-colors">Documentos</Link> <a href="/dashboard/documentos" className="hover:text-slate-900 transition-colors cursor-pointer">Documentos</a>
<ChevronLeft size={10} className="rotate-180" /> <ChevronLeft size={10} className="rotate-180" />
<span className="text-slate-900 truncate tracking-[0.1em]">Gerenciar Arquivo</span> <span className="text-slate-900 truncate tracking-[0.1em]">Gerenciar Arquivo</span>
</nav> </nav>

View File

@@ -10,7 +10,6 @@ import {
FileText, FileText,
ChevronLeft, ChevronLeft,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link";
import { uploadFile } from "@/app/actions/upload"; import { uploadFile } from "@/app/actions/upload";
import { createDocument } from "@/app/actions/documents"; import { createDocument } from "@/app/actions/documents";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
@@ -111,8 +110,7 @@ export default function NewDocumentClient({
}); });
if (result.success) { if (result.success) {
router.push("/dashboard/documentos"); window.location.href = "/dashboard/documentos";
router.refresh();
} else { } else {
setError(result.error || "Erro ao salvar."); setError(result.error || "Erro ao salvar.");
setIsSaving(false); setIsSaving(false);
@@ -126,7 +124,7 @@ export default function NewDocumentClient({
<div className="flex flex-col md:flex-row md:items-end justify-between gap-6"> <div className="flex flex-col md:flex-row md:items-end justify-between gap-6">
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
<nav className="flex items-center gap-2 mb-3 text-[10px] font-bold uppercase tracking-widest text-slate-400"> <nav className="flex items-center gap-2 mb-3 text-[10px] font-bold uppercase tracking-widest text-slate-400">
<Link href="/dashboard/documentos" className="hover:text-slate-900 transition-colors">Documentos</Link> <a href="/dashboard/documentos" className="hover:text-slate-900 transition-colors cursor-pointer">Documentos</a>
<ChevronLeft size={10} className="rotate-180" /> <ChevronLeft size={10} className="rotate-180" />
<span className="text-slate-900 truncate tracking-[0.1em]">Upload de Arquivo</span> <span className="text-slate-900 truncate tracking-[0.1em]">Upload de Arquivo</span>
</nav> </nav>

View File

@@ -75,8 +75,7 @@ export default function SetupClient() {
const result = await createOrganization(formData); const result = await createOrganization(formData);
if (result.success) { if (result.success) {
router.push("/dashboard"); window.location.href = "/dashboard";
router.refresh();
} else { } else {
alert(result.error || "Erro ao finalizar instalação"); alert(result.error || "Erro ao finalizar instalação");
setIsSubmitting(false); setIsSubmitting(false);

View File

@@ -34,8 +34,7 @@ export default function LoginClient({ organization }: { organization: Organizati
setIsLoading(true); setIsLoading(true);
const result = await login(email, password); const result = await login(email, password);
if (result.success) { if (result.success) {
router.push("/dashboard"); window.location.href = "/dashboard";
router.refresh();
} else { } else {
setError(result.error || "Erro ao fazer login"); setError(result.error || "Erro ao fazer login");
setIsLoading(false); setIsLoading(false);

View File

@@ -11,7 +11,6 @@ import {
X, X,
Globe, Globe,
} from "lucide-react"; } from "lucide-react";
import Link from "next/link";
import { usePathname } from "next/navigation"; import { usePathname } from "next/navigation";
import { logout } from "@/app/actions/auth"; import { logout } from "@/app/actions/auth";
import { Button } from "@/components/ui/button"; import { Button } from "@/components/ui/button";
@@ -93,7 +92,7 @@ export function Sidebar({
{menuItems.map((item) => { {menuItems.map((item) => {
const isActive = pathname === item.href || (item.href !== "/dashboard" && pathname.startsWith(item.href)); const isActive = pathname === item.href || (item.href !== "/dashboard" && pathname.startsWith(item.href));
return ( return (
<Link <a
key={item.href} key={item.href}
href={item.href} href={item.href}
onClick={() => setMobileOpen(false)} onClick={() => setMobileOpen(false)}
@@ -105,7 +104,7 @@ export function Sidebar({
> >
<item.icon size={18} className={`transition-transform duration-300 ${isActive ? "scale-110" : "group-hover:scale-110 opacity-70 group-hover:opacity-100"}`} /> <item.icon size={18} className={`transition-transform duration-300 ${isActive ? "scale-110" : "group-hover:scale-110 opacity-70 group-hover:opacity-100"}`} />
<span className="text-[13px] tracking-tight">{item.label}</span> <span className="text-[13px] tracking-tight">{item.label}</span>
</Link> </a>
); );
})} })}
</nav> </nav>
@@ -131,7 +130,7 @@ export function Sidebar({
<div className="p-4 lg:p-6 mt-auto"> <div className="p-4 lg:p-6 mt-auto">
<div className="flex flex-col gap-3 lg:gap-4 p-4 lg:p-5 rounded-2xl lg:rounded-[24px] bg-white border border-slate-200/80"> <div className="flex flex-col gap-3 lg:gap-4 p-4 lg:p-5 rounded-2xl lg:rounded-[24px] bg-white border border-slate-200/80">
<Link <a
href="/dashboard/perfil" href="/dashboard/perfil"
onClick={() => setMobileOpen(false)} onClick={() => setMobileOpen(false)}
className="flex items-center gap-3 lg:gap-3.5 group" className="flex items-center gap-3 lg:gap-3.5 group"
@@ -148,7 +147,7 @@ export function Sidebar({
</p> </p>
<p className="text-[10px] lg:text-[11px] font-medium text-slate-400 truncate mt-0.5">{user.email}</p> <p className="text-[10px] lg:text-[11px] font-medium text-slate-400 truncate mt-0.5">{user.email}</p>
</div> </div>
</Link> </a>
<div className="h-px bg-slate-100 mx-1" /> <div className="h-px bg-slate-100 mx-1" />