fix: back button goes to folder, remove try-catch that redirected to setup on any error
This commit is contained in:
@@ -47,9 +47,11 @@ type DocumentType = {
|
|||||||
export default function DocumentViewClient({
|
export default function DocumentViewClient({
|
||||||
document: doc,
|
document: doc,
|
||||||
organization,
|
organization,
|
||||||
|
backUrl,
|
||||||
}: {
|
}: {
|
||||||
document: DocumentType;
|
document: DocumentType;
|
||||||
organization: Organization;
|
organization: Organization;
|
||||||
|
backUrl?: string | null;
|
||||||
}) {
|
}) {
|
||||||
const primaryColor = organization.primaryColor || "#2563eb";
|
const primaryColor = organization.primaryColor || "#2563eb";
|
||||||
const [numPages, setNumPages] = useState<number | null>(null);
|
const [numPages, setNumPages] = useState<number | null>(null);
|
||||||
@@ -187,15 +189,23 @@ export default function DocumentViewClient({
|
|||||||
<p className="text-xs text-white/70 hidden md:block">Portal de Transparência</p>
|
<p className="text-xs text-white/70 hidden md:block">Portal de Transparência</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Link
|
{backUrl ? (
|
||||||
href="/"
|
<Link
|
||||||
className="text-white/80 hover:text-white flex items-center gap-1 md:gap-2 text-xs md:text-sm"
|
href={backUrl}
|
||||||
>
|
className="text-white/80 hover:text-white flex items-center gap-1 md:gap-2 text-xs md:text-sm"
|
||||||
<ArrowLeft size={14} className="md:hidden" />
|
>
|
||||||
<ArrowLeft size={16} className="hidden md:block" />
|
<ArrowLeft size={14} className="md:hidden" />
|
||||||
<span className="hidden sm:inline">Voltar ao Portal</span>
|
<ArrowLeft size={16} className="hidden md:block" />
|
||||||
<span className="sm:hidden">Voltar</span>
|
<span className="hidden sm:inline">Voltar à Pasta</span>
|
||||||
</Link>
|
<span className="sm:hidden">Voltar</span>
|
||||||
|
</Link>
|
||||||
|
) : (
|
||||||
|
<div className="text-white/50 flex items-center gap-1 md:gap-2 text-xs md:text-sm">
|
||||||
|
<ArrowLeft size={14} className="md:hidden" />
|
||||||
|
<ArrowLeft size={16} className="hidden md:block" />
|
||||||
|
<span className="hidden sm:inline">Documento Público</span>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
|
|||||||
@@ -19,6 +19,13 @@ export default async function PublicDocumentPage({
|
|||||||
primaryColor: true,
|
primaryColor: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
folder: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
name: true,
|
||||||
|
isPublished: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -27,10 +34,17 @@ export default async function PublicDocumentPage({
|
|||||||
notFound();
|
notFound();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determina o link de voltar
|
||||||
|
const backUrl = document.folder?.isPublished
|
||||||
|
? `/visualizar/pasta/${document.folder.id}`
|
||||||
|
: null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DocumentViewClient
|
<DocumentViewClient
|
||||||
document={document}
|
document={document}
|
||||||
organization={document.organization}
|
organization={document.organization}
|
||||||
|
backUrl={backUrl}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,25 +5,20 @@ import LoginClient from "@/components/LoginClient";
|
|||||||
import { getSession } from "@/app/actions/auth";
|
import { getSession } from "@/app/actions/auth";
|
||||||
|
|
||||||
export default async function Page() {
|
export default async function Page() {
|
||||||
try {
|
// Verifica se o usuário já está logado
|
||||||
// Verifica se o usuário já está logado
|
const session = await getSession();
|
||||||
const session = await getSession();
|
if (session) {
|
||||||
if (session) {
|
redirect("/dashboard");
|
||||||
redirect("/dashboard");
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Verifica se existe alguma organização cadastrada
|
// Verifica se existe alguma organização cadastrada
|
||||||
const organization = await prisma.organization.findFirst();
|
const organization = await prisma.organization.findFirst();
|
||||||
|
|
||||||
// Se não houver organização, redireciona para o setup inicial (Instalação)
|
// Se não houver organização, redireciona para o setup inicial (Instalação)
|
||||||
if (!organization) {
|
if (!organization) {
|
||||||
redirect("/setup");
|
|
||||||
}
|
|
||||||
|
|
||||||
return <LoginClient organization={organization} />;
|
|
||||||
} catch (error) {
|
|
||||||
console.error("Erro ao verificar organização:", error);
|
|
||||||
// Se der erro de banco (provavelmente banco vazio ou não iniciado), vamos para o setup
|
|
||||||
redirect("/setup");
|
redirect("/setup");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return <LoginClient organization={organization} />;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user